• poj2954Triangle


    传送门

    Pick定理

    定点坐标为整点的三角形,面积为S,边上的整点个数为L,三角形内部整点个数为N

    S=N+L/2-1

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 typedef long long LL;
    16 typedef double db;
    17 using namespace std;
    18 LL x[10],y[10];
    19 
    20 template<typename T>void read(T &x)  {
    21     char ch=getchar(); x=0; T f=1;
    22     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    23     if(ch=='-') f=-1,ch=getchar();
    24     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    25 }
    26 
    27 db get_S(int x,int y,int xx,int yy) {
    28     return abs(x*yy-xx*y)/2.0;
    29 }
    30 
    31 LL gcd(LL a,LL b) { return !b?a:gcd(b,a%b); }
    32 
    33 db get_L(int x,int y,int xx,int yy) {
    34     if(xx-x==0&&yy-y==0) return 0;
    35     if(xx-x==0) return abs(yy-y)-1;
    36     if(yy-y==0) return abs(xx-x)-1;
    37     return gcd(abs(x-xx),abs(y-yy))-1;
    38 }
    39 
    40 int main() {
    41 #ifdef ANS
    42     freopen(".in","r",stdin);
    43     freopen(".out","w",stdout);
    44 #endif
    45     for(;;) {
    46         read(x[1]); read(y[1]);
    47         read(x[2]); read(y[2]);
    48         read(x[3]); read(y[3]);
    49         if(x[1]==0&&y[1]==0&&x[2]==0&&y[2]==0&&x[3]==0&&y[3]==0) break;
    50         db S=get_S(x[2]-x[1],y[2]-y[1],x[3]-x[1],y[3]-y[1]);
    51         db L=3+get_L(x[1],y[1],x[2],y[2])+get_L(x[1],y[1],x[3],y[3])+get_L(x[2],y[2],x[3],y[3]);
    52         db n=S-L/2.0+1;
    53         printf("%d
    ",(int)n);
    54     }
    55     Formylove;
    56 }
    View Code
  • 相关阅读:
    产品经理经常犯的错误李可按
    skills_hive
    skills_office
    skills_idea
    skills_linux
    skills_ubuntu
    skills_git
    skills_redis
    skills_centos
    problems_hive
  • 原文地址:https://www.cnblogs.com/Achenchen/p/9513348.html
Copyright © 2020-2023  润新知