HDU 1705 Count the grid && jisuanke 35 三角形内点
来源:互联网 发布:cda数据分析师工资 编辑:程序博客网 时间:2024/06/06 12:57
链接:click here
题意:
给出一个三角形,求三角形内的整点;
皮克定理:S=a/2+b-1; S为多边形面积;a为多边形边上的点; b为多边形内的点;
a为边上的点可以由欧几里得定理gcd(x1-x0,y1-y0)求得点数;
另编程网站计蒜客35题也是一样的求法,只不过给出两点,实际写的话改成注释的那块就可以,链接:click here
代码:
#include <math.h>#include <queue>#include <map>#include <set>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;#define lowbit(a) a&-a#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double eps = 1e-6;const double Pi = acos(-1.0);static const int inf= ~0U>>2;static const int N=30010;int scan(){ int res = 0, flag = 0; char ch; if((ch = getchar()) == '-') flag = 1; else if(ch >= '0' && ch <= '9') res = ch - '0'; while((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + (ch - '0'); return flag ? -res : res;}void out(int a){ if(a < 0) { putchar('-'); a = -a; } if(a >= 10) out(a / 10); putchar(a % 10 + '0');}int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}struct point{ int x,y;} p[1000],pp[1000];int acoss(point p1,point p2,point p0){ return abs((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x));}int main(){ int a,area,ans; while(cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y>>p[2].x>>p[2].y) { //while(cin>>p[1].x>>p[1].y>>p[2].x) // { //p[0].x=0,p[0].y=0,p[2].y=0; if(!p[0].x&&!p[0].y&&!p[1].x&&!p[1].y&&!p[2].x&&!p[2].y)break; pp[0].x=abs(p[0].x-p[1].x); pp[0].y=abs(p[0].y-p[1].y); pp[1].x=abs(p[1].x-p[2].x); pp[1].y=abs(p[1].y-p[2].y); pp[2].x=abs(p[0].x-p[2].x); pp[2].y=abs(p[0].y-p[2].y); a=gcd(pp[0].x,pp[0].y)+gcd(pp[1].x,pp[1].y)+gcd(pp[2].x,pp[2].y); area=acoss(p[1],p[2],p[0]);//求S ans=(area-a+2)/2; printf("%d\n",ans); } return 0;}
When you want to give up, think of why you persist until now!
0 0
- HDU 1705 Count the grid && jisuanke 35 三角形内点
- 【HDU 5471】Count the Grid
- hdu 1705 Count the grid (皮克定理)
- HDU 1705 Count the grid(皮克定理的应用)
- hdu 5471 Count the Grid(容斥)
- 计蒜客 三角形内点
- 点是否在三角形内
- 判断点在三角形内
- 点是否在三角形内
- Count the Buildings HDU
- Count The Pairs HDU
- Count the string HDU
- Count the string HDU
- Count the Tetris HDU
- DP HDOJ 5471 Count the Grid
- SPOJ AMR11B:Save the Students_判断点是否在圆、矩形、三角形内
- HDU 2948 Geometry Darts(点在圆,三角形,矩形内判定)
- HDU 2948 Geometry Darts(点在圆,三角形,矩形内判定)
- 学习小结
- 使用attach命令调试线程
- 结构体定义 typedef struct 用法详解和用法小结
- poj2001Shortest Prefixes
- Generating Artifacts问题解决汇总
- HDU 1705 Count the grid && jisuanke 35 三角形内点
- 【设计模式】之面向对象基础一
- 机器学习10大经典算法
- JavaScript继承详解(六)
- 苹果软件的短连接地址
- 堆排序
- 最强DE 战斗力 【大数】
- 编程的标点 英文表达
- 如何使用debug检测shell script语法问题