HDU 1705 Count the grid && jisuanke 35 三角形内点
2015-03-08 16:08
267 查看
链接:click here
题意:
给出一个三角形,求三角形内的整点;
皮克定理:S=a/2+b-1; S为多边形面积;a为多边形边上的点; b为多边形内的点;
a为边上的点可以由欧几里得定理gcd(x1-x0,y1-y0)求得点数;
另编程网站计蒜客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]);//求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!
相关文章推荐
- HDU 1705 Count the grid(皮克定理的应用)
- hdu 1705 Count the grid(皮克定理)
- hdu 1705 Count the grid (皮克定理)
- hdu 5471 Count the Grid(容斥)
- hdu 4380 Farmer Greedy && hdu 4353 Finding Mine && 4367 The war of virtual world (确定三角形内的点个数题目)
- 【HDU 5471】Count the Grid
- 【HDU】1131 - Count the Trees(组合数学 - 卡特兰数 & java)
- hdu 3336 Count the string -KMP&dp
- hdu 1131 Count the Trees
- HDU&&Color the ball
- Connect the Cities&&http://acm.hdu.edu.cn/showproblem.php?pid=3371
- jqGrid is a grid component for ASP.NET & PHP based on the world's most popular and flexible jQuery g
- hdu Count the string(KMP)
- ODBC:m_pSet->GetRecordCount;m_MSFGrid显示
- hdu 1023 大数Catalan (n>35)
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- hdu 3336 Count the string
- HDU 3336 Count the string
- hdu 4004 The Frog's Games
- HDU 3548 Enumerate the Triangles(找周长最小的三角形)