10682 Deathgod want to know.
The problem is solved
Time limit: 1000MS memory limit: 65535K
Number of submissions: 265 Hits: 14
Question types: programming language: g++; Gcc
Description
An ant crawled through the map to leave traces, Deathgod saw after the map built a coordinate, the ants left traces into a number of lines connected to the first, and those segments of the end points are integral points, and now he wants to know that the ant through the coordinates of the number of integer points.
Input format
The first line enters an integer t, which indicates the number of case, and for each of these, the first line enters an integer n (0<=n<=10), which represents the number of segments the ant passes through, and the next n+1 line, each line has two integers, x, y ( -10000<=x,y<= 10000), which indicates that the ant passes through the end of the line segment in turn.
Output format
Each case outputs a row and the number of integer points the ant passes through.
Input sample
130 00 42) 22 0
Output sample
9
Exercises
Calculate the number of integral points before two points, as long as the GCD (ABS (X1-X2), ABS (Y1-Y2)) is OK.
Then use this to figure out the coordinates of the integer points before the two points.
Then throw it into the set and go heavy.
The number of final output set.
Specific look at the code
#include <iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<Set>using namespacestd;intgcdintAintb) { returnB>0? gcd (b,a%b): A;}intMain () {intT; scanf ("%d",&T); while(t--) { Set<pair<int,int> >S; intN; scanf ("%d",&N); inta,b,c,d; if(n) {scanf ("%d%d",&a,&b); S.insert (Make_pair (A, b)); } for(intI=0; i<n;i++) {scanf ("%d%d",&c,&d); intGCD=GCD (ABS (C-A), ABS (db)); intlen1=0, len2=0; if(GCD) len1= (c-a)/gcd,len2= (d-b)/GCD; for(intj=1; j<=gcd;j++) {S.insert (Make_pair (a+j*len1,b+j*len2)); //cout<< "Pass the point:" <<a+j*len1<< "" <<b+j*len2<<endl;} a=c,b=D; } printf ("%d\n", S.size ()); } return 0;}
10682 Deathgod want to Know (number theory)