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个黑色的点可能会使得原先白色的点 ...
随机推荐
- C++指针初始化总结
1.字符指针的初始化 在c语言中 "string"保存的就是首个字符所在的地址 所以可以把 字符串常量"string" 赋值给指针 char *p; &qu ...
- 飘逸的python - 性能调优利器profile及其意义
VIM 的作者Bram Moolenaar在一篇叫高效文本编辑器的7个习惯的ppt中有这么一段话. Three basic steps 1. Detect inefficiency 2. ...
- 【转】Android中自动连接到指定SSID的Wi-Fi
最近在做一个项目,其中涉及到一块“自动连接已存在的wifi热点”的功能,在网上查阅了大量资料,五花八门,但其中一些说的很简单,即不能实现傻瓜式的拿来就用,有些说的很详细,但其中不乏些许错误造成功能无法 ...
- ubuntu 14.04 下试用Sublime Text 3
很多源代码都没有IDE支持的,尤其是开源的源代码.从github上下载的,很多也不用IDE.包括我自己公司的代码,基本都是脚本,也不用IDE.通常情况下,都是用notepad++.UE之类的文本编辑器 ...
- UIScrollView上面放一个UIScrollView或者UITableView拖动时候 View出现一闪一闪解决办法
在项目中发现一个问题: 创建一个UIScrollView 上面放一个scrollView或者TableView,拖动scrollview或TableView 画面出现一闪一闪的情况. 解决办法设置一下 ...
- 文件系统 busybox and initramfs
1.busybox制作根文件系统 http://wenku.baidu.com/link?url=h2m_xrj6OsLiHVVhMY2e0C7WKikw_H3dZY_b4mUiW1E7AEf_q34 ...
- 一般处理程序、ASP.NET核心知识(5)--转载
初窥 1.新建一个一般处理程序 新建一个一般处理程序 2.看看里头的代码 public class MyHandler : IHttpHandler { public void ProcessRequ ...
- Ajax请求安全性讨论 - Eric.Chen(转)
Ajax请求安全性讨论 - Eric.Chen 时间 2013-07-23 20:44:00 博客园-原创精华区 原文 http://www.cnblogs.com/lc-chenlong/p/3 ...
- MVC中的AppendTrailingSlash以及LowercaseUrls
asp.net MVC是一个具有极大扩展性的框架,可以在从Url请求开始直到最终的html的渲染之间进行扩展,所以要学好还是需要了解框架的运行原理,推荐Artech. 今天我们回忆的不是MVC中的fi ...
- sql 模糊查询带下划线的字段 _
1.SELECT * FROM dbo.tb_Test 2.SELECT * FROM dbo.tb_Test WHERE name LIKE '%c_%' 3.SELECT * FROM dbo.t ...