Greeting Card

题目描述

Quido plans to send a New Year greeting to his friend Hugo. He has recently acquired access to an advanced high-precision plotter and he is planning to print the greeting card on the plotter.
Here’s how the plotter operates. In step one, the plotter plots an intricate pattern of n dots on the paper. In step two, the picture in the greeting emerges when the plotter connects by a straight segment each pair of dots that are exactly 2 018 length units apart. 
The plotter uses a special holographic ink, which has a limited supply.Quido wants to know the number of all plotted segments in the picture to be sure that there is enough ink to complete the job.

 

输入

The first line of input contains a positive integer n specifying the number of plotted points. The following n lines each contain a pair of space-separated integer coordinates indicating one plotted point. Each coordinate is non-negative and less than 231. There are at most 105 points, all of them are distinct.
In this problem, all coordinates and distances are expressed in plotter length units, the length of the unit in the x-direction and in the y-direction is the same.

 

输出

The output contains a single integer equal to the number of pairs of points which are exactly 2018 length units apart.

题意:

给出一组点,求其中两点之间距离为2018的数量。

题解:

刚开始用暴力写 但数据太大死在了超时上,因为点的坐标都为整数打表可以找到规律。只存在两种情况1.在同一直线上相距2018,二、分别相差1118和1680。用其中一个点根据关系遍历看该点在集合中是否存在,即可以找到所有满足的点。

#include<iostream>
#include<cstdio>
#include<set>
#include<utility>
typedef long long ll;

using namespace std;
const int maxn = 100000+2;
int n;
ll x,y;
ll ans;
int dx[]={2018,0,-2018,0,1118,1680,1680,-1118,-1680,1118,-1118,-1680};
int dy[]={0,2018,0,-2018,1680,1118,-1118,1680,1118,-1680,-1680,-1118};
ll X[maxn],Y[maxn];
int main()
{

    cin>>n;
    pair<ll,ll> p;
    set<pair<ll,ll> >st;
    for(int i = 0;i<n;i++){
        cin>>X[i]>>Y[i];
        p.first = X[i];
        p.second = Y[i];
        st.insert(p);
    }
    ans = 0;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<12;j++){
            p.first = X[i]+dx[j];
            p.second = Y[i]+dy[j];
            if(st.count(p))
                ans++;
        }
    }
    cout<<ans/2<<endl;
    return 0;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值