Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

set强大自动删重,未压缩的代码不到40行

Posted by 986677841 at 2016-05-03 22:52:54 on Problem 3668 and last updated at 2016-05-03 22:53:10
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator