【开源社区openEuler实践】 D. Cat, Fox and Maximum Array Split
【代码】Codeforces Round 945 (Div. 2) D. Cat, Fox and Maximum Array Split。
·
思路:

#include<bits/stdc++.h>
using namespace std;
#define double long double
#define int long long
int ask(int l, int x){
cout << '?' << ' ' << l << ' ' << x << '\n';
cout.flush();
int res;
cin >> res;
return res;
}
void print(int x){
cout << "! " << x << '\n';
cout.flush();
int res;
cin >> res;
}
void solve(){
int n, k;
cin >> n >> k;
int mx = 0;
for(int i = 1; i <= n; i++){
int r = ask(1, n * i);
if(r == n){
mx = i;
break;
}
}
auto check = [&](int val) -> bool {
int cur = 1;
for(int i = 1; i <= k; i++){
if(cur > n) return 0;
int r = ask(cur, val);
if(r == n + 1) return 0;
cur = r + 1;
}
return cur == n + 1;
};
for(int i = 1; i <= n / k; i++){
int val = i * mx;
if(check(val)){
print(val);
return;
}
}
print(-1);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while(T--){
solve();
}
return 0;
}
鲲鹏昇腾开发者社区是面向全社会开放的“联接全球计算开发者,聚合华为+生态”的社区,内容涵盖鲲鹏、昇腾资源,帮助开发者快速获取所需的知识、经验、软件、工具、算力,支撑开发者易学、好用、成功,成为核心开发者。
更多推荐

所有评论(0)