【Codeforces Round #499 (Div. 1) B】Rocket

【链接】 我是链接,点我呀:)
【题意】

让你猜到火星的距离x是多少. 已知1<=x<=m 然后你可以问系统最多60个问题 问题的形式以一个整数y表示 然后系统会回答你3种结果 -1 xy 但是系统有时候会撒谎 这个撒谎的过程由一个长度为n的序列决定 n<=30 如果p[i]=1表示它对接下来的询问不会撒谎 p[i]=0表示它对接下来的询问会撒谎 撒谎之后系统会输出-ans 如果问的个数>=n了那么重新从1开始 p数组未知 但是长度n告诉你了

【题解】

前n个问题一直问m 看看系统回答什么,回答0直接输出m,否则根据这个询问来确定系统说的是真话还是假话。 从而得到p数组。 然后根据p数组写个二分就能最后问出距离啦

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 1e5;

int n,k,a[N+10],g;
int flag[N+10];

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "r", stdin);
	#endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> k;
    for (int i = 1;i <= n;i++) cin >> a[i];
    g = a[1];
    for (int i = 2;i <= n;i++) g = __gcd(g,a[i]);
    for (int s = 0,i = 1;i <= k;s = (s+g)%k,i++) flag[s] = 1;
    int cnt = 0;
    for (int i = 0;i <k;i++) if (flag[i]) cnt++;
    cout<<cnt<<endl;
    for (int i = 0;i < k;i++) if (flag[i]) cout<<i<<' ';
	return 0;
}

原文地址:https://www.cnblogs.com/AWCXV/p/9379525.html