• poj2954


    题目大意:给定三角形的三个顶点,求内部点有多少。。

    思路:先叉积求面积,然后用 S=a + b/2 - 1(皮克公式),a为内部点,b为边上点,求出a。。

    code:

     1 /*
     2   State:Accepted
     3   Time:2013-04-06 16:40:55
     4 */
     5 #include<iostream>
     6 #include<fstream>
     7 #include<cstring>
     8 #include<cstdlib>
     9 #include<cstdio>
    10 #include<string>
    11 #include<cmath>
    12 #include<algorithm>
    13 using namespace std;
    14 struct oo{ int  x , y; };
    15 oo a, b, c;
    16 
    17 int work_x(int x2, int y2, int x1, int y1){
    18      return   x1*y2 - x2*y1;  
    19 }
    20 
    21 int gcd(int a, int b){
    22     if  (a % b == 0) return b;
    23     else return gcd(b , a % b);
    24 }
    25 
    26 int work_p(const oo a, const oo b){
    27      int dx = a.x - b.x;
    28      int dy = a.y - b.y;
    29      int d;
    30      if (dx == 0) d = abs(dy);
    31      else if (dy == 0) d = abs(dx);
    32           else d = gcd(abs(dx), abs(dy));
    33      return d;
    34 }
    35 void solve(){
    36       int squre = abs(work_x(b.x - a.x, b.y - a.y, c.x - a.x, c.y - a.y));
    37       int tm = work_p(a, b) + work_p(b,c) + work_p(a,c);
    38       int ans = (squre + 2 - tm) / 2;
    39       printf("%d\n",ans);
    40 }
    41 
    42 int main(){
    43      freopen("poj2954.in","r",stdin);
    44      freopen("poj2954.out","w",stdout); 
    45      while (scanf("%d%d%d%d%d%d",&a.x, &a.y, &b.x, &b.y, &c.x, &c.y) != EOF){
    46         if (!a.x && !a.y && !b.x && !b.y && !c.x && !c.y) break;
    47         solve();    
    48      }
    49      fclose(stdin); fclose(stdout);
    50 }
  • 相关阅读:
    【转载】C++指针随想
    微信小程序实现电子签名
    js数组常用方法
    css文本两端对齐
    js判断某个数组中是否包含另一个数组
    react 限制小数点位数
    原生js 操作class 原生js获取父元素
    转发: JS中的call()和apply()方法和区别 --小白变色记
    fail2Ban ubuntu
    VSCode 搭建 Vue项目 lite-server
  • 原文地址:https://www.cnblogs.com/yzcstc/p/3015766.html
Copyright © 2020-2023  润新知