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;
    }
  • 相关阅读:
    using 关键字有两个主要用途:
    Pl/SQL 从零开始
    SQL从零开始
    wcf 从零开始
    设置主键
    dbf导入sqlserver
    SHBrowseForFolder
    oracle 导入导出数据库
    sql改列名
    Delphi 为Edit或是Memo添加一个气球提示
  • 原文地址:https://www.cnblogs.com/MeowMeowMeow/p/7291256.html
Copyright © 2011-2022 走看看