测试赛D - The War(有控制范围的贪心)
2014-07-30 14:53
330 查看
D - The War
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status
Description
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
Sample Output
贪心的问题,人可以使用的有一些范围,武器有重量,唯一要解决的问题就是在一个人的控制范围内包含另一个人的,这种情况要让范围小的先找
y有小到大,如果y相同时x由小到大。
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status
Description
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 3 1 5 3 7 5 10 4 8 9 2 2 5 10 10 20 4 21
Sample Output
2 0
贪心的问题,人可以使用的有一些范围,武器有重量,唯一要解决的问题就是在一个人的控制范围内包含另一个人的,这种情况要让范围小的先找
y有小到大,如果y相同时x由小到大。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct node{ int x , y ; } p[2600]; int q[1200] ; bool cmp(node a,node b) { return a.y < b.y || ( a.y == b.y && a.x < b.x ) ; } int main() { int i , j , n , m ; while(scanf("%d %d", &n, &m) !=EOF ) { memset(q,0,sizeof(q)); for(i = 0 ; i < n ; i++) scanf("%d %d", &p[i].x, &p[i].y); while(m--) { scanf("%d", &i); q[i]++ ; } m = 0 ; sort(p,p+n,cmp); for(i = 0 ; i < n ; i++) { int l = p[i].x , r = p[i].y ; for(j = l ; j <= r ; j++) if( q[j] ) { q[j]--; m++ ; break; } } printf("%d\n", m); } return 0 ; }
相关文章推荐
- 毕业设计翻译的文章-系统范围内挂钩本地API控制进程的创建
- 设置成本控制范围对话框
- 给公司代码分配信贷控制范围
- Java学习笔记 Java调用Win32 API控制鼠标活动范围
- 地图坐标与屏幕坐标的转换&&控制地图显示范围的参数
- 该页正在访问其控制范围之外的数据。这有些危险。是否继续?
- matlab绘图的坐标轴数字、范围、间隔控制
- --hdu2717->搜索的范围控制
- ASP.NET 字体控制数量范围
- WdatePicker插件来实现开始和结束时间选择范围控制
- 如何控制百度地图的显示范围 ios软件开发
- 基础算法(二分,贪心):NOIP 2012 疫情控制
- AE+C#控制Globe操作范围
- 使用WdatePicker时间插件简单的控制页面上两个时间选择的前后范围
- Fibonacci Again(多次取模控制范围)
- matlab绘图的坐标轴数字、范围、间隔控制
- 使用JS闭包控制对象属性访问范围
- AE+C#控制Globe操作范围
- Ext.form.DateField简单用法及日期范围控制
- 纯JS控制DIV选择范围移动与复制