【贪心】poj3636 nested dolls
2012-05-27 22:50
302 查看
好水啊好水啊。。。
不过输入输出有点恶心,cout和cin就超时,scanf和printf就AC了。。。
不过输入输出有点恶心,cout和cin就超时,scanf和printf就AC了。。。
#include<iostream> #include<algorithm> #include<stdlib.h> #include<stdio.h> using namespace std; struct Node{ int w,h; }; int cmp(const void* elem1,const void*elem2){ Node *p,*q; p=(Node *)elem1; q=(Node *)elem2; if((p->h)!=(q->h)) return (p->h)-(q->h); else return (q->w)-(p->w); } Node node[20005]; bool selected[20005]; int main(){ int t,n,counter,maximum; scanf("%d",&t); //cin>>t; while(t--){ //cin>>n; scanf("%d",&n); counter=0; for(int i=0;i<n;i++) scanf("%d%d",&node[i].w,&node[i].h); //cin>>node[i].w>>node[i].h; for(int i=0;i<n;i++) selected[i]=false; qsort(node,n,sizeof(Node),cmp); for(int i=0;i<n;i++){ if(selected[i]==true) continue; counter++; maximum=node[i].w; selected[i]=true; for(int j=i+1;j<n;j++){ if(selected[j]==false&&node[j].w>maximum){ selected[j]=true; maximum=node[j].w; } }//end for loop } printf("%d\n",counter); //cout<<counter<<endl; } //system("pause"); return 0; }
相关文章推荐
- 【POJ3636】Nested Dolls Dilworth定理(偏序集定理二)
- AYITACM2016省赛第三周A-Nested Dolls(贪心解嵌套问题)
- hdu1677 Nested Dolls(贪心)
- POJ 3636 俄罗斯Nested Dolls 贪心二分 动态规划
- UVA 11368 & POJ 3636 & HDU 1677 Nested Dolls(贪心 + 二分LIS)
- hdu 1677 Nested Dolls【贪心解嵌套娃娃问题】
- HDOJ 1677 Nested Dolls(贪心+LIS)
- hdu 1677 Nested Dolls(贪心+LIS模板题)
- hdu 1677 Nested Dolls【贪心解嵌套娃娃问题】
- hdu1677--Nested Dolls(贪心+LIS)
- POJ3636Nested Dolls
- 606第十周周六赛E - Nested Dolls 套玩具
- hdu 1677 Nested Dolls 子串
- HDU1677 Nested Dolls
- HDU/HDOJ 1677 Nested Dolls 搜索
- POJ3636 Nested Dolls ACM解题报告(暴力贪心(也可用二分查找降低复杂度))
- EOJ1765 Nested Dolls 最长上升子序列
- hdu----(1677)Nested Dolls(DP/LIS(二维))
- hdu 1677 Nested Dolls (Greedy + Treap)
- HDU 1677:Nested Dolls