码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #500 (Div. 2) BC

时间:2018-07-30 23:31:59      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:str   break   codeforce   sort   gif   lse   tar   int   img   

 

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 }
View Code

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 }
View Code

 

Codeforces Round #500 (Div. 2) BC

标签:str   break   codeforce   sort   gif   lse   tar   int   img   

原文地址:https://www.cnblogs.com/cjc7373/p/9393373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!