zoukankan      html  css  js  c++  java
  • 【模拟7.29】辣鸡

    根据内存,本以为是道数学题,或是数据结构题。

    当然不是,其实正解真的超好想,就是一堆if判断.....

    我们发现成立的情况要么是矩形内部,要么是矩形之间

    显而易见矩形内部就是(长-1)*(宽-1)*2

    矩形之间分情况(先按x1排序 y1次之)

    case 1:(在角上)

    那么最多只有1的贡献

    if(e[j].x1==e[i].x2+1&&(e[i].y2+1==e[j].y1||e[i].y1-1==e[j].y2))
    {
            ans++;
    } 

    case 2:在上下(以上为例)

    因为我们已经按x分好

    所以此时我们只要考虑2种情况

    一种是上面的长度大于下面的,一种小于。

    case 3:在左右

    反正我是分了四种情况,还有各种++操作,有点麻烦......

    大体上就是想加上(两个矩形重复相邻的-1)在加上两个矩形重复相邻部分的上边缘,下边缘,判断一下即可

    算了还是看代码吧

      1 #include<iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<algorithm>
      5 #include<cmath>
      6 #include<string>
      7 #include<vector>
      8 #include<map>
      9 #define int long long 
     10 #define MAXN 110010
     11 using namespace std;
     12 int n;
     13 struct node{int x1;int y1;int x2;int y2;}e[MAXN];
     14 bool cmp(node a,node b)
     15 {
     16      return (a.x1==b.x1)?(a.y1<b.y1):(a.x1<b.x1);
     17 }
     18 int ans=0;
     19 void work1(int x,int y)
     20 {
     21      if(e[y].y1>=e[x].y2+1)return ;
     22      if(e[y].y2<=e[x].y1-1)return ;
     23      int a=e[x].x2,b=e[y].x1;
     24      int c=e[x].y2,d=e[x].y1,ee=e[y].y2,f=e[y].y1;
     25      if(c>=ee&&d<=f)
     26      {
     27          ans+=2*(ee-f);
     28          if(c>=ee+1)
     29          {
     30                ans+=1;
     31          }
     32          if(d<=f-1)
     33          {
     34                ans+=1;
     35          }
     36      }
     37      else if(c<=ee&&d>=f)
     38      {
     39          ans+=2*(c-d);
     40          if(ee>=c+1)
     41          {
     42                ans+=1;
     43          }
     44          if(f<=d-1)
     45          {
     46                ans+=1;
     47          }
     48      }
     49      else if(f<=c&&c<=ee)
     50      {
     51          ans+=2*(c-f);
     52          if(ee>=c+1)
     53          {
     54                ans++;
     55          }
     56          if(d<=f-1)
     57          {
     58                ans++;
     59          }
     60      }
     61      else if(d<=ee&&d>=f)
     62      {
     63          ans+=2*(ee-d);
     64          if(f<=d-1)
     65          {
     66              ans++;
     67          }
     68          if(ee<=c-1)
     69          {
     70              ans++;
     71          }
     72      }
     73      return ;
     74 }
     75 void work2(int x,int y)
     76 {
     77    if(e[x].x2<=e[y].x1-1)return ;
     78    if(e[x].x1>=e[y].x2+1)return ;
     79    if(e[y].x2>=e[x].x2)
     80    {
     81        ans+=2*(e[x].x2-e[y].x1);
     82        int a=e[x].x1,b=e[x].x2,c=e[y].x1,d=e[y].x2;
     83        if(a<=c-1)ans++;
     84        if(b<=d-1)ans++;   
     85       // printf("work2: ans=%lld
    ",ans);
     86    }
     87    else
     88    {
     89        ans+=2*(e[y].x2-e[y].x1);
     90        int a=e[x].x1,b=e[x].x2,c=e[y].x1,d=e[y].x2;
     91        if(a<=c-1)ans++;
     92        if(b>=d+1)ans++;
     93    }
     94    
     95 }
     96 signed main()
     97 {
     98     scanf("%lld",&n);
     99     for(int i=1;i<=n;++i)
    100     {     
    101         scanf("%lld%lld%lld%lld",&e[i].x1,&e[i].y1,&e[i].x2,&e[i].y2);
    102     }
    103     sort(e+1,e+n+1,cmp);
    104     for(int i=1;i<=n;++i)
    105     {
    106          for(int j=i+1;j<=n;++j)
    107          {
    108             //  printf("i=%lld x1=%lld y1=%lld x2=%lld y2=%lld
    j=%lld x1=%lld y1=%lld x2=%lld y2=%lld
    ",i,e[i].x1,e[i].y1,e[i].x2,e[i].y2,j,e[j].x1,e[j].y1,e[j].x2,e[j].y2);
    109               if(e[j].x1>e[i].x2+1)
    110               {
    111                   break;
    112               }       
    113               //printf("%lld %lld
    ",e[i].y2+1,e[i].y1);
    114               if(e[j].x1==e[i].x2+1&&(e[i].y2+1==e[j].y1||e[i].y1-1==e[j].y2))
    115               {
    116                   //printf("work3:
    ");
    117                    ans++;
    118               } 
    119               else if(e[j].x1==e[i].x2+1)
    120               {
    121                  //  printf("work1:
    ");
    122                    work1(i,j);
    123               }
    124               else if(e[j].y1==e[i].y2+1||e[j].y2+1==e[i].y1)
    125               {
    126                //    printf("work2:
    ");
    127                    work2(i,j);
    128               }
    129               //printf("ans=%lld
    ",ans);
    130          }
    131          if(e[i].y2-e[i].y1==0||e[i].x2-e[i].x1==0)continue;
    132          ans+=(e[i].y2-e[i].y1)*(e[i].x2-e[i].x1)*2;
    133          //printf("---------ans=%lld
    ",ans);
    134     }
    135     printf("%lld
    ",ans);
    136 }
    View Code
  • 相关阅读:
    2013.4.15 Particle Swarm Optimization with Skyline Operator for Fast Cloudbased Web Service Composition
    Adaptive service composition in flexible processes
    2013.4.13 DomainSpecific Service Selection for Composite Services
    2013.4.14 Modeling and Algorithms for QoSAware Service Composition in VirtualizationBased Cloud Computing
    2013.5.29 Towards Networkaware Service Composition in the Cloud
    Efficient algorithms for Web services selection with endtoend QoS constraints
    SQL Server中常用的SQL语句
    接口限流自定义注解
    linux服务器生产环境搭建
    MVEL自定义函数重复掉用报错:duplicate function
  • 原文地址:https://www.cnblogs.com/Wwb123/p/11265313.html
Copyright © 2011-2022 走看看