Codeforces Round #500 (Div. 2) BC

CodeForces 1013B And
CodeForces 1013C  Photo of The Sky

B

可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况

 #include <bits/stdc++.h>
#define show(a) cout << #a << " = " << a << endl;
const int MOD = 1e9+;
const int MAXN = ;
const int INF = ;
typedef long long ll; using namespace std; int main()
{
std::ios::sync_with_stdio(false);
int n, x, ans = -;
cin >> n >> x;
int a[MAXN], point[MAXN];
for (int i = ; i <= n; i++)
{
cin >> a[i];
}
sort(a+, a++n);
for (int i = ; i <= n; i++)
{
if (a[i] == a[i-])
{
ans = ;
break;
}
}
if (ans == -)
{
int flg = ;
for (int i = ; i <= n; i++)
point[i] = a[i] & x;
for (int i = ; i <= n; i++)
{
int s = lower_bound(a+, a++n, point[i]) - a;
if (point[i] == a[s] && s != i)
{
ans = , flg = ;
break;
}
}
if (!flg)
{
sort(point+, point++n);
for (int i = ; i <= n; i++)
{
if (point[i] == point[i-])
{
ans = ;
break;
}
}
}
}
cout << ans << endl;
return ;
}

C

可以看成是红蓝染色,要求(红最大-红最小)*(蓝最大*蓝最小),排序后考虑两端颜色相同或不同,时间复杂度O(n)

 #include <bits/stdc++.h>
#define show(a) cout << #a << " = " << a << endl;
typedef long long ll;
const int MOD = 1e9+;
const int MAXN = ;
const ll INF = 1e18; using namespace std; int main()
{
std::ios::sync_with_stdio(false);
int n;
cin >> n;
ll num[n*+];
for (int i = ; i <= *n; i++)
cin >> num[i];
sort(num+, num++*n);
ll ans = INF;
for (int i = ; i <= n; i++)
ans = min(ans, (num[i+n-] - num[i]) * (num[*n] - num[]));
ans = min(ans, (num[n*] - num[n+]) * (num[n] - num[]));
cout << ans << endl;
return ;
}
上一篇:POJ 3067 Japan(树状数组)


下一篇:Java IO流体系中常用的流分类