试数据大法(基本篇)
首先,先给你看一道我用试数据A掉的黑题:P8562
在洛谷中,当有些题你不会时,输出数据又很简单(如一个字符串或一个数字)时,用试数据大法再适合不过了。下面会给出教程。
教程(用c++演示,其它语言请照葫芦画瓢):
为了说明白,我们假设有道题的输出数据是“hahf6e1i”(我已将此题编写了出来,大家可以在这道题中按下面的方法进行尝试,更容易理解。题目链接:https://www.luogu.com.cn/problem/U371238),而我们并不知道,我们就能使用试数据大法试出这个字符串。
首先,我们先提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"a";
return 0;
}提交后,当然会WA,我们将鼠标移到WA的测试点上,会出现一段提示:Wrong Answer.wrong answer On line 1 column 1, read a, expected h.,意思为错误答案。错误答案在第1行第1栏,读a,应为h。,于是,我们能知道,这个字符串第一个字符为.
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"ha";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer Too short on line 1.,记住:凡是出现这一段时,那这个字符一定为(前提是你的方法和我完全一样)。
于是,第二个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"haa";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer On line 3 column 1, read a, expected h.,根据前面的经验,可得第三个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"haha";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer On line 4 column 1, read a, expected f.,可得第四个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"hahfa";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer On line 5 column 1, read a, expected 6.,可得第五个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"hahf6a";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer On line 6 column 1, read a, expected e.,可得第六个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"hahf6ea";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer On line 7 column 1, read a, expected 1.,可得第七个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"hahf6e1a";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer On line 8 column 1, read a, expected i.,可得第八个字符为。
然后,我们再提交以下代码:
#include<iostream>
using namespace std;
int main(){
cout<<"hahf6e1ia";
return 0;
}将鼠标移到测试点上,会出现Wrong Answer.wrong answer Too long on line 1.(注:不要和Wrong Answer.wrong answer Too short on line 1.混了),当你出现这段字符时,那恭喜你,你的试数据就要完工了!!!只要将输出末尾的去掉,就能输出数据,AC本题!!!
即:
#include<iostream>
using namespace std;
int main(){
cout<<"hahf6e1i";
return 0;
}将这个代码提交上去,就能AC本题,并得到了个hahf6e1i的字符,它在这只是个例子,但在我的解密中通过试数据得到的字符串可能是解密的关键!!!
注:这只是最基本的试数据,仅使用它无法A掉像P8562那样的黑题。
如果对试数据还有什么疑问,欢迎私信我!!!
对了,给你道课后练习,要求试出输出数据,看你能通过试数据否试出来!
版权声明:可以转载,但要注明作者@qinxuekai。