Codeforces Global Round 5
Posted misuchii
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Global Round 5相关的知识,希望对你有一定的参考价值。
Codeforces Global Round 5
A. Balanced Rating Changes
思路:(n)为偶数 则这n个数里面奇数的个数一定为偶数 那么就每次令一个答案为(frac{a_i}{2} - 1) 另一个答案为(frac{a_i}{2} + 1)(注意(a_i)的正负性
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
int n, x;
vector<int> a, ans;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i ++ ){
cin >> x;
a.push_back(x);
}
int flag = 1;
for (int i = 0; i < n; i ++ ){
if (a[i] & 1){
if (flag == 1){
if (a[i] >= 0)
ans.push_back(a[i] / 2);
else
ans.push_back(a[i] / 2 - 1);
}
else{
if (a[i] >= 0)
ans.push_back(a[i] / 2 + 1);
else
ans.push_back(a[i] / 2);
}
flag *= -1;
}
else
ans.push_back(a[i] / 2);
}
for (int i = 0; i < n; i ++ )
cout << ans[i] << "
";
return 0;
}
B. Balanced Tunnel
思路:模拟搞搞就行
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
const int N = 1e5 + 10;
int n, ans;
int a[N], b[N], res[N];
bool vis[N];
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++ )
cin >> a[i];
for (int i = 1; i <= n; i ++ )
cin >> b[i];
int j = 1;
for (int i = 1; i <= n; i ++ ){
vis[a[i]] = true;
for (; j <= n; j ++ ){
if (res[a[i]] || a[i] == b[j])
break;
if (!vis[b[j]])
res[b[j]] = 1;
}
}
for (int i = 1; i <= n; i ++ )
if (res[i])
ans ++ ;
cout << ans << "
";
return 0;
}
C. Balanced Removals
思路:一维可以根据x坐标对所有点排序 然后成对移除 二维的时候把每个x相同的点单独处理 然后剩下y不同的进行排序 继续成对移除 分别都剩下一个数 就一起处理 三维同理
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
const int N = 5e4 + 10;
int n;
struct Point{
int x, y, z, id;
}p[N], tmp[N];
inline bool cmp(const Point &p1, const Point &p2){
if (p1.x != p2.x)
return p1.x < p2.x;
if (p1.y != p2.y)
return p1.y < p2.y;
return p1.z < p2.z;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++ ){
cin >> p[i].x >> p[i].y >> p[i].z;
p[i].id = i;
}
sort(p + 1, p + n + 1, cmp);
int j = 0;
for (int i = 1; i <= n; i ++ ){
if (p[i].x == p[i + 1].x && p[i].y == p[i + 1].y && i < n){
cout << p[i].id << " " << p[i + 1].id << "
";
i ++ ;
}
else
tmp[ ++ j ] = p[i];
}
int k = 0;
for (int i = 1; i <= j; i ++ ){
if (tmp[i].x == tmp[i + 1].x && i < j){
cout << tmp[i].id << " " << tmp[i + 1].id << "
";
i ++ ;
}
else
p[ ++ k ] = tmp[i];
}
for (int i = 1; i < k; i += 2 )
cout << p[i].id << " " << p[i + 1].id << "
";
return 0;
}
D. Balanced Playlist
思路:先特判下(mina * 2)是否(geq maxa) 然后把(a)重复三遍 注意跳出条件
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
const int N = 3e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
int max_a = -INF, min_a = INF;
int a[N];
multiset<int> st;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++ ){
cin >> a[i];
a[i + 2 * n] = a[i + n] = a[i];
max_a = max(max_a, a[i]), min_a = min(min_a, a[i]);
}
if (min_a * 2 >= max_a){
for (int i = 1; i < n; i ++ )
cout << "-1 ";
cout << "-1
";
return 0;
}
int j = 0;
for (int i = 1; i <= n; i ++ ){
for (;;){
if ((!st.empty() && (*( -- st.end())) > 2 * a[j + 1]) || (j == 3 * n))
break;
st.insert(a[ ++ j ]);
}
cout << j - i + 1 << " ";
st.erase(st.lower_bound(a[i]));
}
return 0;
}
以上是关于Codeforces Global Round 5的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Global Round 16 A-E
Codeforces Global Round 7 题解(未完)(ABCD)