hdu4268贪心
来源:互联网 发布:手机八字排盘命理软件 编辑:程序博客网 时间:2024/06/16 00:30
题意:
两个人有一些图片,矩形的,问a最多能够覆盖b多少张图片..
思路:
两个人有一些图片,矩形的,问a最多能够覆盖b多少张图片..
思路:
明显是贪心,但是有一点很疑惑,如果以别人为主,每次都用自己最小的切能覆盖敌人的方法就wa,而以自己为主,去覆盖自己可能覆盖的最大就ac了,证明不了,总感觉这东西在孙子兵法里会有,,解题过程就是先吧两个人的所有卡片放一起以 长 小的在前面,如果 长 相等 id 大的(被覆盖那个)在前面排序,保证每一个卡片能覆盖的一定在自己的前面,然后从1开始跑循环,如果当前的点是被覆盖的点,那么直接把他的y扔进set里,否则就从set里取出一个自己能覆盖的最大的那个卡片,这样遍历到最后就行了,我忘记了题目中的y可能不可能重复了,如果可以重复的话直接把set改成muitiset就行了...
#include<stdio.h>#include<algorithm>#include<map>#include<set>#define N_max 220000#define inf 2000000000using namespace std;typedef struct{ int h ,w ,key;}CARD;CARD card[N_max];bool camp(CARD x ,CARD y){ return x.h < y.h || x.h == y.h && x.w < y.w || x.h == y.h && x.w == y.w && x.key < y.key;}int main (){ int t ,i ,n ,sum; scanf("%d" ,&t); while(t--) { scanf("%d" ,&n); for(i = 1 ;i <= n ;i ++) { scanf("%d %d" ,&card[i].h ,&card[i].w); card[i].key = 1; } for(i = 1 ;i <= n ;i ++) { scanf("%d %d" ,&card[i + n].h ,&card[i + n].w); card[i + n].key = 0; } map<int ,int >mark; set<int>st; sort(card + 1 ,card + n + n + 1 ,camp); sum = 0; st.insert(inf); for(n *= 2 ,i = 1 ;i <= n ;i ++) { if(card[i].key) { int now = *st.lower_bound(-card[i].w); if(now == inf) continue; sum ++; mark[now] --; if(!mark[now]) st.erase(now); } else { st.insert(-card[i].w); mark[-card[i].w] ++; } } printf("%d\n" ,sum); } return 0;}
0 0
- hdu4268贪心
- hdu4268(贪心+set)
- hdu4268 multiset应用 贪心
- hdu4268(贪心+set容器)
- HDU4268 Alice and Bob 【贪心】
- hdu4268
- hdu4268 排序贪心Alice and Bob
- ACM 贪心 STL multiset 二分查找 hdu4268
- hdu4268 Alice and Bob(贪心)
- HDU4268 Alice and Bob【贪心+SET】
- hdu4268 NavigableSet
- hdu4268 Alice and Bob(二维贪心的固定思想 STL的multiset的二分查找函数实现)
- hdu4268 Alice and Bob
- HDU4268 Alice and Bob
- hdu4268 && 2012 Regional Changchun
- hdu4268 Alice and Bob
- hdu4268 Alice and Bob
- hdu4268 Alice and Bob,multiset
- 学习ajax【3】AJAX在PHP中的应用示例
- 判别式模型和产生式模型 (discriminative model and generative model)
- Oracle 查看用户信息
- C++ string
- fw_printenv 配置文件 nand flash
- hdu4268贪心
- jqgrid 去除 clear Search Value 按钮
- Intro to Java Programming, 6E - FigurePanel.java
- CString.Format的详细用法(转)
- java调用脚本
- PadDesigner中添加自己创建的热风焊盘Flash
- How to get current full screen dimention and orientation in run time
- 数据库自我快速学习笔记
- 动态链接库和静态链接库的区别