交互题
作者:互联网
暴力求解,把每次可能的值都求出来,然后逐个比较。
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int x, n;
typedef pair<int, int> pii;
vector<pii> vet;
signed main(){
cin >> n;
while(n -- ){
cout << 0 <<" " << 0 << endl;
cout.flush();
cin >> x;
vet.clear();
if(x == 0) continue;
for(int i = 0; i * i <= x; i++){
int a = i * i;
int b = x - a;
int y = sqrt(b);
if(y * y == b) vet.push_back({i, y});
}
for(vector<pii>::iterator it = vet.begin(); it != vet.end(); it ++){
pii t = *it;
if(t.first < 0 || t.first > 1e6 || t.second < 0 || t.second > 1e6) continue;
cout << t.first <<" " << t.second << endl;
cout.flush();
cin >> x;
if(x == 0) break;
}
}
return 0;
}
2、
标签:pii,vet,cout,int,second,1e6,交互 来源: https://www.cnblogs.com/N-lim/p/16663123.html