1. 程式人生 > >Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

reg abs ins getchar stream 直線 name stdout etc

因為是x,y均為整數因此對於同一直線的點,其最簡分數x/y是相同的(y可以為0,這裏不做除法)於是將這些點不斷求最簡分數用pair在set中去重即可。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include 
<string> #include <iostream> #include <algorithm> #include <functional> #include <stack> using namespace std; typedef long long ll; #define T int t_;Read(t_);while(t_--) #define dight(chr) (chr>=‘0‘&&chr<=‘9‘) #define alpha(chr) (chr>=‘a‘&&chr<=‘z‘) #define
INF (0x3f3f3f3f) #define maxn (100005) #define hashmod 100000007 #define ull unsigned long long #define repne(x,y,i) for(i=x;i<y;++i) #define repe(x,y,i) for(i=x;i<=y;++i) #define ri register int void Read(int &n){char chr=getchar(),sign=1;for(;!dight(chr);chr=getchar())if(chr==-)sign=-1;
for(n=0;dight(chr);chr=getchar())n=n*10+chr-0;n*=sign;} void Read(ll &n){char chr=getchar(),sign=1;for(;!dight(chr);chr=getchar())if (chr==-)sign=-1; for(n=0;dight(chr);chr=getchar())n=n*10+chr-0;n*=sign;} int n,x,y,a,b; int gcd(int x,int y){return y==0?x:gcd(y,x%y);} set<pair<int,int> > se1,se2; int main() { freopen("a.in","r",stdin); freopen("b.out","w",stdout); ri i; Read(n),Read(x),Read(y); repe(1,n,i){ Read(a),Read(b); int ex = abs(x - a),ey = abs(y - b),g = gcd(ex,ey); if((x - a >= 0 && y - b >= 0) || (x - a <= 0 && y - b <= 0)) se1.insert(make_pair(ex/g,ey/g)); else se2.insert(make_pair(ex/g,ey/g)); } printf("%d\n",(int)se1.size() + (int)se2.size()); return 0; }

Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun