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. 微信小程序开发——以简单易懂的浏览器页面栈理解小程序的页面路由

    前言: 对于小程序的页面路由,如果没有一定开发经验的话,理解起来还是会有些困难的.哪怕是有一定小程序开发经验的开发者,能够完全理解掌握的恐怕也不多. 这里就以另外一种方式来详细的介绍小程序的页面栈及路 ...

  2. awk参数解析

    # awk --help Usage: awk [POSIX or GNU style options] -f progfile [--] file ... Usage: awk [POSIX or ...

  3. Java_10.1继承应用

    /*   *  描述学生和工人两个类   name  age进行抽取 ,父类 Person 提供set   get   *  同时创建学生和工人对象  必须明确年龄和姓名  并且控制台输出 * */ ...

  4. SQL update语句 更新和查询同一张表 冲突

    #update 和 select在同一张表的时候会显示冲突  报错信息: [Err] 1093 - You can't specify target table 'tb_a' for update i ...

  5. mysql --secure-file-priv is set to NULL.Operations related to importing and exporting data are disabled

    --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabledmy ...

  6. linux操作系统-源码包安装jdk1.7

    1.下载安装文件 在oracle官方找不到bin二进制安装文件只能使用rpm包来安装 下载地址:http://www.oracle.com/technetwork/java/javase/downlo ...

  7. C# 使用printDocument1.Print打印时不显示 正在打印对话框

    C#使用printDocument1.Print打印时不显示正在打印对话框有两种方法 第一种,使用PrintController       PrintController printControll ...

  8. andorid 表格布局

    tablelayout.xml表格布局 <?xml version="1.0" encoding="utf-8"?> <TableLayout ...

  9. hdu 4004 (二分加贪心) 青蛙过河

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...

  10. LINUX查看网卡UUID

    有时我们不小心将/etc/sysconfig/network-scripts/ifcfg-eth0(可以通过此文件进行查看UUID)删除或者损坏,要重新编辑ifcfg-eth0文件时不知道网卡的UUI ...