Codeforces Round #538 (Div. 2) E. Arithmetic Progression( 交互题 )
人生第一道交互题,确实挺有意思的,hhh,就是调试起来费劲
题目大意:
直接用vjudge里的翻译了
思路:
首先我们可以通过>操作,来找出序列的最大值maxx
这个过程最多用30次左右,2^30直接到1e10了
对于每一个序列内的数
a n = a 1 ( n − 1 ) d = m a x x − k 1 d a 1 = m a x x − ( n − 1 ) d a_n = a_1 (n-1)d=maxx - k_1d\\ a1 = maxx-(n-1)d an=a1 (n−1)d=maxx−k1da1=maxx−(n−1)d
所以我们只要确定d即可
怎么去求d呢
我们还有另一个操作?,可以查询序列中任意一位的数(序列是乱)
如果k1 与 k2 互质,也就是说gcd(k1,k2)=1
那么 gcd(k1 * d , k2 * d) = d
k1和k2,我们可以通过
maxx - ai得来
也就是说只要不断随机查询,来找到k1,k2互质的情况即可
注意:
交互题里输出最好用cout<<…<<endl
不要用printf,用printf的话要清理缓冲区,不然。。。
会犯下懒惰之罪 (Idleness limit exceeded)
不要问我怎么知道的QWQ
AC代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<random>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 5e3 7;
int n;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
map<int, int > map1;
int main() {
scanf("%d", &n);
int maxx = 0;
int l, r;
l = 0; r = 1e9;
while (l <= r) {
int mid = (l r) >> 1;
cout << "> " << mid << endl;
cout.flush();
int x;
scanf("%d", &x);
if (x)l = mid 1;
else r = mid - 1;
}
maxx = l;
mt19937 rnd(1e9 7);
int d = 0;
for (int i = 1; i <= min(30, n); i) {
int idx;
while (idx = rnd() % n 1) {
if (map1[idx])continue;
map1[idx] = 1;
break;
}
//printf("? %d\n", idx);
cout << "? " << idx << endl;
int x;
scanf("%d", &x);
d = gcd(d, maxx - x);
}
//printf("! %d %d\n",maxx - (n-1)*d,d);
cout << "! " << maxx - (n - 1) * d << " " << d << endl;
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhggieef
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13