Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
set强大自动删重,未压缩的代码不到40行#include<cstdio> #include<cstdlib> #include<algorithm> #include<iostream> #include<memory.h> #include<vector> #include<set> using namespace std; struct line{ int x,y; bool operator < (const line &a)const{ if(a.x==x)return y<a.y; else return x<a.x; } }; int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int n; int x[9999],y[9999]; int main(){ cin>>n; set<line>lj; for(int i=0;i<n;i++) cin>>x[i]>>y[i]; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){ line p; p.x=x[i]-x[j]; p.y=y[i]-y[j]; int tmp=gcd(p.x,p.y); p.x/=tmp; p.y/=tmp; lj.insert(p); } cout<<lj.size(); system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator