The War
来源:互联网 发布:get it right 编辑:程序博客网 时间:2024/05/16 18:30
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 are N (1 <= N <= 2500) unarmed soldier in your kingdom and there are M (1 <= M <= 40000) weapons in your arsenal. Each weapon has a weight W (1 <= W <= 1000), and for soldier i, he can only arm the weapon whose weight is between minWi 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
题意为给定一个士兵所承受的重量范围,让其挑选兵器。
将承重范围和兵器的重量都进行从小到大的排序,再用两个循环进行筛选
<span style="font-size:18px;color:#33cc00;">#include <iostream>#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int u,v;}zhong[2511];int cmp(struct node a,struct node b){ return a.v<b.v;}int main(){ int n,m,i,j,num; int a[40014]; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) scanf("%d%d",&zhong[i].u,&zhong[i].v); for(i=0;i<m;i++) scanf("%d",&a[i]); sort(zhong,zhong+n,cmp); sort(a,a+m); num=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(a[i]>=zhong[j].u&&a[i]<=zhong[j].v&&a[i]!=-1&&zhong[j].v!=-1) { num++; a[i]=-1; zhong[j].v=-1; } } } printf("%d\n",num); }}</span>
- The War
- Pacifism and the War
- 352The Seasonal War
- zoj 3508 the war
- ZOJ 3508 The War
- The War&&贪心算法
- zoj 3500 The War
- deploy the war project
- zoj3508 The War 贪心
- HDOJ 4005 The war
- HDU 4005 The war
- The War(Zoj 3508)
- ZOJ-3508-The War
- What's the WAR
- War of the Worlds
- The Trojan War------Greek mythology
- Who are the War Criminals?
- ZOJ 3508 The War 贪心
- select, poll和epoll (ZZ)
- 容器框架的探索思绪日记
- POJ 1204Word Puzzles 字典树
- 如何防止客户端被破解
- 02-3. 逆序的三位数(10)
- The War
- OpenCV学习C++接口 Mat像素遍历详解
- poj 2411 编程之美-瓷砖覆盖地板
- 拓扑排序Sorting It All Out
- 求解 :在最后为什么输出的整形数字是-858993460,,应该不是溢出错误
- POJ 1258 Agri-Net最小生成树 prim
- STL源码解析 - nth_element
- 数组和指针
- 关于Java中两个数组的复制(b=a)