Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #pragma warning(disable:4786)
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<set>
  7. #include<map>
  8. #include<functional>
  9. #include<string>
  10. #include<cstring>
  11. #include<cstdlib>
  12. #include<queue>
  13. #include<utility>
  14. #include<fstream>
  15. #include<sstream>
  16. #include<cmath>
  17. #include<stack>
  18. #include<cstdio>
  19. #include <ctime>
  20.  
  21.  
  22. using namespace std;
  23.  
  24. #define MEM(a,b) memset(a,(b),sizeof(a))
  25. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  26. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  27. #define istr(S) istringstream sin(S)
  28. #define MP make_pair
  29. #define pb push_back
  30. #define inf 1000000000
  31. #define MAXN 1000000
  32.  
  33. typedef long long LL;
  34. //typedef __int64 LL;
  35.  
  36. typedef pair<int,int> pi;
  37. typedef vector<int> vi;
  38. typedef vector<string> vs;
  39. typedef vector<double> vd;
  40. typedef vector<pi> vpi;
  41.  
  42. struct rect
  43. {
  44. int va,vb,vc;
  45. int ha,hb,hc;
  46. int type,x1,y1,x2,y2,w,h;
  47. };
  48.  
  49. int getb(int mask,int x) { return (mask&(1<<x)) ? 1 : 0 ; }
  50.  
  51. int contains(rect A,rect B)
  52. {
  53. if(A.x1<B.x1 && A.y1<B.y1 && A.x2>B.x2 && A.y2>B.y2) return 1;
  54. return 0;
  55. }
  56.  
  57. rect rects[105];
  58. int p[105];
  59. vi edges[105];
  60.  
  61. // hor,ver,top,bot,left,right
  62.  
  63. void dfs(int u,LL tw,LL th)
  64. {
  65. int i,j,k;
  66.  
  67. for(i=0;i<edges[u].size();i++)
  68. {
  69. int v=edges[u][i];
  70. int type=rects[v].type;
  71.  
  72. LL tl,tspv,tsph;
  73.  
  74. tl=getb(type,1)*rects[v].vb+getb(type,2)*rects[v].va+getb(type,3)*rects[v].vc;
  75. tspv=th - (rects[v].va+rects[v].vb+rects[v].vc -tl );
  76.  
  77. if(getb(type,1))
  78. rects[v].vb = (tspv*rects[v].vb)/tl;
  79. if(getb(type,2))
  80. rects[v].va = (tspv*rects[v].va)/tl;
  81. if(getb(type,3))
  82. rects[v].vc = (tspv*rects[v].vc)/tl;
  83. rects[v].y1=rects[u].y1+rects[v].va;
  84. rects[v].h =rects[v].vb;
  85.  
  86. tl=getb(type,0)*rects[v].hb+getb(type,4)*rects[v].ha+getb(type,5)*rects[v].hc;
  87. tsph=tw - (rects[v].ha+rects[v].hb+rects[v].hc - tl);
  88.  
  89. if(getb(type,0))
  90. rects[v].hb = (tsph*rects[v].hb)/tl;
  91. if(getb(type,4))
  92. rects[v].ha = (tsph*rects[v].ha)/tl;
  93. if(getb(type,5))
  94. rects[v].hc = (tsph*rects[v].hc)/tl;
  95.  
  96. rects[v].x1=rects[u].x1+rects[v].ha;
  97. rects[v].w =rects[v].hb;
  98.  
  99.  
  100. dfs(v,rects[v].w,rects[v].h);
  101. }
  102. }
  103.  
  104. int main()
  105. {
  106. int i,j,k,tests,cs=0,n,m,w,h;
  107.  
  108. while(scanf("%d%d%d%d",&n,&m,&w,&h)==4)
  109. {
  110. if(!n && !m && !w && !h) break;
  111.  
  112. for(i=0;i<=n;i++)
  113. edges[i].clear();
  114.  
  115. for(i=1;i<=n;i++)
  116. {
  117. scanf("%d%d%d%d",&rects[i].x1,&rects[i].y1,&rects[i].w,&rects[i].h);
  118.  
  119. int type=0;
  120.  
  121. for(j=0;j<6;j++)
  122. {
  123. scanf("%d",&k);
  124. if(k)
  125. type|=(1<<j);
  126. }
  127.  
  128. rects[i].x2=rects[i].x1+rects[i].w;
  129. rects[i].y2=rects[i].y1+rects[i].h;
  130.  
  131. if(!getb(type,0) && !getb(type,4) && !getb(type,5))
  132. type|=(1<<5);
  133.  
  134. if(!getb(type,1) && !getb(type,2) && !getb(type,3))
  135. type|=(1<<2);
  136.  
  137. rects[i].type=type;
  138.  
  139. rects[i].ha=rects[i].x1;
  140. rects[i].hb=rects[i].w;
  141.  
  142. rects[i].va=rects[i].y1;
  143. rects[i].vb=rects[i].h;
  144. }
  145.  
  146. rects[0].w=w;
  147. rects[0].h=h;
  148.  
  149. for(i=1;i<=n;i++)
  150. {
  151. int x=0,best=inf;
  152.  
  153. for(j=1;j<=n;j++)
  154. if(i!=j && contains(rects[j],rects[i]) && rects[j].w<best)
  155. x=j,best=rects[j].w;
  156.  
  157.  
  158. p[i]=x;
  159. edges[x].pb(i);
  160. rects[i].hc = rects[x].w - rects[i].ha - rects[i].hb;
  161. rects[i].vc = rects[x].h - rects[i].va - rects[i].vb;
  162.  
  163. //printf("%d %d %d\n",rects[i].va,rects[i].vb,rects[i].vc);
  164.  
  165. }
  166.  
  167. ++cs;
  168. for(i=1;i<=m;i++)
  169. {
  170. scanf("%d%d",&w,&h);
  171. dfs(0,w,h);
  172.  
  173. printf("Case %d, resize operation %d:\n",cs,i);
  174. for(j=1;j<=n;j++)
  175. {
  176. printf(" Window %d, x = %d, y = %d, width = %d, height = %d\n",j,
  177. rects[j].x1,rects[j].y1,rects[j].w,rects[j].h);
  178. }
  179. }
  180.  
  181.  
  182.  
  183. }
  184. return 0;
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement