https://codeforces.com/contest/1114/problem/E

题意

交互题,需要去猜一个乱序的等差数列的首项和公差,你能问两种问题

1. 数列中有没有数比x大

2. 数列的第i项是什么

最多只能问60次

题解

  • 首先用第一种问题+二分问出数列最大的数是多少,最多二十次
  • 然后用第二种问题尽可能分散的询问第i项,然后将问出的数组排序,对相邻两个数的差求gcd

随机数生成链接

https://codeforces.com/blog/entry/61587

https://codeforces.com/blog/entry/61675

#include<bits/stdc++.h>
#define M 1000000
#define P 23333
#define X 23
#define ll long long
using namespace std;
int vi[M+5];
ll n,cnt,x,sz,a[100],l,r,mid,gcd,i,mul;
int main(){
cin>>n;
mul+=P;x=((ll)rand()*X%n+mul)%n+1;vi[x]=1;
cout<<"? "<<x<<endl;cnt++;cout.flush();
cin>>a[sz++];
l=a[0];r=1e9;
while(l<r){
mid=(l+r)/2;
cout<<"> "<<mid<<endl;cnt++;cout.flush();
cin>>x;
if(x)l=mid+1;
else r=mid;
}
for(;cnt<=60;cnt++){
if(sz==n)break;
mul+=P;
x=((ll)rand()*X%n+mul)%n+1;
while(vi[x]){
mul+=P;
x=((ll)rand()*X%n+mul)%n+1;
}
vi[x]=1;
cout<<"? "<<x<<endl;cnt++;cout.flush();
cin>>a[sz++];
}
sort(a,a+sz);
gcd=a[1]-a[0];
for(i=2;i<sz;i++){
gcd=__gcd(gcd,a[i]-a[i-1]);
}
cout<<"! "<<l-(n-1)*gcd<<" "<<gcd<<endl;
cout.flush();
}

Codeforces Round #538 (Div. 2) E 随机数生成的更多相关文章

  1. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  2. Codeforces Round #538 (Div. 2) (CF1114)

    Codeforces Round #538 (Div. 2) (CF1114)   今天昨天晚上的cf打的非常惨(仅代表淮中最低水平   先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O( ...

  3. Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?) (分解质因数)

    题目:http://codeforces.com/problemset/problem/1114/C 题意:给你n,m,让你求n!换算成m进制的末尾0的个数是多少(1<n<1e18    ...

  4. Codeforces Round #538 (Div. 2)

    目录 Codeforces 1114 A.Got Any Grapes? B.Yet Another Array Partitioning Task C.Trailing Loves (or L'oe ...

  5. Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  6. Codeforces Round #538 (Div. 2) C 数论 + 求b进制后缀零

    https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a ...

  7. Codeforces Round #538 (Div. 2) D. Flood Fill 【区间dp || LPS (最长回文序列)】

    任意门:http://codeforces.com/contest/1114/problem/D D. Flood Fill time limit per test 2 seconds memory ...

  8. Codeforces Round #538 (Div. 2) CTrailing Loves (or L'oeufs?)

    这题明白的意思就是求n!在b进制下的后缀零的个数. 即最大的n!%(b^k)==0的k的值.我们需要将如果要构成b这个数,肯定是由一个个质因子相乘得到的.我们只需要求出b的质因子,然后分析n!中可以组 ...

  9. Codeforces Round #538 (Div. 2)D(区间DP,思维)

    #include<bits/stdc++.h>using namespace std;int a[5007];int dp[5007][5007];int main(){    int n ...

随机推荐

  1. “东信杯”广西大学第一届程序设计竞赛(同步赛)H

    链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...

  2. f5 Seldom used

    1.负载均衡算法 2)最快响应速度(Fastest) •优先查看7层请求的连接数,然后查看4层连接数 •需要在virtual server上关联7层的profile,否则与最小连接数相同 •后台服务器 ...

  3. [leetcode]122. Best Time to Buy and Sell Stock II 最佳炒股时机之二

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  4. 11-web网页制作APP

    如何将H5和WebApp 加壳成apk.ipa     问题:已经做好的纯H5的站点 想分别加两个壳子,变成apk和ipa ,要怎么实现? 要点: 1. app只是壳子,打开app直接跳转到H5的Ur ...

  5. python 大量使用json 存储数据时,格式化输出的方式

    import json, pprint dic = {'name': 234, 'user_name': 'yan xia ting yu ', 'list': ['ds', 'a', 2], '你好 ...

  6. python any() all()

    any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,则返回 False,如果有一个为 True,则返回 True. 元素除了是 0.空.FALSE 外都算 TRUE. ...

  7. 初次搭建spring-boot 整合ssm(有许多小坑)

    首先,我是采用官网下载,版本最好选择1.5.16的(这是重点) 下载完毕后,用idea打开解压后的项目. 1.整合spring-mvc 在pom.xml中加入web依赖 <dependency& ...

  8. js filter关键字

    filter filter也是一个常用的操作,它用于把Array的某些元素过滤掉,然后返回剩下的元素. 和map()类似,Array的filter()也接收一个函数.和map()不同的是,filter ...

  9. Squid 搭建正向代理服务器

    Squid 是一款缓存代理服务器软件,广泛用于网站的负载均衡架构中,常见的缓存服务器还有varnish.ATS等. 正向代理服务器可满足内网仅有一台服务器可以上网,而要供内网所有机器上网的需求,也可以 ...

  10. Jenkins2.0中的pipeline

    jenkins的实现是标准的master/slave模式,用户与master交互,master将job分布到slave上运行. jenkins的基本概念: 1. master, 也就是jenkins的 ...