codeforces-gym-100187-F【贪心】
来源:互联网 发布:无心整合包捏脸数据 编辑:程序博客网 时间:2024/05/31 11:04
题目链接:点击打开链接
大意:世界末日在 t 秒后要来了,n 个人,m 个避难所,一个避难所最多容纳 k 个人,每个人一秒只能走 1 米,给出所有人,所有避难所的位置(都位于同一直线上),问最后最多几个人可以活下来。
思路:就是贪心,一直挂在 test11 上,后来改了才过。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,k,t;int a[200010],b[200010];int main(){while(~scanf("%d%d%d%d",&n,&m,&k,&t)){for(int i=0;i<n;i++)scanf("%d",a+i);for(int i=0;i<m;i++)scanf("%d",b+i);sort(a,a+n);sort(b,b+m);int ans=0,j=0;for(int i=0;i<m;i++){int v=k;while(j<n&&a[j]-t<=b[i]&&v) // 这里注意一下,只要人往左走最大能走到避难所的左边,且此时避难所有空位置,那么不管这个人能不能进去,都去换下一个人上 {if(a[j]+t>=b[i]){ans++;v--;}j++;}if(j==n)break;}printf("%d\n",ans);}return 0;}
0 0
- 【Codeforces Gym 100187F 】+ 贪心
- codeforces-gym-100187-F【贪心】
- Gym 100187F (贪心+覆盖)
- codeforces Gym 101102F
- Codeforces-GYM-100726F
- Codeforces GYM 100803F
- Codeforces gym 101350F 想法
- Codeforces Gym 101142 F. Folding
- Codeforces Gym 101164 F. Letter
- GYM 101173 F.Free Figurines(贪心)
- codeforces gym 100342F Move to Front
- codeforces gym 101142 F(思维)
- Codeforces Gym 100642 C D F
- Codeforces Gym-101116-F (Flight Plan)
- Gym - 101102F F. Exchange 贪心、简单题
- F. Madness Codeforces 822F 贪心 构造
- Codeforces Gym 100623F Problem F. Fenwick Tree
- 【Codeforces Gym 100187A】
- mysql 数据插入时的一些问题
- JSON Web Tokens(JWT)介绍
- 驱动程序无法通过使用安全套接字层(SSL)......
- sjoj学习笔记 1008 二哥买期货
- git教程(四)--使用GIT SUBTREE集成项目到子目录
- codeforces-gym-100187-F【贪心】
- maven简介
- Codeup 算法笔记2.7 指针E
- 在Chrome中查看ssl证书
- 解决yum安装报错Protected multilib versions
- Android的swift语言Kotlin中文开发文档
- ZOJ
- 指向父类的指针可以指向子类的对象
- C++_Operator Overloading(运算符重载 | 计算有理数的加减乘除)