Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4786)
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<vector>
- #include<set>
- #include<map>
- #include<functional>
- #include<string>
- #include<cstring>
- #include<cstdlib>
- #include<queue>
- #include<utility>
- #include<fstream>
- #include<sstream>
- #include<cmath>
- #include<stack>
- #include<cstdio>
- #include <ctime>
- using namespace std;
- #define MEM(a,b) memset(a,(b),sizeof(a))
- #define MAX(a,b) ((a) > (b) ? (a) : (b))
- #define MIN(a,b) ((a) < (b) ? (a) : (b))
- #define istr(S) istringstream sin(S)
- #define MP make_pair
- #define pb push_back
- #define inf 1000000000
- #define MAXN 1000000
- typedef long long LL;
- //typedef __int64 LL;
- typedef pair<int,int> pi;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<double> vd;
- typedef vector<pi> vpi;
- struct rect
- {
- int va,vb,vc;
- int ha,hb,hc;
- int type,x1,y1,x2,y2,w,h;
- };
- int getb(int mask,int x) { return (mask&(1<<x)) ? 1 : 0 ; }
- int contains(rect A,rect B)
- {
- if(A.x1<B.x1 && A.y1<B.y1 && A.x2>B.x2 && A.y2>B.y2) return 1;
- return 0;
- }
- rect rects[105];
- int p[105];
- vi edges[105];
- // hor,ver,top,bot,left,right
- void dfs(int u,LL tw,LL th)
- {
- int i,j,k;
- for(i=0;i<edges[u].size();i++)
- {
- int v=edges[u][i];
- int type=rects[v].type;
- LL tl,tspv,tsph;
- tl=getb(type,1)*rects[v].vb+getb(type,2)*rects[v].va+getb(type,3)*rects[v].vc;
- tspv=th - (rects[v].va+rects[v].vb+rects[v].vc -tl );
- if(getb(type,1))
- rects[v].vb = (tspv*rects[v].vb)/tl;
- if(getb(type,2))
- rects[v].va = (tspv*rects[v].va)/tl;
- if(getb(type,3))
- rects[v].vc = (tspv*rects[v].vc)/tl;
- rects[v].y1=rects[u].y1+rects[v].va;
- rects[v].h =rects[v].vb;
- tl=getb(type,0)*rects[v].hb+getb(type,4)*rects[v].ha+getb(type,5)*rects[v].hc;
- tsph=tw - (rects[v].ha+rects[v].hb+rects[v].hc - tl);
- if(getb(type,0))
- rects[v].hb = (tsph*rects[v].hb)/tl;
- if(getb(type,4))
- rects[v].ha = (tsph*rects[v].ha)/tl;
- if(getb(type,5))
- rects[v].hc = (tsph*rects[v].hc)/tl;
- rects[v].x1=rects[u].x1+rects[v].ha;
- rects[v].w =rects[v].hb;
- dfs(v,rects[v].w,rects[v].h);
- }
- }
- int main()
- {
- int i,j,k,tests,cs=0,n,m,w,h;
- while(scanf("%d%d%d%d",&n,&m,&w,&h)==4)
- {
- if(!n && !m && !w && !h) break;
- for(i=0;i<=n;i++)
- edges[i].clear();
- for(i=1;i<=n;i++)
- {
- scanf("%d%d%d%d",&rects[i].x1,&rects[i].y1,&rects[i].w,&rects[i].h);
- int type=0;
- for(j=0;j<6;j++)
- {
- scanf("%d",&k);
- if(k)
- type|=(1<<j);
- }
- rects[i].x2=rects[i].x1+rects[i].w;
- rects[i].y2=rects[i].y1+rects[i].h;
- if(!getb(type,0) && !getb(type,4) && !getb(type,5))
- type|=(1<<5);
- if(!getb(type,1) && !getb(type,2) && !getb(type,3))
- type|=(1<<2);
- rects[i].type=type;
- rects[i].ha=rects[i].x1;
- rects[i].hb=rects[i].w;
- rects[i].va=rects[i].y1;
- rects[i].vb=rects[i].h;
- }
- rects[0].w=w;
- rects[0].h=h;
- for(i=1;i<=n;i++)
- {
- int x=0,best=inf;
- for(j=1;j<=n;j++)
- if(i!=j && contains(rects[j],rects[i]) && rects[j].w<best)
- x=j,best=rects[j].w;
- p[i]=x;
- edges[x].pb(i);
- rects[i].hc = rects[x].w - rects[i].ha - rects[i].hb;
- rects[i].vc = rects[x].h - rects[i].va - rects[i].vb;
- //printf("%d %d %d\n",rects[i].va,rects[i].vb,rects[i].vc);
- }
- ++cs;
- for(i=1;i<=m;i++)
- {
- scanf("%d%d",&w,&h);
- dfs(0,w,h);
- printf("Case %d, resize operation %d:\n",cs,i);
- for(j=1;j<=n;j++)
- {
- printf(" Window %d, x = %d, y = %d, width = %d, height = %d\n",j,
- rects[j].x1,rects[j].y1,rects[j].w,rects[j].h);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement