日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ural1147 Shaping Regions

發布時間:2024/1/17 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ural1147 Shaping Regions 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Shaping Regions

Time limit: 0.5 second
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

inputoutput
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

分析:經典的覆蓋問題,參考http://blog.csdn.net/skyprophet/article/details/4514926,冰塊上浮法;

   倒序計算,在計算到當前矩形時,看在他上面的矩形有沒有重疊的,有就去掉那個部分,一直遞歸下去即可;

代碼:  

#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; }

轉載于:https://www.cnblogs.com/dyzll/p/5867574.html

總結

以上是生活随笔為你收集整理的ural1147 Shaping Regions的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。