首页 > 其他 > 详细

hoj 13814 Cake cut

时间:2017-08-05 20:22:15      阅读:278      评论:0      收藏:0      [点我收藏+]

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

#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;
}

 

hoj 13814 Cake cut

原文:http://www.cnblogs.com/MeowMeowMeow/p/7291256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!