关于E 题

dd 2023-03-11 14:26:42

建议使用 cin 输入,cout 输出,并在每次提问后 cout<<endl;

共 2 条回复

dd

E的输入并不是文件输入,而是交互器给出的。

dd

E的交互器代码如下

#include<iostream>
#include <fstream>
using namespace std;

typedef long long ll;

std::ofstream score("score.txt");

template <typename T>
inline void assert(const T &condition, const std::string &message)
{
	if (!condition)
	{
		std::cerr << message << std::endl;
		score << 0 << std::endl;
		exit(0);
	}
}

int main(int argc, char** argv)
{
	std::ifstream datin("input");
	int t;
	datin>>t;
	cout<<t<<endl<<flush;
	int sum=0;
	for(int i=1;i<=t;i++)
	{
		ll k,a,n,m;
		datin>>k>>a>>n>>m;
		cout<<n<<' '<<m<<endl<<flush;
		int cnt=0;
		
		while(true)
		{
			char c;
			ll x1,x2;
			assert(cin >> c >> x1>>x2, "Invalid input!");
			if(c=='?')
			{
				if(cnt>=31)
				{
					score<<0<<endl;
					cerr<<"you have asked more than 31 times!"<<endl;
					exit(0);
				}
				if(x1>x2){cerr<<"your x1 is "<<x1<<" and your x2 is "<<x2<<' '<<"so input out of range!"<<endl;score<<0<<endl;exit(0);}
				if(x1<n||x2>m){cerr<<"your x1 is "<<x1<<" and your x2 is "<<x2<<' '<<"so input out of range!"<<endl;score<<0<<endl;exit(0);}
				ll now1=x1*k,now2=x2*k;
				if(x1>a)now1-=k;
				if(x2>a)now2-=k;
				++cnt;
				++sum;
				cout<<now2-now1<<endl<<flush;
			}
			else
			{
				if(x1==k&&x2==a)
				{
					break;
				}
				else 
				{
					cerr<<"not good!~_~"<<"your guess k is "<<x1<<" and your guess a is "<<x2<<" so your answer is wrong!"<<endl;
					score<<0<<endl;
				}
				exit(0);
			}
		}
	}
	cerr<<"Delicious! "<<sum<<" time(s) guess."<<endl;
	score<<100<<endl;
	return 0;
}