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

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 ;
}

測试赛D - The War(有控制范围的贪心)的更多相关文章

  1. SDUT2013级測试赛_D

    题目描写叙述 给出一棵含有n个点的树.每一个点权值为wi.求从根节点到叶子结点权值和最大的那条路经的权值和是多少. 输入 n(1<= n && n <= 10000). 接 ...

  2. 測试赛C - Eqs(哈希)

    C - Eqs Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  3. WinCE C#程序,控制启动时仅仅能启动一个程序,使用相互排斥量来实现,该实现方法測试通过

    </pre><pre code_snippet_id="430174" snippet_file_name="blog_20140718_5_46349 ...

  4. db_keep_cache_size參数的控制范围測试

    ocm考试新题中.须要创建keep存储的表,但在该參数是否应该改动上,有一些分歧.有人说asmm会自己主动给keep分配内存的,该參数就不用设置了. 看文档和asktom.也是云山雾罩,说什么的都有, ...

  5. springMVC4(5)RestTemplate控制层单元測试

    在前面我们进行web測试,总要在游览器进行.数据组装.请求方法更给等都极为麻烦. RestTemplate是Spring提供的一个web层測试模板类,我们能够通过RestTemplate在client ...

  6. Unityclient通信測试问题处理(二)

    Unityclient通信測试问题处理(二) 在client的通信測试过程中.场景载入的问题给自己带来了不小的麻烦.由于消息的解析方法在单独的监听线程中调用,这也就意味着无法在消息的解析方法中调用Un ...

  7. Maven实现Web应用集成測试自己主动化 -- 部署自己主动化(WebTest Maven Plugin)

    上篇:Maven实现Web应用集成測试自己主动化 -- 測试自己主动化(WebTest Maven Plugin) 之前介绍了怎样在maven中使用webtest插件实现web的集成測试,这里有个遗留 ...

  8. mongodb3.0 性能測试报告 一

    mongodb3.0 性能測试报告 一 mongodb3.0 性能測试报告 二 mongodb3.0 性能測试报告 三 測试环境: 服务器:X86 pcserver   共6台 cpu:  单颗8核 ...

  9. [WebGL入门]十九,遮挡剔除和深度測试

    注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:],另外.鄙人webgl研究还不够深入,一些专业词语,假设翻译有误.欢迎大家指 ...

随机推荐

  1. Python+selenium学习(二) selenium 定位不到元素

    转载:https://www.cnblogs.com/tarrying/p/9681991.html tarrying selenium的三种等待时间 //隐式等待(20秒以内没哥一段时间就会去找元素 ...

  2. ubuntu部署java环境

    一.安装java sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracl ...

  3. 牛客多校Round 10

    咕咕咕.... 去烽火台和兵马俑了

  4. PrintWriter与ServletOutputStream的区别之文件下载

    copy自:https://blog.csdn.net/weixin_37703598/article/details/803870611.out = response.getWriter(); re ...

  5. c++运行程序闪退

        以最简单程序为例       法一:在主函数末尾下一行getchar();即可.需要注意的是这种方法并不适合所有程序,       法二:<1>先在程序开头加上头文件#includ ...

  6. STL二分查找函数的应用

    应用二分查找的条件必须是数组有序! 其中二分查找函数有三个binary_serch,upper_bound,lower_bound 测试数组 int n1[]={1,2,2,3,3,4,5}; int ...

  7. pipreqs(找当前项目依赖的包)

    pipreqs pipreqs可以帮你找到当前项目的所有组件及其版本.就是当别人给你一个程序的时候,你要在自己电脑上运行起来,就需要安装程序所依赖的组件,总不能自己一个一个找吧. # 安装 pip3 ...

  8. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  9. Webstorm如何配置自动补全前缀--autoprefixer

    我们在写样式代码时,对不同平台会有不同的兼容性写法,会在代码前加前缀,但是手动加前缀很费时间而且很容易弄错.Webstorm编辑器是有自带补全前缀功能的,那为什么还要写这篇配置博客,因为Webstor ...

  10. cocos2dx 2.1.x 退出SDK相关界面后EGLView 不刷新渲染

    报错内容为: [3390:1456879] failed to call contextcocos2d: surface size: 0x0[3390:1456879] Failed to make ...