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\n",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\n",ans,sum-ans);
    return 0;
}

 

posted @ 2017-08-05 20:04  MeowMeowMeow  阅读(101)  评论(0编辑  收藏  举报