Codeforces Round #185 (Div. 2)-The Closest Pair
来源:互联网 发布:多媒体互动软件 编辑:程序博客网 时间:2024/06/18 17:04
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.
The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between(x1, y1) and(x2, y2) is.
The pseudo code of the unexpected code is as follows:
input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output d
Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second,tot should not be more than k in order not to get Time Limit Exceeded.
You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000,1 ≤ k ≤ 109).
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else printn lines, and the i-th line contains two integersxi, yi(|xi|, |yi| ≤ 109) representing the coordinates of thei-th point.
The conditions below must be held:
- All the points must be distinct.
- |xi|, |yi| ≤ 109.
- After running the given code, the value of tot should be larger thank.
4 3
0 00 11 01 1
2 100
no solution
题意理解:
找到让其超时的点,并输出n组超时的点,k是给定的最小时间。是给若是找不到,输出“No solution”
for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output d从这可以看出tot的时间复杂度是n*(n-1)/2,这是最长的时间,但是如果两点的x坐标的距离超过d就会跳出。这时候就会跳出,用的时间会少。所以要让n*(n-1)/2>k,也就是最长的时间都超过k防止其不超过。
输出时的技巧:
d=INF!=0所以要输出点的横坐标都为0就可以!
以下为代码:
#include<iostream>#include<cstdio>using namespace std;int n,k;const int MAXN=2002;int A[MAXN];int main(){ scanf("%d%d",&n,&k); double t=n*(n-1)/2; if(t<=k) printf("no solution"); else{ for(int i=1;i<=n;i++){ cout<<'0'<<' '<<i<<endl; } }}
- Codeforces Round #185 (Div. 2)-The Closest Pair
- Codeforces Round #185 (Div. 1) / 311A The Closest Pair (“陷阱”题)
- Codeforces Round #209 (Div. 2) D. Pair of Numbers
- Codeforces Round #209 (Div. 2) D. Pair of Numbers
- Codeforces Round #209 (Div. 2), problem: (D) Pair of Numbers
- Codeforces Round #209 (Div. 2) D. Pair of Numbers
- D. Pair of Numbers Codeforces Round #209 (Div. 2)
- Codeforces Round #209 (Div. 2) D - Pair of Numbers
- Codeforces Round #271 (Div. 2) F 线段树+pair
- Codeforces Round #377 (Div. 2) E. Sockets(map,pair,STL)
- Codeforces Round #209 (Div. 2) D.Pair of Numbers
- CodeForces 312C The Closest Pair(构造)
- Codeforces Round #398 (Div. 2)The Queue
- Codeforces Round #185 (Div. 1) && (Div. 2)
- Codeforces Round #209 (Div. 2)-C. Prime Number(set)和D. Pair of Numbers(线段树)
- Codeforces Round #209 (Div. 2) / 359D Pair of Numbers (一点点想法)
- Codeforces Round #346 (Div. 2) B (pair+vector的应用)
- 【Codeforces Round #398 (Div. 2)】Codeforces 767B The Queue
- 解决win8使用pip安装numpy后无法使用
- 计算机组成原理与体系结构---CISC和RISC
- Linux 常用命令
- Codeforces 671D Roads in Yusland dfs序+线段树
- Spark Streaming学习
- Codeforces Round #185 (Div. 2)-The Closest Pair
- 神经网络的发展历史与深度学习
- pom.xml已配置,但无法引用jar
- EMD和Hilbert
- 计蒜客 乘法游戏
- Tensorflow基本概念
- JQuery--DOM
- 学生中应用的SQL注入
- 字符串碎片