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个黑色的点可能会使得原先白色的点 ...
随机推荐
- Apache本地服务无法自启动问题解决
问题描述: Windows不能在本地计算机启动Apache2.有关更多信息,查阅系统事件日志.如果这是非Microsoft服务,请与服务厂商联系,并参考特定服务错误代码1. 解决方案: 1.检查Apa ...
- hdu4536-XCOM Enemy Unknown(爆搜)
XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...
- 【PAT L2-001】最短路计数
给定一个无向带权网络,无负边,无重边和自环,每个顶点有一个正数权值.首先求特定原点s到终点d的最短路的个数:然后求所有最短路中顶点权值a[i]之和最大的那条,输出这条路径. 可用dijkstra算法求 ...
- QString转换为char*
QString在Qt里相当于C++里的std::string,或者是C里的c style string.不过,QString跟编码相关,在低层想把一个QString发送出去相当麻烦,尤其对方用的不是Q ...
- java算法之冒泡排序法
由此可见:N个数字要排序完成,总共进行N-1趟排序,每第 i 趟的排序次数为 (N-i) 次,所以 可以用双重循环语句,外层控制循环多少趟,内层控制每一趟的循环次数,即 for(inti=0;i& ...
- (3)选择元素——(6)属性选择器(Attribute selectors)
Attribute selectors are a particularly helpful subset of CSS selectors. They allow us to specify an ...
- A10 平板开发二搭建Android开发环境
我是直接在Ubuntu 12.10 64位系统下操作的,搭建Ubuntu开发环境类似,见Ubuntu 10.04开发环境配置.需要注意的是,64位的系统,需要安装支持32位的库(sudo apt-ge ...
- 免费自学Cocos2d-x3.0final2014原创视频教程(56集)(适用于Cocos2d-x3.1 Cocos2d-x3.2版本号全)
Cocos2d-x3.0final(适用于Cocos2d-x3.1 Cocos2d-x3.2版本号全) 视频播放地址:http://yun.itxdl.cn/course/62 视频下载地址:http ...
- AJAX 控件集之TextBoxWatermark(水印文本框)控件
功能: 可以让TextBox控件初始化的时候拥有水印文字.属性: TargetControlID :要使用具有水印效果的TextBox控件ID. WatermarkCssCla ...
- .net 地址栏传中文乱码 的解决方法
1.设置web.config文件. <system.web> ...... <globalization requestEncoding="gb2312" res ...