hoj 13814 Cake cut

Posted MeowMeowMeow

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

 

以上是关于hoj 13814 Cake cut的主要内容,如果未能解决你的问题,请参考以下文章

HDU4762 Cut the Cake

HDOJ4328 Cut the cake

HDU4328 Cut the cake(动规:最大子矩形问题/悬线法)

1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts (M)

leetcode1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts

非常简短的片段:PHP word cut