ZOJ 3508 ——The War 贪心
来源:互联网 发布:kendalltau python 编辑:程序博客网 时间:2024/05/17 03:46
A war had broken out because a sheep from your kingdom ate some grasses which belong to your neighboring kingdom. The counselor of your kingdom had to get prepared for this war. There areN (1 <= N <= 2500) unarmed soldier in your kingdom and there areM (1 <= M <= 40000) weapons in your arsenal. Each weapon has a weightW (1 <= W <= 1000), and for soldier i, he can only arm the weapon whose weight is betweenminWi and maxWi ( 1 <= minWi <= maxWi <= 1000). More armed soldier means higher success rate of this war, so the counselor wants to know the maximal armed soldier he can get, can you help him to win this war?
Input
There multiple test cases. The first line of each case are two integers N, M. Then the following N lines, each line contain two integers minWi, maxWi for each soldier. Next M lines, each line contain one integer W represents the weight of each weapon.
Output
For each case, output one integer represents the maximal number of armed soldier you can get.
Sample Input
3 31 53 75 104892 25 1010 20421
Sample Output
20
贪心,不多说了....
#include <stdio.h>#include <algorithm>using namespace std;int wq[40001];struct shb{ int mn; int mx; int nwq;}ls[2501];int cmpsb(struct shb a,struct shb b){ if(a.mn==a.mn) return a.mx<b.mx; return a.mn<b.mn;}int cmpwq(int a,int b){ return a<b;}int main(){ int n,m,i,j,js; while(~scanf("%d%d",&n,&m)) { js=0; for(i=0;i<n;i++) { scanf("%d%d",&ls[i].mn,&ls[i].mx); ls[i].nwq=0; } for(i=0;i<m;i++) { scanf("%d",&wq[i]); } sort(ls,ls+n,cmpsb); sort(wq,wq+m,cmpwq); j=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(wq[i]>=ls[j].mn&&wq[i]<=ls[j].mx&&ls[j].nwq==0) { ls[j].nwq=1; js++; break; } } } printf("%d\n",js); } return 0;}
- ZOJ 3508 ——The War 贪心
- ZOJ 3508 The War 贪心
- ZOJ 3508 The War 贪心
- ZOJ 3508 The War(贪心)
- zoj 3508 The War 贪心
- ZOJ 3508 The War(贪心)
- ZOJ-#3508 The War(贪心)
- ZOJ——3508 The War
- zoj 3508 the war
- ZOJ 3508 The War
- The War(Zoj 3508)
- ZOJ-3508-The War
- ZOJ 3058 The War(简单贪心)
- ZOJ 3508 (the war)
- zoj 3500 The War
- The War&&贪心算法
- zoj3508 The War 贪心
- UVa 11729 Commando War——贪心
- unix环境高级编程复习-文件I/O(2)
- Hdu1404 Digital Deletions(暴力SG博弈)
- Word Break II
- poj 1276 Cash Machine
- 数字电路设计之同步电路的一些经验
- ZOJ 3508 ——The War 贪心
- Hibernate getCurrentSession 与 openSession() 的区别
- 【最短路径floyd算法】HDU 1869---六度分离
- 静态字典树和动态字典树模板
- 深入Linux设备驱动程序内核机制读书笔记
- IOS中延时执行的几种方式的比较和汇总
- dijkstra完整模板
- Android客户端和Servlet服务端的JSON传输(注释详细到啰嗦的地步,欢迎新手学习)
- 循环-06. 统计一行文本的单词个数