Codeforces Round #500 (Div. 2) BC
Posted cjc7373
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #500 (Div. 2) BC相关的知识,希望对你有一定的参考价值。
CodeForces | 1013B | And |
CodeForces | 1013C | Photo of The Sky |
B
可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况
1 #include <bits/stdc++.h> 2 #define show(a) cout << #a << " = " << a << endl; 3 const int MOD = 1e9+7; 4 const int MAXN = 100005; 5 const int INF = 500005; 6 typedef long long ll; 7 8 using namespace std; 9 10 int main() 11 { 12 std::ios::sync_with_stdio(false); 13 int n, x, ans = -1; 14 cin >> n >> x; 15 int a[MAXN], point[MAXN]; 16 for (int i = 1; i <= n; i++) 17 { 18 cin >> a[i]; 19 } 20 sort(a+1, a+1+n); 21 for (int i = 2; i <= n; i++) 22 { 23 if (a[i] == a[i-1]) 24 { 25 ans = 0; 26 break; 27 } 28 } 29 if (ans == -1) 30 { 31 int flg = 0; 32 for (int i = 1; i <= n; i++) 33 point[i] = a[i] & x; 34 for (int i = 1; i <= n; i++) 35 { 36 int s = lower_bound(a+1, a+1+n, point[i]) - a; 37 if (point[i] == a[s] && s != i) 38 { 39 ans = 1, flg = 1; 40 break; 41 } 42 } 43 if (!flg) 44 { 45 sort(point+1, point+1+n); 46 for (int i = 2; i <= n; i++) 47 { 48 if (point[i] == point[i-1]) 49 { 50 ans = 2; 51 break; 52 } 53 } 54 } 55 } 56 cout << ans << endl; 57 return 0; 58 }
C
可以看成是红蓝染色,要求(红最大-红最小)*(蓝最大*蓝最小),排序后考虑两端颜色相同或不同,时间复杂度O(n)
1 #include <bits/stdc++.h> 2 #define show(a) cout << #a << " = " << a << endl; 3 typedef long long ll; 4 const int MOD = 1e9+7; 5 const int MAXN = 200005; 6 const ll INF = 1e18; 7 8 using namespace std; 9 10 int main() 11 { 12 std::ios::sync_with_stdio(false); 13 int n; 14 cin >> n; 15 ll num[n*2+5]; 16 for (int i = 1; i <= 2*n; i++) 17 cin >> num[i]; 18 sort(num+1, num+1+2*n); 19 ll ans = INF; 20 for (int i = 2; i <= n; i++) 21 ans = min(ans, (num[i+n-1] - num[i]) * (num[2*n] - num[1])); 22 ans = min(ans, (num[n*2] - num[n+1]) * (num[n] - num[1])); 23 cout << ans << endl; 24 return 0; 25 }
以上是关于Codeforces Round #500 (Div. 2) BC的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #500 (Div. 2) BC
Codeforces Round#500 Div.2 翻车记