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

因为是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;
}

 

转载于:https://www.cnblogs.com/zhuiyicc/p/9588899.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值