Codeforces Round #521 (Div. 3)
Posted acgoto
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #521 (Div. 3)相关的知识,希望对你有一定的参考价值。
题目链接:http://codeforces.com/contest/1077
A.Frog Jumping
解题思路:
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 LL T,a,b,k;///差值相减即可 5 int main(){ 6 while(cin>>T){ 7 while(T--){ 8 cin>>a>>b>>k; 9 cout<<(a-b)*(k/2)+(k%2?a:0)<<endl; 10 } 11 } 12 return 0; 13 }
B.Disturbed People
解题思路:
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 int n,cnt,a[105];///暴力即可 5 int main(){ 6 while(cin>>n){ 7 cnt=0; 8 for(int i=0;i<n;++i)cin>>a[i]; 9 for(int i=1;i<n-1;){ 10 if(a[i-1]&&!a[i]&&a[i+1])cnt++,i+=3; 11 else i++; 12 } 13 cout<<cnt<<endl; 14 } 15 return 0; 16 }
C.Good Array
解题思路:
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int maxn=2e5+5; 5 int n,k,b[maxn];LL a[maxn],sum,tmp;map<LL,int> mp; 6 int main(){ 7 while(~scanf("%d",&n)){ 8 sum=0,k=0;mp.clear(); 9 for(int i=1;i<=n;++i)scanf("%lld",&a[i]),sum+=a[i],mp[a[i]]++;///要用map记录每个数字出现的次数,不能用set容器 10 for(int i=1;i<=n;++i){ 11 if((sum-a[i])&1LL)continue; 12 tmp=(sum-a[i])>>1; 13 mp[a[i]]--; 14 if(mp[tmp])b[k++]=i; 15 mp[a[i]]++; 16 } 17 printf("%d ",k); 18 if(!k)puts(""); 19 for(int i=0;i<k;++i)printf("%d%c",b[i],(i==k-1)?‘ ‘:‘ ‘); 20 } 21 return 0; 22 }
D.Cutting Out
解题思路:
AC代码:
1 #include<iostream> 2 #include<cstdio> 3 #include <map> 4 #include <vector> 5 using namespace std; 6 typedef long long LL; 7 int n, k, x, l, r, mid, t; 8 map<int, int> mp; 9 vector<int> ans, cnt; 10 bool check(int z){ 11 int sum = 0; 12 for (auto num : cnt)sum += num / z; 13 return sum >= k; 14 } 15 int main(){ 16 while (~scanf("%d%d", &n, &k)){ 17 mp.clear(), ans.clear(), cnt.clear(); l = 1, r = n; 18 for (int i = 0; i < n; ++i)scanf("%d", &x), mp[x]++; 19 for (auto y : mp)cnt.push_back(y.second);///保存对应数字出现的次数 20 while (l <= r){///二分查找要切的最大次数 21 mid = (l + r) >> 1; 22 if (check(mid))l = mid + 1;///最大化往右边找 23 else r = mid - 1; 24 } 25 for (auto u : mp){ 26 t = u.second / r; 27 while (t--)ans.push_back(u.first);///第i个元素一次需要取t个 28 } 29 for (int i = 0; i < k; ++i)printf("%d%c", ans[i], i == k - 1 ? ‘ ‘ : ‘ ‘); 30 } 31 return 0; 32 }
以上是关于Codeforces Round #521 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #521 (Div. 3)
Codeforces Round #521 Div. 3 玩耍记
CodeForces Round #521 (Div.3) E. Thematic Contests
CodeForces Round #521 (Div.3) C. Good Array