CF1207E 题解

CF1207E 题解

题面

交互题。交互机给给定一个数 x ∈ [ 0 , 2 14 − 1 ] x \in [0, 2^{14} - 1] x[0,2141]

需要问两个问题,每个问题有恰好 100 100 100 个互不相同的数。

交互机会在这 100 100 100 个数中随机选取一个数,输出这个数 xor ⁡ x \operatorname{xor} x xorx

题解

思维题。

考虑给出的 200 200 200 个数,肯定有一些特性。

因为只有两个询问,只能 0 0 0 位确定各自的数

考虑分组。前 7 7 7 位和后 7 7 7 位正好可以用 127   ( > 100 ) 127\ (>100) 127 (>100) 个数列举。

Code

#include 

#define int long long
// FOR templates.
#define rep(i, s, n, k) for(int i = s;i <= n;i += k)
#define repn(i, s, n, k) for(int i = s;i < n;i += k)
#define pre(i, s, n, k) for(int i = s;i >= n;i -= k)
#define pren(i, s, n, k) for(int i = s;i > n;i -= k)
// Abbr for STL.
#define pii pair<int, int>
#define pdd pair<double, double>
#define mpi map<int, int>
#define pii pair<int, int>
#define pdd pair<double, double>
#define vc vector<int>
#define mpp map<int, int>
#define arr(k, n) int k[n]
#define all(v) v.begin(), v.end()
// CIN templates, proven very useful.
#define cn(n) int n;cin >> n
#define cm(n) cin >> n
// Abbr for funcs.
#define pb push_back
#define mset memset
// #define files
using namespace std;
const int MAXN = 0x3f3f3f3f3f3f3f3fLL;
const int MOD1 = 1000000007LL;
const int MOD2 = 998244353LL;
int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int gcd(int a, int b) {if(b == 0) return a;return gcd(b, a % b);}
inline int lowbit(int x) {return x & (-x);}
inline int lcm(int a, int b) {return a * b / gcd(a, b);}


signed main(){
#ifdef files
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cout << "? ";
	repn(i, 0, 100, 1){
		cout << i << " ";
	}
	cout << endl; cout << flush;
	cn(n);
	cout << "? ";
	rep(i, 1, 100, 1){
		cout << i * 128 << " ";
	}
	cout << endl; cout << flush;
	cn(m);
	cout << "! " << ((n >> 7) << 7) + (m % 128) << endl;
	cout << flush;
	return 0;
}

/*
 *  things to check
 *  1.  int overflow or long long memory need
 *  2.  recursion/array/binary search/dp/loop bounds
 *  3.  precision
 *  4.  special cases(n=1,bounds)
 *  5.  delete debug statements
 *  6.  initialize(especially multi-tests)
 *  7.  = or == , n or m ,++ or -- , i or j , > or >= , < or <=
 *  8.  keep it simple and stupid
 *  9.  do not delete, use // instead
 *  10. operator priority
 *  11. is there anything extra to output?
 *  12. THINK TWICE CODE ONCE, THINK ONCE DEBUG FOREVER
 *  13. submit ONCE, AC once. submit twice, WA forever
 *  14. calm down and you'll get good rank
 *  15. even a bit wrong scores zero
 *  16. ...
 **/
 
/*
 *  something to think about
 *  1. greedy? dp? searching? dp with matrix/ segment tree? binary search? ...?
 *  2. If it is difficult, why not the opposite?
 **/
 

你可能感兴趣的:(综合题题解,c语言,c++,算法)