UVA 11292 - Dragon of Loowater
来源:互联网 发布:数据关联算法 编辑:程序博客网 时间:2024/04/27 17:44
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267
直接贪心,从小到大排序,然后比较就ok了
代码如下:
#include <iostream>#include <queue>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <cmath>using namespace std;int i,j;const int N=20010;typedef long long LL;int a[N],b[N];int n,m;int main(){ while(scanf("%d%d",&n,&m)&&(n+m)!=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); int sum=0,cur=0; for(i=0,j=0;i<n;i++) { while(b[j]<a[i]&&j<m) { j++; } if(j>=m) break; if(b[j]>=a[i]) { cur++; sum+=b[j]; j++; } } if(cur>=n) printf("%d\n",sum); else printf("Loowater is doomed!\n"); } return 0;}/*2 3547842 155100 0*/
- uva --11292 --Dragon of Loowater
- UVa 11292 - Dragon of Loowater
- uva - 11292 - Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- uva 11292 - Dragon of Loowater
- Uva-11292-Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- UVA 11292 Dragon of Loowater
- uva 11292 - Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- UVA 11292 Dragon of Loowater
- UVA 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater
- UVA 11292 Dragon of Loowater
- uva 11292 Dragon of Loowater
- UVA - 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater
- TCP长连接与短连接的区别
- ASIHttpRequest异步操作返回数据
- rand()&&srand()
- COM聚合技术中的QueryInterface
- 《c和指针》笔记--宏插入到字符串常量
- UVA 11292 - Dragon of Loowater
- hdoj_2112
- 2008新版眼保健操图解
- 合并排序
- Android开发第3-1课:支持不同的语言
- QT不规则窗体图形(代码+详解)
- C#获取当前时间日期
- Android开发第3-2课:支持不同的屏幕
- 分步学习Struts(四) 自己写Struts框架