UVa11292
来源:互联网 发布:mac 结构图软件 编辑:程序博客网 时间:2024/06/08 14:48
题目链接
分析:
能力强的骑士开高价是合理的
但是不能大材小用,所以我们直接贪心
把龙和骑士排序之后,
一个一个砍就行了
当然,不能砍掉“当前需要砍掉的头”的骑士我们就不用再考虑ta了
tip
成功的砍掉一个头之后,不要忘了把骑士的指针向后推移一位
附图:
//这里写代码片#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int M=20005; int a[M],b[M]; int main() { int n,m; while(scanf("%d%d",&n,&m)&&n&&m) { int i,j=0,sum=0; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<m;i++) scanf("%d",&b[i]); sort(a,a+n); sort(b,b+m); for(i=0;i<m;i++) if(b[i]>=a[j]) { sum+=b[i]; if(++j==n) break; } if(j<n) printf("Loowater is doomed!\n"); else printf("%d\n",sum); } return 0; }
当然,还有一种更优美的写法:
//这里写代码片#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int n,m;int dragon[20010],knight[20010];int ans=0;int main(){ while (scanf("%d%d",&n,&m)!=EOF&&n&&m) { for (int i=1;i<=n;i++) scanf("%d",&dragon[i]); for (int i=1;i<=m;i++) scanf("%d",&knight[i]); if (n>m) { printf("Loowater is doomed!\n"); continue; } sort(dragon+1,dragon+1+n); sort(knight+1,knight+1+m); ans=0; int cnt=1; for (int i=1;i<=m;i++) if (knight[i]>=dragon[cnt]) { ans+=knight[i]; if (++cnt>n) break; } if (cnt<n) printf("Loowater is doomed!\n"); else printf("%d\n",ans); } return 0;}
阅读全文
0 0
- UVA11292
- UVa11292
- UVa11292
- uva11292
- uva11292
- UVa11292
- Uva11292
- UVA11292
- UVa11292
- UVA11292
- UVa11292
- UVa11292
- UVA11292杀怪
- uva11292--贪心
- uva11292 Dragon of Loowater
- UVA11292:Dragon of Loowater
- UVa11292 Dragon of Loowater
- uva11292 - Dragon of Loowater
- 三条命令解决Git 如何删除远程服务器文件同时保留本地文件
- 爬取环境信息实例
- 上传大文件失败问题记录
- SQLSTATE[HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MySQL server怎么解决?
- 用jQuery实现简单的表单验证
- UVa11292
- 解决使用libhdfs.so连接hdfs出错问题java.lang.ClassNotFoundException: org.apache.hadoop.fs.F
- 在Java中按字节获得字符串长度的两种方法
- redis设置开机启动
- 2017.10.13
- java变量类型的讨论
- 解决wordpress 浏览次数位置调整问题(wp postviews 插入代码)
- SQL 学习笔记
- Android 获取系统服务的源代码分析