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. Git之清除已保存的账户

    Git会自动保存输入过的用户名.密码. Git的配置文件是-/.gitconfig.可在windows下的GIt Bash.Mac的命令行中,用vim ~/.gitconfig打开. Windows ...

  2. Netty实践一(数据通信)

    我们需要了解下在真正项目应用中如何去考虑Netty的使用,大体上对于一些参数设置都是根据服务器性能决定的.这个不是最主要的. 我们需要考虑的问题是两台机器(甚至多台)使用Netty的怎样进行通信,大体 ...

  3. springmvc控制器传可变路径

    @RequestMapping("/clone{path}") public String cloneModules(HttpServletRequest req,@PathVar ...

  4. fnb2b分支拉取注意事项

    1. 大B分支拉取以后不要忘记把index.php中dev环境改为 $save_url = "http://dev-b2b.dev1.fn/"; 2. 大B分支拉取后,记得/bas ...

  5. Maven学习笔记(十二)-maven打包之resource配置

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u011781521/article/details/79052725 一.简介 构建Maven项目的 ...

  6. 国内淘宝镜像 cnpm转npm

    npm install -g cnpm --registry=http://registry.npm.taobao.org

  7. golang 常用的正则查找与替换

    package main; import ( "regexp" "fmt" "strings" ) func main() { //1.过正 ...

  8. mybatis入门--mybatis和hibernate比较

    mybatis和hibernate的比较 Mybatis和hibernate不同,它不完全是一个ORM框架,因为MyBatis需要程序员自己编写Sql语句,不过mybatis可以通过XML或注解方式灵 ...

  9. hdu 1754(基础线段树) I Hate It

    http://acm.hdu.edu.cn/showproblem.php?pid=1754 数据比较大,暴力会超时,所以明显是线段树,普通的线段树,结构体中多开一个值sum储存每个子区间的最大成绩, ...

  10. Generate a Push Certificate

    To send Push notification to an application/device couple you need an unique device token (see the O ...