ACM-ICPC 2015 BeiJing

比赛连接:ACM-ICPC 2015 BeiJing

本次比赛只写了 A G     然后 I题随后补

A

有一个正方形土地,上面有若干块绿洲。让你以x0为界限划一条竖线,要求左边绿洲面积>=右边绿洲面积且两者面积最接近。另外要求左边的土地总面积最大。求x0

二分 or 扫描线

// 二分
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
#define LL long long
struct ac{
  LL  x,y,l,h;
}a[maxn];
LL n;
bool cmp(ac q,ac w){
   return q.x<w.x;
}
LL work(LL mid){
    LL ans=0;
    for(LL j=0;j<n;j++){
        if(a[j].l+a[j].x<=mid){
            ans+=a[j].l*a[j].h;
        }
        else if(a[j].x<=mid&&(a[j].x+a[j].l)>=mid){
            ans+=(mid-a[j].x)*a[j].h;
        }else return ans;
    }
    return ans;
}
int  main(){
   LL  t;
   cin>>t;
   while(t--){
      LL  r,sum=0;
      cin>>r>>n;
      for(LL  j=0;j<n;j++){
         cin>>a[j].x>>a[j].y>>a[j].l>>a[j].h;
         if(a[j].x+a[j].l>=r){
           a[j].l=r-a[j].x;
         }
         sum+=a[j].l*a[j].h;
      }
      //cout<<sum<<endl;
      sort(a,a+n,cmp);
      LL  ll=1,rr=r+1,ans;
      while(ll<rr){
         LL  mid=(ll+rr)/2;
         ans=0;
         LL ans=work(mid);
         if(ans*2<sum){
             ll=mid+1;
         }else rr=mid;
      }
      //cout<<ll<<" "<<rr<<endl;
      ans=work(ll);
      while(work(ll)<=ans&&ll<=r){
          ll++;
      }
      cout<<ll-1<<endl;
   }
}

// 扫描线
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000010
#define LL long long
LL  a[maxn];
int main(){
   LL  t;
   cin>>t;
   while(t--){
      LL  n,r,sum=0;
      cin>>r>>n;
      memset(a,0,sizeof(a));
      for(LL  j=0;j<n;j++){
         LL  x,y,z,zz;
         cin>>x>>y>>z>>zz;
         for(LL k=x+1;k<=x+z;k++){
            a[k]+=zz;
         }
         sum+=(min(r,x+z)-x)*zz;
      }
      LL  ans=0,j;
      for(j=1;j<r&&ans*2<sum;j++){
         ans+=a[j];
         //cout<<ans<<" "<<j<<endl;
      }
      while(a[j]==0&&j<=r){
         j++;
      }
      cout<<j-1<<endl;
   }
}

G

给你四个矩形 选出来三个看是否可以组成新的矩阵

数据很小直接全排列暴力枚举

#include<bits/stdc++.h>
using namespace std;
struct ac{
  int x,y;
}a[10];
int b[10];
bool work(){
   bool i=0;
   int w=a[b[0]].x;
   int h=a[b[0]].y;
   int ww=a[b[1]].x;
   int hh=a[b[1]].y;
   int www=a[b[2]].x;
   int hhh=a[b[2]].y;
   if(w==ww){
      h+=hh;
      i=1;
   }else if(w==hh){
     h+=ww;
     i=1;
   }else if(h==ww){
     w+=hh;
     i=1;
   }else if(h==hh){
     w+=ww;
     i=1;
   }
   if(i==0) return 0;
   i=0;
   if(www==w){
      i=1;
   }else if(w==hhh){
     i=1;
   }else if(h==www){
     i=1;
   }else if(h==hhh){
     i=1;
   }
   if(i)
    return 1;
   else return 0; 
}
int main(){
    int t;
    cin>>t;
    while(t--){
       for(int j=0;j<4;j++){
          cin>>a[j].x>>a[j].y;
          b[j]=j;
       }
       bool fa=0;
       do{
         if(work()){
            fa=1;
            break;
         }
       }while(next_permutation(b,b+4));
       if(fa){
          cout<<"Yes"<<endl;
       }else cout<<"No"<<endl;
    }
}

猜你喜欢

转载自www.cnblogs.com/DyLoder/p/9921873.html