题目描述
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.
样例输入
4 20180000 20180000 20180000 20182018 20182018 20180000 20182018 20182018
样例输出
4
题意:
题意很好理解,就是给你一些点,问你有多少对距离是2018的
思路其实很好想,看到给的点是整数,当时就想打表看看,有多少个 x^2 + y^2 = 2018*2018(x,y是两点的水平差和垂直差),结果一看就两个,加上垂直水平四个方向,一共有十二个点是可以和当前给出的点满足相距2018的。数组不好存,就用map+pair,每给出一个点就在关于他的这十二个点上加一,后面输入的点如果被标记过,那么它对应的map值就是有多少个点可以和他相距2018,最后把它们都加起来,就是结果了。
AC代码
#include<iostream>
#include<cstdio> //EOF,NULL
#include<cstring> //memset
#include<cstdlib> //rand,srand,system,itoa(int),atoi(char[]),atof(),malloc
#include<cmath> //ceil,floor,exp,log(e),log10(10),hypot(sqrt(x^2+y^2)),cbrt(sqrt(x^2+y^2+z^2))
#include<algorithm> //fill,reverse,next_permutation,__gcd,
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<iterator>
#include<iomanip> //setw(set_min_width),setfill(char),setprecision(n),fixed,
#include<functional>
#include<map>
#include<set>
#include<limits.h> //INT_MAX
#include<cmath> // bitset<?> n
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 10010;
map<P,ll> m;
ll dir[12][2] = {2018,0,0,2018,-2018,0,0,-2018,1118,1680,-1118,1680,1118,-1680,-1118,-1680,1680,1118,1680,-1118,-1680,1118,-1680,-1118};
int main()
{
// rep(i,1,2019)
// {
// rep(j,1,2019)
// {
// if(i*i + j*j == 2018 * 2018)
// {
// printf("%d %d\n",i,j);
// }
// }
// }
int n;
int t;
sca(t);
ll x,y;
ll sum = 0;
while(t--)
{
scanf("%lld%lld",&x,&y);
sum += m[{x,y}];
//printf("%d\n",m[{x,y}]);
rep(i,0,12)
{
m[{x+dir[i][0],y+dir[i][1]}]++;
}
}
printf("%lld\n",sum);
return 0;
}
本文探讨了一项趣味挑战:使用高精度绘图仪绘制新年贺卡,通过精确坐标定位,连接距离为2018单位长度的点对,形成图案。文章详细介绍了算法思路与实现代码,展示了如何利用数学和编程解决这一问题。
378





