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个黑色的点可能会使得原先白色的点 ...
随机推荐
- Array vs Linked List
Access: Random / Sequential 1. Array element can be randomly accessed using index 2. Random access f ...
- Spiral Matrix II 解答
Question Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral or ...
- hbase单机安装
1.网上内容比较混乱,其实安装单机hbase只需要安装hbase即可 2.把hbase-0.xxx.tart.gz 拷贝到/opt/hbase文件及下(这是安装目录,可自定义) 2.1 tar xfz ...
- 2014 BDTC 參会有感
中国大数据技术大会(Big Data Technology Conference,BDTC)是眼下国内最具影响.规模最大的大数据领域的技术盛会. 大会的前身是Hadoop中国云计算大会(Hadoop ...
- JavaScript(19)jQuery HTML 获取和设置内容和属性
jQuery HTML jQuery 拥有可操作 HTML 元素和属性的强慷慨法. jQuery DOM 操作 jQuery 中非常重要的部分,就是操作 DOM 的能力.jQuery 提供一系列与 D ...
- 使用ant自动编译、打包生成apk文件
上次使用命令行生成apk文件<Android 命令行编译.打包生成apk文件>,学习命令行生成的目的是为了编写ant打下基础. 一. ant环境 下载ant包,配置环境变量 二.ant编译 ...
- html5lib-python doc
http://html5lib.readthedocs.org/en/latest/ By default, the document will be an xml.etree element ins ...
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- java public protect default private
(1)对于public修饰符,它具有最大的访问权限,可以访问任何一个在CLASSPATH下的类.接口.异常等.它往往用于对外的情况,也就是对象或类对外的一种接口的形式. (2)对于protected修 ...
- sql service重置自动增长字段数字的方法
1.--SQL表重置自增长字段(不删除表的数据) DBCC CHECKIDENT('表名', RESEED, 起始数) 2.--删除表数据的同时,重置自动增长字段 truncate table 表名