Error message here!

Hide Error message here!

Error message here!

Hide Error message here!

Error message here!

Close

## Good Bye 2019（前五题题解）

nblyz2003 2020-01-07 19:44:00 阅读数:81 评论数:0 点赞数:0 收藏数:0

D题是人生中做完的第一道交互题，不容易。

A.Card Game

``` #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

int main(){
int t;
scanf("%d", &t);
rep(times, , t){
int n, k1, k2;
scanf("%d%d%d", &n, &k1, &k2);
int maxx1 = , maxx2 = ;
rep(i, , k1){
int x;
scanf("%d", &x);
maxx1 = max(maxx1, x);
}
rep(i, , k2){
int x;
scanf("%d", &x);
maxx2 = max(maxx2, x);
}
if(maxx1 > maxx2) puts("YES");
else puts("NO");
}
return ;
}```
View Code-A

B.Interesting Subarray

``` #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN 200005
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

int a[MAXN];

int main(){
int t;
scanf("%d", &t);
rep(times, , t){
int n;
scanf("%d", &n);
rep(i, , n) scanf("%d", &a[i]);
int s = INF, id = , ans = ;
rep(i, , n){
if(s < a[i] - i){
printf("YES\n%d %d\n", id, i);
ans = ;
break;
}
if(a[i] - i < s){
s = a[i] - i;
id = i;
}
}
if(!ans){
s = , id = ;
rep(i, , n){
if(s > a[i] + i){
printf("YES\n%d %d\n", id, i);
ans = ;
break;
}
if(a[i] + i > s){
s = a[i] + i;
id = i;
}
}
}
if(!ans) puts("NO");
}
return ;
}```
View Code-B

C.Make Good

0110 | 1

0111 | 0

011 | 1

011 | 0

10 | 0

01 | 0                    相同

1 | 0

0 | 1                      不同，答案变成11

| 1

| 1                         相同

``` #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

int main(){
int t;
scanf("%d", &t);
rep(times, , t){
int n;
scanf("%d", &n);
ll s1 = , s2 = ;
rep(i, , n){
ll x;
scanf("%lld", &x);
s1 += x;
s2 ^= x;
}
s2 <<= ;
ll ans = ;
for(int i = ; s1 != s2; i++){
if((s1 & ) ^ (s2 & )){
s1 += ;
s2 ^= ;
ans += 1ll << i;
}
s1 >>= ;
s2 >>= ;
}
printf("1\n%lld\n", ans);
}
return ;
}```
View Code-D

D.Strange Device

2 3 4

1 3 4

1 2 4

1 2 3

``` #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

map<int, int> f;

int main(){
int n, k;
scanf("%d%d", &n, &k);
int maxx = ;
rep(i, , k + ){
putchar('?');
rep(j, , k + ){
if(i == j) continue;
printf(" %d", j);
}
puts("");
fflush(stdout);
int x, y;
scanf("%d%d", &x, &y);
f[y]++;
maxx = max(maxx, y);
}
printf("! %d\n", f[maxx]);
return ;
}```
View Code-D

E.Divide Points

``` #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN 1005
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

vi ans;
int x[MAXN], y[MAXN], cnt[][];

int main(){
int n;
scanf("%d", &n);
rep(i, , n) scanf("%d%d", &x[i], &y[i]);
while(){
clr(cnt, );
rep(i, , n) cnt[x[i] & ][y[i] & ]++;
if(cnt[][] + cnt[][] > && cnt[][] + cnt[][] > ){
rep(i, , n)
if((x[i] & ) ^ (y[i] & )) ans.pb(i);
printf("%d\n", SZ(ans));
rep(i, , SZ(ans) - ) printf("%d ", ans[i]);
puts("");
return ;
}
if(cnt[][] + cnt[][] > && cnt[][] + cnt[][] > ){
rep(i, , n)
if(x[i] & ) ans.pb(i);
printf("%d\n", SZ(ans));
rep(i, , SZ(ans) - ) printf("%d ", ans[i]);
puts("");
return ;
}
rep(i, , n){
x[i] >>= ;
y[i] >>= ;
}
}
return ;
}```
View Code-E

https://www.cnblogs.com/nblyz2003/p/12161998.html