ural 1147. Shaping Regions 几何
来源:互联网 发布:苹果手机网络卡怎么办 编辑:程序博客网 时间:2024/06/09 20:35
1147. Shaping Regions
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
N opaque rectangles (1 ≤ N ≤ 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures of different colors will be seen.
The coordinate system has its origin (0, 0) at the sheet's lower left corner with axes parallel to the sheet's borders.
Input
The order of the input lines dictates the order of laying down the rectangles. The first input line is a rectangle “on the bottom”. First line contains A, B and N, space separated (1 ≤ A, B ≤ 10000). Lines 2, …, N + 1 contain five integers each: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is color (1 ≤ color ≤ 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed.
Output
The output should contain a list of all the colors that can be seen along with the total area of each color that can be seen (even if the regions of color are disjoint), ordered by increasing color. Do not display colors with no area.
Sample
20 20 32 2 18 18 20 8 19 19 38 0 10 19 4
1 912 843 1874 38
题意: 对照案例, 有20*20个格子, 有三次涂颜色的操作, 接下来涂颜色,输入坐标和颜色 llx, lly, urx, ury, color。 后涂会覆盖之前涂的,最后输出的是个个颜色的面积,没涂颜色的算颜色1。
做法: 几何,从第一个开始, 处理第一个的时候不断找其上层的 有没有覆盖他, 有的话去掉覆盖的部分继续 处理剩下的部分。
#include<stdio.h>#include<string.h>#define max(a,b) a>b?a:b#define min(a,b) a<b?a:bstruct rectangle {int x1,y1,x2,y2; int c; };int cal(int x1,int y1,int x2,int y2){return (x2-x1)*(y2-y1);} rectangle rect[1100];int area_num[2600];//1-2500 int area_cal(int x1,int y1,int x2,int y2,const int& k,const int& n){int kk;for(int i=k+1;i<=n+1;i++){if(i==n+1)return cal(x1,y1,x2,y2);if(x1>=rect[i].x2||x2<=rect[i].x1||y1>=rect[i].y2||y2<=rect[i].y1)//没有覆盖continue; else{kk=i;break;}}int sum=0;if(x1<rect[kk].x1){sum+=area_cal(x1,y1,rect[kk].x1,y2,kk,n);x1=rect[kk].x1;}if(x2>rect[kk].x2){ sum+=area_cal(rect[kk].x2,y1,x2,y2,kk,n); x2=rect[kk].x2;}if(y1<rect[kk].y1){ sum+=area_cal(x1,y1,x2,rect[kk].y1,kk,n); y1=rect[kk].y1;}if(y2>rect[kk].y2){ sum+=area_cal(x1,rect[kk].y2,x2,y2,kk,n); y2=rect[kk].y2;} return sum;}int main(){int a,b,n;while(scanf("%d%d%d",&a,&b,&n)!=EOF){memset(area_num,0,sizeof area_num);area_num[1]=a*b;for(int i=1;i<=n;i++){scanf("%d%d%d%d%d",&rect[i].x1,&rect[i].y1,&rect[i].x2,&rect[i].y2,&rect[i].c);}for(int i=n;i>=1;i--){int tem=area_cal(rect[i].x1,rect[i].y1,rect[i].x2,rect[i].y2,i,n);area_num[rect[i].c]+=tem;area_num[1]-=tem;}for(int i=1;i<=2500;i++){if(area_num[i])printf("%d %d\n",i,area_num[i]); } } return 0; }/*20 20 32 2 18 18 20 8 19 19 38 0 10 19 44 4 21 1 3 3 32 2 4 4 2 右上4 4 21 1 3 3 30 2 2 4 2 左上 1 912 843 1874 38*/
0 0
- ural 1147. Shaping Regions 几何
- URAL 1147 Shaping Regions
- Shaping Regions
- [URAL 1147][USACO rect1]Shaping Regions(矩形切割)
- [U]3.1.4 Shaping Regions 递归,计算几何
- USACO 3.1 Shaping Regions
- 【模拟】【USACO】Shaping Regions
- usaco Shaping Regions
- Shaping Regions解题报告
- usaco 3.1 Shaping Regions
- USACO:Shaping Regions
- USACO-Shaping Regions
- USACO 3.1 Shaping Regions
- URAL1147 Shaping Regions
- usaco Shaping Regions
- usaco6.2.3 Shaping Regions
- 3.1 Shaping Regions 漂浮法
- USACO / Shaping Regions (矩形分割)
- 使用 Hadoop 和 Hive 获取机器数据
- 解决url传递中文参数乱码问题
- Python 元组
- linux内核源码“双向链表list_head”
- Keil中自定义快捷键的方法
- ural 1147. Shaping Regions 几何
- Python 字典(Dictionary)
- 移动设备,屏幕自适应问题解决方法
- jsp页面中JSTL/EL标签引用java后台静态static字段的方法总结
- linux内核源码“双向链表list_head”续
- java 学习写架构必会几大技术点
- QT5.3 下的CMAKE MANUAL
- struts2和CKFinder的整合(java版)
- poj 3070(矩阵快速幂)