poj1230 Pass-Muraille (Greedy)
来源:互联网 发布:excel2003无法粘贴数据 编辑:程序博客网 时间:2024/06/05 14:56
#include<iostream>#include <cstdio>#include <cstring>#include <algorithm>//和上一题蛮像的,要先排序再搞,还有就是删区间的时候找最能靠右的删using namespace std;const int N=110;struct node{ int x1,y1,x2,y2;}p[N];bool cmp(node a,node b){ return a.x1<b.x1;}int n,k,a[N];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;}
0 0
- poj1230 Pass-Muraille (Greedy)
- poj1230 Pass-Muraille
- poj1230 Pass-Muraille 贪心算法,形成良好的代码风格很重要
- Pass-Muraille
- Pass-Muraille
- 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( 贪心 )
- poj 1230 Pass-Muraille 贪心
- POJ 1230 Pass-Muraille 贪心
- POJ 1230 Pass-Muraille 贪心
- ios发送http GET和POST请求
- LeetCode题解其一(题1~题5)
- php 面向对象的三大特征 (封装,继承,多态)
- 第一章 绪论 知识导图
- cocos2d-x基本知识点:声音
- poj1230 Pass-Muraille (Greedy)
- 嵌入式系统编程和调试技巧
- Two Sum -- LeetCode [数组类]
- jquery ajax 返回undefined?
- Xcode里-ObjC, -all_load, -force_load
- Android性能优化总结
- 递归算法之类循环组合排列
- Microsoft Speech Platform 自学笔记2 环境要求与安装过程
- C#中的 params、 ref、out关键字,方法返回多个值