(贪心5.1.1)POJ 1230 Pass-Muraille
/*
* POJ_1230.cpp
*
* Created on: 2013年10月9日
* Author: Administrator
*/ #include <iostream>
#include <cstdio> using namespace std; int map[105][105]; int main() {
int t, n, k, x, y, x1, y1, max_x, max_y, sum_s; scanf("%d", &t);
while (t--) {
max_x = 0;
max_y = 0;
sum_s = 0;
memset(map, 0, sizeof(map)); scanf("%d%d", &n, &k);
int i;
for (i = 1; i <= n; ++i) {
scanf("%d%d%d%d", &x, &y, &x1, &y1); if (x > max_x) {
max_x = x;
} if (x1 > max_x) {
max_x = x1;
} if (y > max_y) {
max_y = y;
} int j;
if (x < x1) {
for (j = x; j <= x1; ++j) {
map[j][y] = i;
}
} else {
for (j = x1; j <= x; ++j) {
map[j][y] = i;
}
}
} for (i = 0; i <= max_x; ++i) {
int temp = 0;
int j;
for (j = 0; j <= max_y; ++j) {
if (map[i][j] > 0) {
temp++;
}
} int offset = temp - k;
if (offset > 0) {
sum_s += offset; while (offset--) {
int max_s = 0;
int max_bh = 0;
int k;
for (k = 0; k <= max_y; ++k) {
if (map[i][k] > 0) {
int z;
int temp_s = 0;
for (z = i + 1; z <= max_x; ++z) {
if (map[z][k] == map[i][k]) {
temp_s++;
} else {
break;
}
} if (max_s < temp_s) {
max_s = temp_s;
max_bh = k;
}
}
} int a;
for (a = i; a <= i + max_s; ++a) {
map[a][max_bh] = 0;
}
}
}
} printf("%d\n", sum_s);
} return 0;
}
(贪心5.1.1)POJ 1230 Pass-Muraille的更多相关文章
- zoj 1375||poj 1230(贪心)
Pass-Muraille Time Limit: 2 Seconds Memory Limit: 65536 KB In modern day magic shows, passing t ...
- POJ 1230 Pass-Muraille#贪心+vector迭代器用法
(- ̄▽ ̄)-* (注意下面代码中关于iterator的用法,此代码借鉴某大牛) #include<iostream> #include<cstdio> #include< ...
- (并查集 贪心思想)Supermarket -- POJ --1456
链接: http://poj.org/problem?id=1456 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- 【贪心】Communication System POJ 1018
题目链接:http://poj.org/problem?id=1018 题目大意:有n种通讯设备,每种有mi个制造商,bi.pi分别是带宽和价格.在每种设备中选一个制造商让最小带宽B与总价格P的比值B ...
- 【贪心】Moving Tables POJ 1083
题目链接:http://poj.org/problem?id=1083 题目大意:走廊上的房间如下图设置,现在有n个移动桌子的任务,把桌子从xi移动到yi(整个过程中会占用xi到yi房间之间的走廊), ...
- 贪心-Saruman‘s Army POJ - 3069
万恶之源 目录 题意 思路 贪心的原则是什么呢? 错解 正解 代码实现 书上的代码 我的代码 比较一下 问题 题意 给定若干个点的坐标,与范围R.每个点可以选择是否标记,标记后这个点的左右范围R内的所 ...
- (贪心5.1.2)POJ 2287 Tian Ji -- The Horse Racing
/* * POJ_2287.cpp * * Created on: 2013年10月9日 * Author: Administrator */ #include <iostream> #i ...
- 贪心算法——Fence Repair(POJ 3253)
题目描述 农夫约翰为了修理栅栏,要将一块很长的木板切割成N块.准备切成的木板长度为L1,L2,L3--LN,未切割前木板的长度恰好为切割后木板长度的总和.每次切断木板时,需要的开销为这块木板的长度.请 ...
- POJ 1230 Pass-Muraille
#include<iostream> #include<cstring> using namespace std; ; //(x,y) (x1,y1)墙的两个端点,所有墙最大列 ...
随机推荐
- Struts2 web.xml文件配置
在导入了项目需要使用的核心jar包之后需要在web.xml中配置Struts. 1. Struts2的知识点普及: Struts2共有5类配置文件,分别罗列如下: 1), Web.xml; 在没有使用 ...
- hdu 4815 Little Tiger vs. Deep Monkey
概率dp,有点像背包的做法: dp[i][j]代表前i个数组成的j数的概率为多少 #include<cstdio> #include<cstring> #define maxn ...
- 在8086中,[ idata],[bx]表示内存单元时。可能是一个字节,也可能是一个字。
可能表示一个字节,也可能表示一个字.主要由指令中另一个计算对象决定.如al表示一个字节.ax就表示一个字. 这个区别主要体现在循环中,偏移地址的循环变量是加1还是加2,al是偏移地址加1,ax是偏移地 ...
- Delphi REST和Cloud Services
Paulo: What sort of MVC examples are you looking for? Daniele Teti has some great articles on buildi ...
- JSON对象与JSON数组
一个对象以"{"(左括号)开始,"}"(右括号)结束.每个"名称"后跟一个":"(冒号):""名称/ ...
- Linux IP 路由实现
以下代码取自 kernel . [数据结构] 该结构被基于路由表的classifier使用,用于跟踪与一个标签(tag)相关联的路由流量的统计信息,该统计信息中包含字节数和报文数两类信息. 这个结构包 ...
- ActionBar官方教程(4)给ActionBar添加操作项及它们的事件处理
Adding Action Items The action bar provides users access to the most important action items relating ...
- mysql导出csv/excel文件的几种方法,mysql的load导入csv数据
方法一 php教程用mysql的命令和shell select * into outfile './bestlovesky.xls' from bestlovesky where 1 order by ...
- v2ex上100个话题
V2EX 是创意工作者们的社区. 这里目前汇聚了超过 110,000 名主要来自互联网行业.游戏行业和媒体行业的创意工作者. V2EX在华人IT圈占有举足轻重的地位. 近来闲的蛋疼,按照4个不同的指标 ...
- 如何删除已上线的IAP项
cleared for sale to NO. then Delete.