Cake cut

Problem description
Carol and Carla are roommates. Yesterday they threw a big party and today they have a partially eaten cake that they want to divide. Since people were careless when cutting themselves a slice, the cake is now shaped as a prism with its top and bottom faces being the same simple convex polygon. To add some fun to the process of dividing the cake, the girls came up with the following game.
Carol chooses a vertex v of the top face of the cake. Carla chooses another vertex w of the top face that is not adjacent to v. Then, they cut the cake into two pieces by extending downwards the segment vw, so as to obtain two separate pieces of cake, each in the shape of a prism. Finally, Carol chooses the piece that she prefers, and Carla gets the other one. Carla immediately saw that this system gives Carol an advantage. Carla wants to know exactly how much of an advantage Carol has.
You are given a polygon that represents both the top and bottom faces of the cake. The height of the cake is 2, so the volume of a piece of cake is 2 times the area of its top face. Assuming the cake is divided as explained, and that both girls make their decisions to maximize the volume of the piece they have at the end, compute the volume of the piece each girl will get.
Input
The first line contains an integer N representing the number of vertices of the polygonal top face of the cake (4 ≤ N ≤ 105). Each of the next N lines describes a vertex of the polygon with two integers X and Y , indicating the coordinates of the vertex in the XY plane (-108 ≤ X; Y ≤ 108). Vertices are given in counter clockwise order and define a simple convex polygon. No three points in the input are collinear.

Output
Output a line with two integers representing the volume of the piece Carol and Carla will get, in that order, if both make their decisions optimally.


Sample Input
Sample input 1
5
0 0
3 0
3 1
2 2
0 1

Sample input 2
6
0 1
1 0
2 0
3 1
2 2
0 2

Sample input 3
4
-100000000 -100000000
100000000 -100000000
100000000 100000000
-100000000 100000000

Sample input 4
4
-99999995 -100000000
100000000 -100000000
100000000 99999995
-100000000 100000000
Sample Output
Sample output 1
7 2

Sample output 2
6 3

Sample output 3
40000000000000000 40000000000000000

Sample output 4
39999999999999975 39999998000000025
Problem Source
ICPC Latin American Regional -2015

用旋转卡壳来降低复杂度

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
struct point{
    ll x,y;
}p[maxn];
int n;
ll s,a;
ll getarea(point a,point b,point c){
    return a.x*b.y+b.x*c.y+c.x*a.y-c.x*b.y-a.x*c.y-b.x*a.y;
}
int main(){
     scanf("%d",&n);
     for(int i=0;i<n;i++) scanf("%I64d%I64d",&p[i].x,&p[i].y);
     for(int i=2;i<n;i++) s+=getarea(p[0],p[i-1],p[i]);
     //printf("%I64d\n",s);
     int j=2;
     ll cur=getarea(p[0],p[1],p[2]),nx;
     for(int i=0;i<n;i++){
        if(i) cur-=getarea(p[i-1],p[i],p[j%n]);
        while(1){
            nx=cur+getarea(p[i],p[j%n],p[(j+1)%n]);
            if(abs(s-2*cur)<abs(s-2*nx)) break;
            j++;
            cur=nx;
        }
        a=max(a,max(cur,s-cur));
     }
     printf("%I64d %I64d",a,s-a);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值