ural1147 Shaping Regions
生活随笔
收集整理的這篇文章主要介紹了
ural1147 Shaping Regions
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Shaping Regions
Time limit: 0.5 secondMemory 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 3 2 2 18 18 2 0 8 19 19 3 8 0 10 19 4 | 1 91 2 84 3 187 4 38 |
分析:經(jīng)典的覆蓋問(wèn)題,參考http://blog.csdn.net/skyprophet/article/details/4514926,冰塊上浮法;
倒序計(jì)算,在計(jì)算到當(dāng)前矩形時(shí),看在他上面的矩形有沒有重疊的,有就去掉那個(gè)部分,一直遞歸下去即可;
代碼:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, rt<<1 #define Rson mid+1, R, rt<<1|1 const int maxn=3e3+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int n,m,k,t,ans[maxn]; struct node {int x1,x2,y1,y2,c;node(){}node(int _x1,int _x2,int _y1,int _y2,int _c){x1=_x1,x2=_x2,y1=_y1,y2=_y2,c=_c;} }op[maxn]; int get(node p,int nt) {int ans=0;while(nt<=k&&((p.x1>=op[nt].x2)||(p.x2<=op[nt].x1)||(p.y1>=op[nt].y2)||(p.y2<=op[nt].y1)))nt++;if(nt>k)return (p.x2-p.x1)*(p.y2-p.y1);if(p.x1<op[nt].x1)ans+=get(node(p.x1,op[nt].x1,p.y1,p.y2,op[nt].c),nt+1),p.x1=op[nt].x1;if(p.x2>op[nt].x2)ans+=get(node(op[nt].x2,p.x2,p.y1,p.y2,op[nt].c),nt+1),p.x2=op[nt].x2;if(p.y1<op[nt].y1)ans+=get(node(p.x1,p.x2,p.y1,op[nt].y1,op[nt].c),nt+1),p.y1=op[nt].y1;if(p.y2>op[nt].y2)ans+=get(node(p.x1,p.x2,op[nt].y2,p.y2,op[nt].c),nt+1),p.y2=op[nt].y2;return ans; } int main() {int i,j;scanf("%d%d%d",&n,&m,&k);ans[1]=n*m;rep(i,1,k)scanf("%d%d%d%d%d",&op[i].x1,&op[i].y1,&op[i].x2,&op[i].y2,&op[i].c);for(i=k;i>=1;i--){ans[op[i].c]+=(j=get(op[i],i+1));ans[1]-=j;}rep(i,1,2500)if(ans[i])printf("%d %d\n",i,ans[i]);//system("Pause");return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/dyzll/p/5867574.html
總結(jié)
以上是生活随笔為你收集整理的ural1147 Shaping Regions的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Android使用 SO 库时要注意的一
- 下一篇: HTML5 音频 audio