UVALive 7146 Defeat the Enemy (贪心+STL)
来源:互联网 发布:正在监听80端口 编辑:程序博客网 时间:2024/05/14 11:14
思路:将攻击方按攻击力排序,防御方按防御力排序,对于每一个攻击力大于防御力的,就找有没有一个攻击方的防御力比防御方的攻击力高的,有则必定是最优解
#include<bits/stdc++.h>using namespace std;#define LL long longconst int maxn = 1e5+6;struct Node{int att;int def;}a[maxn],b[maxn];bool cmp1(Node a,Node b){return a.att>b.att;}bool cmp2(Node a,Node b){return a.def>b.def;}multiset<int>vis;int main(){int T,cas=1;scanf("%d",&T);while(T--){printf("Case #%d: ",cas++);vis.clear(); int n,m;scanf("%d%d",&n,&m);for(int i = 1;i<=n;i++)scanf("%d%d",&a[i].att,&a[i].def);for(int i = 1;i<=m;i++)scanf("%d%d",&b[i].att,&b[i].def);sort(a+1,a+1+n,cmp1);sort(b+1,b+1+m,cmp2);int ans = 0;int flag = 1;for(int i = 1,j=1;j<=m;j++){while(i<=n&&a[i].att>=b[j].def)vis.insert(a[i++].def);if(vis.empty()){printf("-1\n");flag=0;break;}set<int>::iterator it = vis.upper_bound(b[j].att);if(it!=vis.end())vis.erase(it);else vis.erase(vis.begin()),ans++;}if(flag)printf("%d\n",n-ans);}}
0 0
- UVALive 7146 Defeat the Enemy (贪心+STL)
- UVALive 7146 Defeat the Enemy (贪心)
- UVALive 7146 Defeat the Enemy (贪心)
- UVALive 7146-贪心&数据结构stl-Defeat the Enemy
- UVALive 7146Defeat the Enemy贪心
- UVALive-7146 Defeat the Enemy (map+贪心)
- UVALive 7146 Defeat the Enemy(模拟)
- UVALive 7146 Defeat the Enemy
- UVA 7146 Defeat The Enemy (贪心)
- UVA Live 7146 Defeat the Enemy(贪心+set)
- UVA Live 7146 Defeat the Enemy——STL
- UVA LIVE 7146 Defeat the Enemy
- UVA 7146 Defeat The Enemy 2014 ACM-ICPC Asia shanghai Regional Contest
- 2014年上海赛区现场赛 I 题 Defeat the Enemy
- hdu4145 Cover The Enemy(贪心+枚举)
- UVALive - 3507 Keep the Customer Satisfied 贪心
- UVALive 2757Supermarket(贪心)
- UVALive 6834Shopping (贪心)
- Ubuntu中python切换及pip 安装相应python库
- 【Android】 Exception小结
- 第11周OJ实践 求最大公约数和最小公倍数
- 飞线
- BIOS/UEFI基础——EDK编译生成的二进制的结构
- UVALive 7146 Defeat the Enemy (贪心+STL)
- 下载分享永不关机 几步玩转家庭NAS组建
- 用邻接表存储有向图并实现DFS(递归+非递归)BFS(非递归)两种遍历
- Activity四种启动模式
- Android:InflateException: Binary XML file line #12: Error inflating class null
- MongoDB(三)索引
- 使用JLink烧写bin文件到S3c2440
- Android内核之运行自定义内核
- 实体类返回对象的改善