HDU 3634 City Planning (离散化)
City Planning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 483 Accepted Submission(s): 203
Mr Wan only draw one building on a construction design drawings(all the buildings are rectangle and each edge of buildings' is paraller or perpendicular to others buildings' edge ). And total draw n drawings (all the drawings have same width and length . And bottomleft point is (0, 0)). Due to possible overlap of conditions, so when they build a new building, they should to remove all the overlapping part of it. And for each building, HDU have a jury evaluate the value per unit area. Now Mr dragon want to know how to arrange the order of build these buildings can make the highest value.
Each test case will begin with a single line containing a single integer n (where 1 <= n <= 20).
Next n line will contain five integers x1, y1, x2, y2 ,value . x1,y1 is bottomleft point and x2,y2 is topright point , value is the value of the buildings' unit area.((0 <= x1, y1, x2, y2 <= 10000) (x1 < x2, && y1 < y2) (1 <= value <= 22)
3
1 1 10 10 4
4 4 15 5 5
7 8 20 30 6
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 50
struct Rect
{
int x1, x2, y1, y2, val;
bool operator < (const Rect &r) const{
return val < r.val;
}
};
Rect r[maxn];
int val[maxn][maxn];
int x[maxn], y[maxn];
int main()
{
int t, n;
int cas = ;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
int cnt = ;
for(int i = ; i < n; i++,cnt+=)
{
scanf("%d%d%d%d%d", &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2, &r[i].val);
x[cnt] = r[i].x1; x[cnt+] = r[i].x2;
y[cnt] = r[i].y1; y[cnt+] = r[i].y2;
}
sort(r, r + n);
sort(x, x + cnt);
sort(y, y + cnt);
memset(val, , sizeof val);
for(int i = ; i < n; i++)
{
int x1 = lower_bound(x, x + cnt, r[i].x1) - x;
int x2 = lower_bound(x, x + cnt, r[i].x2) - x;
int y1 = lower_bound(y, y + cnt, r[i].y1) - y;
int y2 = lower_bound(y, y + cnt, r[i].y2) - y;
//printf("%d %d %d %d\n", x1, x2, y1, y2);
for(int j = x1; j < x2; j++)
for(int k = y1; k < y2; k++)//将一个大矩形,分成一个一个小矩形。
val[j][k] = r[i].val;
}
long long ans = ;
for(int i = ; i < cnt-; i++)
for(int j = ; j < cnt-; j++)
ans +=(long long) val[i][j]*(x[i+] - x[i]) *(y[j+] - y[j]);
printf("Case %d: %I64d\n", ++cas, ans);
}
return ;
}
HDU 3634 City Planning (离散化)的更多相关文章
- hdu 3624 City Planning(暴力,也可扫描线)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- hdu 3436 splay树+离散化*
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)
Walk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- hdu 5258 数长方形 离散化
数长方形 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5258 Des ...
- hdu 4358 Boring counting 离散化+dfs序+莫队算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意:以1为根节点含有N(N <= 1e5)个结点的树,每个节点有一个权值(weight ...
- HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)
Coconuts Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- Coconuts HDU - 5925 (二维离散化求连通块的个数以及大小)
题目链接: D - Coconuts HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点 ...
随机推荐
- HashMap Java Doc
原文 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneab ...
- MySql 中的常见问题解决方法
一.关键字做字段 ,mssql的做法是[关键字],mysql的做法是 `关键字` ;ps:(` 是 tab键上面的一个按键) 二.mssql数据导入到mysql: 1.mssql导出insert语句( ...
- mycat实例(2)
全局序列号 数据切分后,原有的关系数据库中的主键约束在分布式条件下将无法使用,因此需要引入外部机制保证数据唯一性标识,这种保证全局性的数据唯一标识的机制就是全局序列号(sequence). 1. 本地 ...
- Android应用程序安装过程源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6766010 Android系统在启动的过程中, ...
- Android窗口管理服务WindowManagerService对窗口的组织方式分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8498908 我们知道,在Android系统中, ...
- Android编译过程详解(二)
通过上篇文章,我们分析了编译android时source build/envsetup.sh和lunch命令,在执行完上述两个命令后, 我们就可以进行编译android了. 1. make 执行ma ...
- ASP.NET MVC 阻止当前请求的视图页面缓存OutputCache
设置缓存 [OutputCache(Duration =333,VaryByCustom ="Index")] 缓存: //在action中,临时阻止该次请求的视图页面缓存 Res ...
- 在SQL SERVER中批量替换字符串
update [表名] set [字段名]=replace([字段名],'被替换原内容','替换后内容')
- C# 获取配置文件节点值
<?xml version="1.0" encoding="utf-8" ?><configuration> <appSetti ...
- Git(Repo)常用命令收集
(注意: 只记录工作中实际使用的命令) 同步android源码 repo sync:(可加-c,只取当前分支: 可加-j4,线程数量) 查看android源码下所有项目的git状态 rep ...