POJ 1265 Area pick定理

http://poj.org/problem?id=1265

求凸多边形上,凸多边形内的整点个数 以及凸多边形的面积...

pick 定理 : S = L/2 + N -1 

S为多边形的面积 , L为多边形上整点的个数 , N为多边形内整点的个数 

多边形上点的个数 对两个端点的横纵左边的绝对值做GCD就可以求得

多边形面积对相邻两点用叉积/2 后相加就可求得

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

#define EPS         1e-8
#define MAXN        (int)1e5+5
#define MOD         (int)1e9+7
#define PI          acos(-1.0)
#define LINF        ((1LL)<<50)
#define INF            (1<<30);
#define max(a,b)    ((a) > (b) ? (a) : (b))
#define min(a,b)    ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG         cout<<"BUG! "<<endl
#define LINE        cout<<"--------------"<<endl
#define L(t)        (t << 1)
#define R(t)        (t << 1 | 1)
#define Mid(a,b)    ((a + b) >> 1)
#define lowbit(a)   (a & -a)
#define FIN            freopen("in.txt","r",stdin)
#define FOUT        freopen("out.txt","w",stdout)
#pragma comment     (linker,"/STACK:102400000,102400000")

// typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
int gcd(int a,int b){ return b?gcd(b,a%b):a; }
int lcm(int a,int b){ return a*b/gcd(a,b); }

/*********************   F   ************************/
struct POINT{
    double x,y;
    POINT(double _x = 0, double _y = 0):x(_x),y(_y){};
};
double multiply(POINT sp,POINT ep,POINT op){
    return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y);
}
POINT p[MAXN];
int POINT_OnSeg(POINT a,POINT b){
    return gcd((int)fabs(a.x-b.x),(int)fabs(a.y-b.y));
}
int main()
{
    //FIN;
    //FOUT;
    int T;
    cin>>T;
    for(int t = 1 ; t <= T ; t++){
        int n;
        cin>>n;
        cin>>p[0].x>>p[0].y;
        for(int i = 1 ; i < n ; i++){
            double xx, yy;
            cin>>xx>>yy;
            p[i].x = p[i-1].x + xx;
            p[i].y = p[i-1].y + yy;
        }
        p[n] = p[0];
        double area = 0;
        for(int i = 0 ; i < n ; i++)
            area += multiply(POINT(0,0),p[i],p[i+1])/2;
        int onside = 0;
        for(int i = 0 ; i < n ; i++)
            onside += POINT_OnSeg(p[i],p[i+1]);
        int inside = area + 1 - onside / 2;
        printf("Scenario #%d:\n",t);
        printf("%d %d %.1lf\n\n",inside,onside,area);
   }
    return 0;
}

 

转载于:https://www.cnblogs.com/Felix-F/p/3243067.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值