POJ 2954 Triangle (Pick定理)
给定三角形,求出给定三角形内部整点的个数。

1 /* 2 Memory: 116 KB Time: 0 MS 3 Language: C++ Result: Accepted 4 By coolwind 5 */ 6 #include <stdio.h> 7 #include <string.h> 8 9 #define MAXN 105 10 struct Point { 11 int x,y; 12 Point(int a = 0, int b = 0) 13 :x(a),y(b){} 14 }; 15 16 Point pt[3]; 17 18 int gcd(int a, int b) 19 { 20 if(b == 0) return a; 21 return gcd(b,a%b); 22 } 23 24 int abs(int x) 25 { 26 if( x < 0) return -x; 27 return x; 28 } 29 30 int Xmul(Point a ,Point b, Point o) 31 { 32 return (a.x - o.x) * (b.y - o.y) - 33 (a.y - o.y) * (b.x - o.x); 34 } 35 36 int main() 37 { 38 while(true) 39 { 40 scanf("%d%d%d%d%d%d",&pt[0].x,&pt[0].y, 41 &pt[1].x,&pt[1].y,&pt[2].x,&pt[2].y); 42 if(pt[0].x == 0&&pt[0].y == 0&&pt[1].x == 0 43 &&pt[1].y == 0&&pt[2].x == 0&&pt[2].y == 0) 44 break; 45 int area = Xmul(pt[1],pt[2],pt[0]); 46 int on = 0; 47 for(int i = 0 ;i < 3; i ++) 48 on += gcd(abs(pt[(i + 1) % 3].x - pt[i].x) 49 ,abs(pt[(i + 1) % 3].y - pt[i].y)); 50 int in = (abs(area) - on + 2) / 2; 51 printf("%d\n",in); 52 } 53 return 0; 54 }
【推荐】FlashTable:表单开发界的极速跑车,让你的开发效率一路狂飙
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DbContext是如何识别出实体集合的
· 一次 .NET 性能优化之旅:将 GC 压力降低 99%
· MySQL索引完全指南:让你的查询速度飞起来
· 一个字符串替换引发的性能血案:正则回溯与救赎之路
· 为什么说方法的参数最好不要超过4个?
· 一次 .NET 性能优化之旅:将 GC 压力降低 99%
· 32岁入行STM32迟吗?
· C#.Net筑基-泛型T & 协变逆变
· 花150元,我用 AI 做出了千万播放的爆款视频!保姆级教程+完整提示词
· 【EF Core】DbContext是如何识别出实体集合的