zoukankan      html  css  js  c++  java
  • hoj 13814 Cake cut

    比赛的时候想不出思路 很难受 

    #include<iostream>
    #include <stdio.h>
    #include <limits.h>
    #define LL long long
    using namespace std;
    
    
    const int maxn= (int)1e5+10;
    struct point{
        LL x,y;
        point(){}
        point(LL x,LL y):x(x),y(y){}
        void input(){scanf("%I64d%I64d",&x,&y);}
        void output(){cout<<x<<" "<<y<<endl;}
        point operator - (const point& a){return point(x-a.x,y-a.y);}
        LL operator * (const point &a){return x*a.y-y*a.x;}
    
    };
    point p[maxn];
    template <class T> T abs(T a){return a>=0? a:-a;}
    LL getvol(int n){
        LL res=0;
        for(int i=1;i+1<n;i++) res+=(p[i+1]-p[0])*(p[i]-p[0]);
        return abs(res);
    }
    int n;
    int main()
    {
        #ifdef shuaishuai
        freopen("a.txt","r",stdin);
        #endif // shuaishuai
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            p[i].input();
        }
        LL ans=-1;
        LL sum=getvol(n);
        LL now=abs( (p[2]-p[0])*(p[1]-p[0]) );
        int j=2;
        for(int i=0;i<n;i++){
            while(1){
                LL tmp=now+abs((p[(j+1)%n]-p[i])*(p[j]-p[i]));
                if(abs(sum-tmp-tmp)>abs(sum-now-now)) break;
                //printf("%I64d %I64d %I64d i=%d j=%d
    ",sum,tmp,now,i,j);
    
                j=(j+1)%n;
                now=tmp;
            }
            ans=max(ans,max(sum-now,now));
          //  cout<<ans<<endl;
            now-=abs((p[j]-p[i])*(p[(i+1)%n]-p[i]));
        }
        printf("%I64d %I64d
    ",ans,sum-ans);
        return 0;
    }
  • 相关阅读:
    queue
    hiho1095(二分)
    uvaliva3942(trie树)
    hiho1014(trie树)
    uvalive4329(树状数组)
    Dropping tests POJ
    linux mysql命令
    linux文件系统和mount(硬盘,win分区,光驱,U盘)
    linux共享windows资料
    linux常用命令
  • 原文地址:https://www.cnblogs.com/MeowMeowMeow/p/7291256.html
Copyright © 2011-2022 走看看