HDU 1705 Count the grid jisuanke 35 三角形内点

链接: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]);//求Sans=(area-a+2)/2;printf("%d\n",ans);}return 0;}When you want to give up, think of why you persist until now!

缘是浪漫的相遇,瞬间让你我的心化为永恒!

HDU 1705 Count the grid jisuanke 35 三角形内点

相关文章:

你感兴趣的文章:

标签云: