poj1230 Pass-Muraille (Greedy)
2014-09-18 00:49
423 查看
#include<iostream> #include <cstdio> #include <cstring> #include <algorithm> //和上一题蛮像的,要先排序再搞,还有就是删区间的时候找最能靠右的删 using namespace std; const int N=110; struct node{ int x1,y1,x2,y2; }p ; bool cmp(node a,node b){ return a.x1<b.x1; } int n,k,a ; int main(){ int t; cin>>t; while(t--){ cin>>n>>k; memset(a,0,sizeof(a)); int maxwall=-1; for(int i=0;i<n;i++){ scanf("%d%d%d%d",&p[i].x1,&p[i].y1,&p[i].x2,&p[i].y2); if(p[i].x1>p[i].x2)swap(p[i].x1,p[i].x2); for(int j=p[i].x1;j<=p[i].x2;j++)a[j]++; maxwall=max(maxwall,p[i].x2); } sort(p,p+n,cmp); int ans=0; for(int i=0;i<=maxwall;i++){//maxwall,,,, while(a[i]>k){ ans++; int mx=-1,pos; for(int j=0;j<n;j++){ if(p[j].x1<=i && p[j].x2>=i && mx<p[j].x2) pos=j,mx=p[j].x2; } for(int j=p[pos].x1;j<=p[pos].x2;j++) a[j]--; p[pos].x1=p[pos].x2=-1; } } cout<<ans<<endl; } return 0; }
相关文章推荐
- POJ 1230 Pass-Muraille
- poj 1230 Pass-Muraille 贪心
- POJ 1230 Pass-Muraille 贪心
- POJ-1230 Pass-Muraille
- POJ 1230 Pass-Muraille
- POJ 1230 Pass-Muraille
- POJ-1230-Pass-Muraille
- poj 1230 Pass-Muraille
- poj 1230 Pass-Muraille
- POJ 1230 Pass-Muraille (贪心)
- (贪心5.1.1)POJ 1230 Pass-Muraille
- POJ 1230 Pass-Muraille 笔记
- poj 1230 Pass-Muraille( 贪心 )
- (贪心5.1.1)POJ 1230 Pass-Muraille
- POJ_1230_Pass-Muraille
- POJ 1230 Pass-Muraille (贪心)
- POJ 1230 Pass-Muraille 贪心
- POJ 1230 Pass-Muraille#贪心+vector迭代器用法
- poj1230 Pass-Muraille 贪心算法,形成良好的代码风格很重要
- Greedy:Packets(POJ 1017)