zoukankan      html  css  js  c++  java
  • Water Testing 匹克定理

     题目链接:here

    1.匹克定理:(2*S=2*n+m-2):(n)表示多边形内部的整点数,m表示多边形边界上的整点数,S表示多边形的面积

    2.已知顶点求多边形面积公式:(S=0.5*absleft ( x_{1}ast y_{2}-y_{1}ast x_{2} + x_{2}ast y_{3}-y_{2}ast x_{3}+cdots + x_{n}ast y_{1}-y_{n}ast x_{1} ight ))

    3.已知方向向量为(left ( x,y ight )),求在线段上的点的个数: (b=gcdleft ( abs(x),absleft ( y ight ) ight )) (如果(left ( x_{1},y_{1} ight ))只是一个顶点而不是向量,就要先求出边的向量才能用这个公式)

     1 //n=0.5*(2*S+2-m)=S+1-0.5*m
     2 #include <bits/stdc++.h>
     3 #include <algorithm>
     4 using namespace std;
     5 typedef long long ll;
     6 const int maxn=1e5+10;
     7 const int inf=0x3f3f3f3f;
     8 const int mod=1e9+7;
     9 #define rep(i,first,second) for(ll i=first;i<=second;i++)
    10 #define dep(i,first,second) for(ll i=first;i>=second;i--)
    11 
    12 int n;
    13 struct node{ ll x,y;}p[maxn];
    14 ll b,s;
    15 
    16 int main()
    17 {
    18     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    19     cin>>n;
    20     rep(i,0,n-1){
    21         cin>>p[i].x>>p[i].y;
    22         if( i ){
    23             s+=__gcd(abs(p[i].x-p[i-1].x),abs(p[i].y-p[i-1].y));
    24             b+=(p[i-1].x*p[i].y - p[i].x*p[i-1].y);
    25         }
    26     }
    27     s+=__gcd(abs(p[0].x-p[n-1].x),abs(p[0].y-p[n-1].y));
    28     b+=(p[n-1].x*p[0].y-p[0].x*p[n-1].y);
    29     double S=0.5*fabs(b);
    30     S=S+1-s*0.5;
    31     cout<<(ll)S<<endl;
    32     return 0;
    33 }

    注意:

     1 //Compilation error
     2 //匹克定理:2*S=2*n+m-2:n表示多边形内部的整点数,m表示多边形边界上的整点数,S表示多边形的面积
     3 //已知顶点求多边形面积公式:S=0.5*abs(x1*y2-y1*x2 + x2*y3-y2*x3 +...+ xn*y1-yn*x1)
     4 //已知方向向量为(x,y),求在线段上的点的个数: b=gcd(fabs(x),fabs(y))(如果(x1,y1)只是一个顶点而不是向量,就要先求出边的向量才能用这个公式)
     5 
     6 //n=0.5*(2*S+2-m)=S+1-0.5*m
     7 
     8 #include <bits/stdc++.h>
     9 using namespace std;
    10 typedef long long ll;
    11 const int maxn=1e5+10;
    12 const int inf=0x3f3f3f3f;
    13 const int mod=1e9+7;
    14 #define rep(i,first,second) for(ll i=first;i<=second;i++)
    15 #define dep(i,first,second) for(ll i=first;i>=second;i--)
    16 
    17 int n;
    18 struct node{ double x,y;}p[maxn];
    19 double b,s;
    20 ll gcd(ll a,ll b){
    21     if( b==0 ) return a;
    22     return gcd(b,a%b);
    23 }
    24 
    25 int main()
    26 {
    27     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    28     cin>>n;
    29     rep(i,0,n-1){
    30         cin>>p[i].x>>p[i].y;
    31         if( i ){
    32             s+=gcd(fabs(p[i].x-p[i-1].x),fabs(p[i].y-p[i-1].y));//gcd不可以有double,即是函数强制转换成了ll
    33             b+=(p[i-1].x*p[i].y - p[i].x*p[i-1].y);
    34         }
    35     }
    36     s+=gcd(fabs(p[0].x-p[n-1].x),fabs(p[0].y-p[n-1].y));
    37     b+=(p[n-1].x*p[0].y-p[0].x*p[n-1].y);
    38     double S=0.5*fabs(b);
    39     S=S+1-s*0.5;
    40     cout<<(ll)S<<endl;
    41     return 0;
    42 }
    Compilation error
  • 相关阅读:
    网站学习网站
    ajax利用json进行服务器与客户端的通信
    Json 数据
    Servlet 编程 请求的转发
    Servlet 编程 简单流程处理(重定向)
    Servlet 编程 http请求类型
    myeclipse10 .jsp将表单提交给.java(form网页与后台通信初识)
    myeclipse10 将一个java工程合并到web工程
    myeclipse 第一个web project
    JAVA字符串转日期或日期转字
  • 原文地址:https://www.cnblogs.com/wsy107316/p/12840133.html
Copyright © 2011-2022 走看看