题目链接: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

解题思路:题意已说得很清楚了,只要找到满足a[i-1]==1&&a[i]==0&&a[i+1]==1,那么就关掉第i-1和第i+1间房间的灯(其状态值改为0),若满足条件--->i+=3,表示当前的灯已熄灭,只需站到第i+3间房间继续检查即可。

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

解题思路:统计所有元素之和:sum,然后枚举每个元素,令tmp=(sum-a[i])>>1表示原数组删去a[i]后剩余元素之和的一半,由"好的数组"定义可知,如果(sum-a[i])为奇数,则剩下的元素肯定不能分成相等的两部分;否则只需检查tmp是否在剩下的元素当中,若是则归纳答案!

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\n",k);
18         if(!k)puts("");
19         for(int i=0;i<k;++i)printf("%d%c",b[i],(i==k-1)?'\n':' ');
20     }
21     return 0;
22 }

D.Cutting Out

解题思路:题目要求找出k个元素组成的集合t,使得每次删去集合s中包含t集合中的k个元素,并且最大化删除的次数,典型的二分查找答案!先统计每个元素出现的次数cnt_i,再通过二分查找最大化删除的次数z,二分条件为∑cnt_i/z≥k,如果为True,则向右找更大的删除次数,否则向左找较小的删除次数,最后每个元素被挑选的个数就为cnt_i/z',简单输出集合t中的k个元素即可。

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 ? '\n' : ' ');
30     }
31     return 0;
32 }

转载于:https://www.cnblogs.com/acgoto/p/9974594.html

Codeforces Round #521 (Div. 3)相关推荐

  1. B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)

    原题链接: https://codeforces.com/contest/1077/problem/B 样例: Examples Input 10 1 1 0 1 1 0 1 0 1 0 Output ...

  2. Codeforces Round #521 (Div. 3) B - Disturbed People (贪心)

    题目链接:http://codeforces.com/contest/1077/problem/B 题意:给你一长度为n的01序列.0表示当前位置的房子灯是灭的,1表示当前房子的位置灯是亮的.判断某个 ...

  3. CodeForces Round #521 (Div.3) B. Disturbed People

    http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...

  4. Codeforces Round #521 (Div.3)题解

    A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...

  5. Codeforces Round #521 (Div. 3): F. Pictures with Kittens(DP+单调队列)

    题意: 你有n幅画,第i幅画的好看程度为ai,再给你两个数字k,x,表示你要从中选出刚好x幅画,并且相邻两幅画的距离不能≥k,好看程度之和最大能多少,选不出来输出-1,F1数据范围<200,F2 ...

  6. Codeforces Round #521 (Div. 3) B. Disturbed People

    There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...

  7. Codeforces Round #521 (Div. 3) B. Disturbed People 思维

    题解 题目大意 n个灯0关灯1开灯 101则中间的睡不着 问最少关掉多少个灯可以全都能睡着 遇见101则将后面的1的灯泡关掉 这样解决10101的问题 计数输出即可 AC代码 #include < ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. eclipse svn 与资源库同步 符号说明
  2. 神策数据携手百丽国际,专注品牌零售行业数字化未来
  3. Debug Docker: Error response from daemon: dial unix docker.raw.sock: connect: connection refused
  4. CG CTF CRYPTO Keyboard
  5. Undo TableSpace ①.管理方法
  6. Leet Code OJ 231. Power of Two [Difficulty: Easy]
  7. 基于动态混合高斯模型的商品价格模型算法
  8. Mybatis 别名机制,自动扫描 数据的增删改
  9. 实操教程:Android部署Nanodet模型完成实时高效的物体检测
  10. 同时带多个文件生成软盘镜像的方法
  11. 多米诺喷码机维修大全之----缺字、字体不成形、字体跑点以及歪
  12. lnmp一键安装的步骤
  13. ubuntu ssh远程连接
  14. arcgis api 4.X 比例尺的添加
  15. 从键盘上获取英文字符并转换大小写(C语言) 9.25
  16. 62道开发人员面试经典题
  17. springboot采用协同过滤算法的家政服务平台的设计与实现毕业设计源码260839
  18. 古文选读161篇--蔡礼旭老师选
  19. FastJson1.2.24反序列化导致任意命令执行漏洞复现(CVE-2017-18349)
  20. 梦想太远,现实太近 3

热门文章

  1. WindowsServer和普通WIN操作系统有什么不同?
  2. php页面在线人数,也谈php网站在线人数统计
  3. python for循环九九乘法表_python—用for循环、while循环和一句话打印九九乘法表
  4. python 面向对象_Python新手入门【面向对象】
  5. Java 抖音授权登录
  6. 网络营销——网络营销专员如何应对网站关键词排名波动情况?
  7. 优化网站设计方案提升网站用户回头率
  8. 猜拳小程序c语言编程,无聊的时候写的猜拳小程序
  9. python时间序列因果检验_Python Statsmodels的时间序列Ljung_Box检验
  10. # 定义四边形_数学教研——认识四边形