POJ 1230 Pass-Muraille (贪心)
2017-03-09 16:57
369 查看
思路:
从小到大扫,遇到不合格的列就对所有边进行遍历找出包含这一列的边并计算此边到最右边的长度 删最长边。
#include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <cmath> #include <algorithm> #include <map> #define pi acos(-1) #define gg 9.87 #define eps 1e-9 typedef long long int lli; using namespace std; struct edge{ int x,y,x2,y2; }ed[110]; int ans; int n,k; int vis[110]; void f(){ for(int i = 0;i <= 100;++i){ if(vis[i] > k){ int maxlen = 0, pos = 0; int r = 0,l = 0; for(int j = 1;j <= n;++j){ l = min(ed[j].y,ed[j].y2); r = max(ed[j].y,ed[j].y2); if(i >= l && i <= r && r-i >= maxlen){ maxlen = r - i; pos = j; } } l = min(ed[pos].y,ed[pos].y2); r = max(ed[pos].y,ed[pos].y2); ed[pos].y2 = -1,ed[pos].y = -1;// 一开始忘了删边了。。 for(int i = l;i <= r;++i){ vis[i]--; } ans++; i--; } } } int main(){ int t; cin>>t; while(t--){ ans = 0; memset(vis,0,sizeof(vis)); memset(ed,0,sizeof(ed)); scanf("%d%d",&n,&k); for(int i = 1;i <= n;++i){ scanf("%d%d%d%d",&ed[i].y,&ed[i].x,&ed[i].y2,&ed[i].x2); int l = min(ed[i].y,ed[i].y2); int r = max(ed[i].y,ed[i].y2); for(int i = l;i <= r;++i){ vis[i]++; } } f(); printf("%d\n",ans); } }
相关文章推荐
- POJ 1230 Pass-Muraille 贪心
- (贪心5.1.1)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
- POJ 1230 Pass-Muraille
- POJ-1230-Pass-Muraille
- POJ 1230 Pass-Muraille
- POJ 1230 Pass-Muraille 笔记
- poj1230 Pass-Muraille (Greedy)
- POJ-1230 Pass-Muraille
- poj 1230 Pass-Muraille
- poj 1230 Pass-Muraille
- POJ 1230 Pass-Muraille
- zoj 1375||poj 1230(贪心)
- poj 1230 贪心法
- poj1230 贪心