zoj3508 The War 贪心
来源:互联网 发布:单片机程序100例 编辑:程序博客网 时间:2024/05/16 14:52
题目大意:有n个人,w件武器,武器只有一个属性,重量。每个人,都有个区间 [l,r] ,他只可以拿这个区间重量的武器。而且,每个人都最多拿一件武器。问,最多能有多少个人能拿到武器?
初一想,是匹配,但是时间要超。认真一想,似乎和求有多少个不相交区间,那道贪心很像。
认真想了想,确实是贪心。
我们先按线段右值从小到大排序,然后对于右值最小的那个,如果可以拿武器,一定拿可以拿的最轻的那个武器。
思路其实和“有多少个不相交区间”差不多,就是就线段情况分三类讨论,说明不会更优。
//#pragma comment(linker, "/STACK:102400000,102400000")#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<cmath>#include<cctype>#include<string>#include<algorithm>#include<iostream>#include<ctime>#include<map>#include<set>using namespace std;#define MP(x,y) make_pair((x),(y))#define PB(x) push_back(x)typedef long long LL;//typedef unsigned __int64 ULL;/* ****************** */const int INF=1000111222;const double INFF=1e200;const double eps=1e-8;const LL mod=1000000007;const int NN=2510;const int MM=100010;/* ****************** */struct LINE{ int l,r; bool operator<(const LINE &tt)const { return r<tt.r; }}line[NN];multiset<int>Myset;int main(){ int n,m; int t,i,ans; multiset<int>::iterator it; while(scanf("%d%d",&n,&m)!=EOF) { Myset.clear(); ans=0; for(i=1;i<=n;i++) { scanf("%d%d",&line[i].l,&line[i].r); } sort(line+1,line+1+n); for(i=0;i<m;i++) { scanf("%d",&t); Myset.insert(t); } Myset.insert(100000); for(i=1;i<=n;i++) { it=Myset.lower_bound(line[i].l); if(*it<=line[i].r) { ans++; Myset.erase(it); } } printf("%d\n",ans); } return 0;}
0 0
- zoj3508 The War 贪心
- ZOJ3508 The War 贪心,最大流
- The War&&贪心算法
- ZOJ 3508 The War 贪心
- ZOJ 3508 The War 贪心
- ZOJ 3508 The War(贪心)
- zoj 3508 The War 贪心
- ZOJ 3508 The War(贪心)
- ZOJ 3058 The War(简单贪心)
- ZOJ 3508 ——The War 贪心
- ZOJ-#3508 The War(贪心)
- The War
- Commando War-uva 贪心
- 【贪心】【Uva11729】 Commando War
- Commando War uva11729(贪心)
- UVA11729 Commando War (贪心)
- 测试赛D - The War(有控制范围的贪心)
- Commando War UVa 11729(贪心)
- 寒假第四天--排序--选夫婿1
- 寒假第四天--排序--排排站
- WinForm的一些写法技巧【待续】
- STM32学习笔记(1):GPIO口的使用
- Practical UML Statecharts in C/C++ 序言
- zoj3508 The War 贪心
- 排序方法
- Postfix服务操作
- STM32学习笔记(2):外部中断的使用
- 白话经典算法系列之七 堆与堆排序
- 来学习的第一周
- Tomcat基于Coyote的HTTP 1.1协议连接器
- STM32学习笔记(3):系统时钟和SysTick定时器
- 最小生成树之prim算法