Ural1147 (Shaping Regions) rectangular cutting

Source: Internet
Author: User
Tags cmath

 

A matrix of 10000*10000 with an initial color of 1 and a maximum of 2500 coloring times. The area of a rectangle is painted into a specific color, ask the final area of each color after painting.

 

Solution: inverted computing, rectangular cutting

 

Code:

/******************************************************* @author:xiefubao*******************************************************/#pragma comment(linker, /STACK:102400000,102400000)#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include #include 
       
        #include
        #include 
         
          #include 
          
           #include 
           
            //freopen (in.txt , r , stdin);using namespace std;#define eps 1e-8#define zero(_) (abs(_)<=eps)const double pi=acos(-1.0);typedef long long LL;const int Max=2510;const int INF=1e9+7;struct rec{ int x1,x2,y1,y2; int color;} recs[Max];int A,B;int n;int getans(int x1,int x2,int y1,int y2,int p){ while((p<=n)&&(x1>=recs[p].x2||x2<=recs[p].x1||y1>=recs[p].y2||y2<=recs[p].y1)) p++; if(p>n) return (x2-x1)*(y2-y1); int ans=0; if(x1
            
             recs[p].x2) ans+=getans(recs[p].x2,x2,y1,y2,p+1),x2=recs[p].x2; if(y2>recs[p].y2) ans+=getans(x1,x2,recs[p].y2,y2,p+1),y2=recs[p].y2; if(y1
             
              =1; i--) { int tool=getans(recs[i].x1,recs[i].x2,recs[i].y1,recs[i].y2,i+1); ans[recs[i].color]+=tool; ans[1]-=tool; } for(int i=1; i<=2500; i++) if(ans[i]) printf(%d %d,i,ans[i]); } return 0;}/*20 20 32 2 18 18 20 8 19 19 38 0 10 19 4*/
             
            
           
          
         
       
      
     
    
   
  
 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.