zoukankan      html  css  js  c++  java
  • poj 2954 Triangle

    pick公式+gcd公式

     1 #include<iostream>
     2 #include<map>
     3 #include<string>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cstdlib>
     7 #include<cmath>
     8 #include<queue>
     9 #include<vector>
    10 #include<algorithm>
    11 #include<cmath>
    12 using namespace std;
    13 int gcd(int a,int b){
    14     if(b==0)  return a;
    15     int r;
    16     while((r=a%b)){
    17         a=b;
    18         b=r;
    19     }
    20     return b;
    21 }
    22 int main(){
    23     int x1,y1,x2,y2,x3,y3;
    24     while(cin>>x1>>y1>>x2>>y2>>x3>>y3&&(x1||y1||x2||y2||x3||y3)){
    25         /*if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0&&y3==0)
    26         break;*/
    27         int area=fabs(((x1-x2)*(y1-y3)-(x1-x3)*(y1-y2))*1.0/2);//叉乘可能为负 
    28         //cout<<area<<endl;
    29         int b=abs(gcd(x1-x2,y1-y2))+abs(gcd(x2-x3,y2-y3))+abs(gcd(x3-x1,y3-y1));//坐标平移,最大公约数+1就是边上的整点 
    30         //cout<<b<<endl;
    31         int pick=area-b/2+1;//pick公式 
    32         cout<<pick<<endl;
    33     } 
    34     return 0;
    35 }
  • 相关阅读:
    soa soap http rpc
    Work Queues(点对多)
    Hello World模式
    RabbitMQ 概念
    RabbitMQ安装
    gradle ssh 插件
    gradle基础配置
    将java打jar包成linux后台服务service
    java 8 日期api
    springboot linux启动方式
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4280670.html
Copyright © 2011-2022 走看看