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. Microsoft SQL Server学习(七)--函数视图

    系统函数 视图 索引 1.系统函数 (1) ()数学函数 Abs() 绝对值 Floor() 向下取整 Ceiling() 向上取整 Sin() 返回指定角度(以弧度为单位)的三角正弦值 Pi() 圆 ...

  2. ElasticSearch学习笔记--一些规范,会持续更新

    我们在ElasticSearch中存储的数据一般是采用json的格式存储,所以ElasticSearch中有一个叫Mapper的东西用来定义jsonschema来规范这个json 但是这个mapper ...

  3. Spring+Spring MVC+Hibernate增查(使用注解)

    使用Spring+Spring MVC+Hibernate做增删改查开发效率真的很高.使用Hibernate简化了JDBC连接数据库的的重复性代码.下面根据自己做的一个简单的增加和查询,把一些难点分析 ...

  4. Java 8 和 Java 9部分区别

    Java 8 和 Java 9中 concurrent 包有了一些改变, 本文对这些改变做了汇总.Java 8 中 Concurrent package的改变java.util.concurrent中 ...

  5. UEditer的使用

    1.首先到官网下载http://ueditor.baidu.com/website/download.html#ueditor 2.然后把解压后的文件复制到项目中(放在UEditer中),如图 3.在 ...

  6. 导出功能在数据库内容为数字,excel表格中是汉字的时候

    代码如下: @ExcelField(title = "饮水器评价",dictType = "waterer_rate" ,align = 2, sort = 2 ...

  7. JavaScipt30(第二个案例)

    承接上篇https://www.cnblogs.com/wangxi01/p/10641115.html,这是第二个案例 附上项目链接: https://github.com/wesbos/JavaS ...

  8. 长久不用的mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    mac上安装过mysql: 然而,尝试连接时报错: $ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to lo ...

  9. python爬虫28 | 你爬下的数据不分析一波可就亏了啊,使用python进行数据可视化

    通过这段时间 小帅b教你从抓包开始 到数据爬取 到数据解析 再到数据存储 相信你已经能抓取大部分你想爬取的网站数据了 恭喜恭喜 但是 数据抓取下来 要好好分析一波 最好的方式就是把数据进行可视化 这样 ...

  10. 【模板】大数乘法(51nod 1027)

    #include<cstdio> #include<cstring> #include<algorithm> #define LL long long #defin ...