POJ 1230 Pass-Muraille (贪心)
来源:互联网 发布:自动填写表单软件 编辑:程序博客网 时间:2024/05/29 15:28
思路:
从小到大扫,遇到不合格的列就对所有边进行遍历
找出包含这一列的边并计算此边到最右边的长度 删最长边。
#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-9typedef 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); }}
0 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 贪心
- (贪心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
- POJ 1230 Pass-Muraille
- POJ 1230 Pass-Muraille 笔记
- Pass-Muraille
- C#分布式云平台功能及使用说明
- myeclipse安装jdk
- js 操作当前鼠标点击的 事件 解决 div ul 下拉框事件
- 【上机笔试之六】Hash应用
- java中深拷贝和浅拷贝
- POJ 1230 Pass-Muraille (贪心)
- Java-IO笔记
- Android 漏洞分析入门 (一)
- android 7.1特性
- spark streaming 实现kafka的createDirectStream方式!!不坑
- SQLite3总结
- web.xml 中的listener、 filter、servlet 加载顺序及其详解
- 排序之简单插入排序(数组)
- 展讯芯片