记录编号 |
118287 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
[USACO Feb08] 连线游戏 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.023 s |
提交时间 |
2014-09-05 22:12:11 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
#define Ldouble double
const int INF=0x7ffffff;
//==============struct declaration==============
struct fractions
{
int numerator,denominator;//分子、分母
fractions(int numerator,int denominator):numerator(numerator),denominator(denominator){}
int gcd(int a,int b)
{
if (a<b) a^=b^=a^=b;
return a%b==0?b:gcd(b,a%b);
}
void reduction()//约分
{
if (numerator==0)
{
denominator=1;
return;
}
if (denominator==0)
{
numerator=1;
return;
}
int gcdn=gcd(abs(denominator),abs(numerator));
denominator/=gcdn;
numerator/=gcdn;
return;
}
bool operator <(const fractions &rhs) const
{
if (rhs.denominator==0) return false;//第二个数的分母为0
if (denominator==0) return true;//第一个数的分母为0
bool symble1,symble2;
if (numerator>=0)
symble1=true;//+
else
symble1=false;//-
if (rhs.numerator>=0)
symble2=true;//+
else
symble2=false;//-
if (symble1!=symble2)
return symble1<symble2;
return numerator*rhs.denominator<denominator*rhs.numerator;
}
};
//==============var declaration=================
const int MAXN=210;
int x[MAXN],y[MAXN];
//==============function declaration============
set <fractions> exist;
//==============main code=======================
int main()
{
string FileName="lines";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
int n;
scanf("%d",&n);
For(i,1,n)
{
scanf("%d%d",&x[i],&y[i]);
For(j,1,i-1)
{
int deltax=x[i]-x[j];
int deltay=y[i]-y[j];
if (deltay<0)
{
deltay=-deltay;
deltax=-deltax;
}
fractions k(deltay,deltax);
k.reduction();
if (!exist.count(k))
exist.insert(k);
}
}
printf("%d\n",exist.size());
#ifdef DEBUG
clock_t End_Time=clock();
cout<<endl<<endl<<"Time Used: "<<(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif
return 0;
}
//================fuction code====================