Codeforces 898
Posted Aragaki
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 898相关的知识,希望对你有一定的参考价值。
A
/* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) make_pair(a,b) #define pb push_back const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}}; using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; if(n%10<=5) { n-=n%10; } else { n+=10-n%10; } cout<<n<<endl; return 0; }
B
/* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) make_pair(a,b) #define pb push_back const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}}; using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; ll a,b; cin >> a >> b; ll bei=n/a; ll now; for(ll i=0;i<=bei;i++) { now=n-i*a; if(now%b==0) { cout<<"YES"<<endl; cout<<i<<" "; cout<<now/b<<endl; return 0; } } cout<<"NO"<<endl; return 0; }
C
/* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) make_pair(a,b) #define pb push_back const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}}; using namespace std; typedef long long ll; map<int, string> mpb; map<string, int> mp; string p[25][205]; int ok[25][205]; int num[25]; int ans[25]; int pop = 0; bool check(string a, string b) { if (b.size() > a.size()) { return false; } for (int i = 0; i < b.size(); i++) { if (a[a.size() - i - 1] != b[b.size() - i - 1]) { return false; } } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int flag; int n; cin >> n; int now; string ch; string ch2; for (int i = 1; i <= n; i++) { cin >> ch >> now; if (!mp[ch]) { mp[ch] = ++pop; mpb[pop] = ch; } for (int j = 1; j <= now; j++) { cin >> ch2; flag=1; for(int k=1;k<=num[mp[ch]];k++) { if(ch2==p[mp[ch]][k]) { flag=0; break; } } if(flag) p[mp[ch]][++num[mp[ch]]] = ch2; } } for (int i = 1; i <= pop; i++) { ans[i] = num[i]; //cout<<ans[i]<<endl; for (int j = 1; j <= num[i]; j++) { for (int k = 1; k <= num[i]; k++) { if (j == k) { continue; } if (check(p[i][k], p[i][j])) { ok[i][j] = 1; ans[i]--; break; } } } } cout << pop << endl; for (int i = 1; i <= pop; i++) { cout << mpb[i] << " "; cout << ans[i] << " "; for (int j = 1; j <= num[i]; j++) { if (!ok[i][j]) { cout << p[i][j] << " "; } } cout << endl; } return 0; }
D
/*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLmaxn = 2e18; const int N = 1e6 + 5; int num[N]; int visit[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> num[i]; visit[num[i]] = 1; } int anser = 0; int now = 0; for (int i = 1; i <= 1000000; i++) { if (!visit[i]) { if ((i - m + 1 >= 1) && visit[i - m + 1]) { now--; } continue; } if (now < k - 1) { now++; } else { visit[i] = 0; //cout << i << endl; anser++; } if ((i - m + 1 >= 1) && visit[i - m + 1]) { now--; } } cout << anser << endl; return 0; }
E
/*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLmaxn = 2e18; const int N = 2e5 + 5; ll num[N]; ll cha[N]; priority_queue<ll, vector<ll>, greater<ll> >q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int sum = 0; int zero = 0; for (int i = 1; i <= n; i++) { cin >> num[i]; ll s = sqrt(num[i]); cha[i] = min(abs(s * s - num[i]), (s + 1) * (s + 1) - num[i]); if (cha[i] == 0) { sum++; } else { q.push(cha[i]); } if (num[i] == 0) { zero++; } } if (sum >= n / 2) { if (sum == n / 2) { cout << 0 << endl; return 0; } if (zero <= n / 2) { cout << sum - n / 2 << endl; } else { cout << sum - zero + (zero - n / 2) * 2 << endl; } return 0; } int t = n / 2 - sum; ll anser = 0; while (t--) { anser += q.top(); q.pop(); } cout << anser << endl; return 0; }
F
以上是关于Codeforces 898的主要内容,如果未能解决你的问题,请参考以下文章
F - Restoring the Expression CodeForces - 898F