codeforces 1114E Arithmetic Progression (交互题)

qwqqqq
我好菜
颓废而不想打cf
qwq

首先看到这个题,第一反应就是先用 l o g 2 ( m a x ( a [ i ] ) ) log_2(max(a[i])) log2(max(a[i]))的次数,得到最大值是多少。

qwq
然后应该怎么做呢…

貌似好像只能询问某一个位置的数字了

但是有一个很有趣的东西

可以通过莫比乌斯反演推出,如果我们随机选择30个数字,并求出来他们的 g c d gcd gcd,那么把这个 g c d gcd gcd当作公差的话

可以证明错误的概率 1.86185 × 1 0 − 9 1.86185 \times 10^{-9} 1.86185×109
qwq证明的话
(咳咳 先留坑

所以直接做就好了咯
qwq

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<ctime>
#define mk make_pair
#define ll long long
using namespace std;
inline int read()
{
  int x=0,f=1;char ch=getchar();
  while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
  while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
  return x*f;
}
const int maxn = 100010;
int a[maxn];
int n,m;
int res=60;
int getmax(int x)
{
	printf("> %d\n",x);
	res--;
	fflush(stdout);
	int now;
	fflush(stdin);
	scanf("%d",&now);
	return now;
}
int getnum(int x)
{
	printf("? %d\n",x);
	fflush(stdout);
	fflush(stdin);
	int now;
	scanf("%d",&now);
	return now;
}
int solve()
{
	int l=0,r=1e9;
	int ans=0;
	while(l<=r)
	{
		int mid =l+r >> 1;
		if (getmax(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	return ans+1;	
}
int main()
{
  fflush(stdin);
  scanf("%d",&n);
  int mx = solve();
  //cout<<"****"<<mx<<endl;
  srand(time(NULL)+20011104+20020918);
  for (int i=1;i<=res;i++) a[i]=1ll*rand()*1ll*rand()*1ll*rand()%(1ll*n)+1;
  for (int i=1;i<=res;i++) a[i]=getnum(a[i]);
  sort(a+1,a+1+res);
  for (int i=1;i<res;i++) a[i]=a[i+1]-a[i];
  int gg = a[1];
  for (int i=2;i<res;i++) gg = __gcd(a[i],gg);
  printf("! %d %d\n",mx - gg*(n-1),gg);
  fflush(stdout); 
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值