欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

【CodeForces - 312C】The Closest Pair (思维)

发布时间:2023/12/10 56 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【CodeForces - 312C】The Closest Pair (思维) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题干:

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 n for i from 1 to ninput the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to nfor j from (i+1) to n++totif (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?

Input

A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109).

Output

If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-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 than k.

Examples

Input

4 3

Output

0 0 0 1 1 0 1 1

Input

2 100

Output

no solution

题目大意:

给你一个程序,要求让你出一组数据,使得这组数据会让程序的tot超过k。换句话说,给出一个最大循环次数k,并且已知如果tot超过k就会TLE。问:能不能给出个样例,让这代码TLE。

解题报告:

  先找到无论如何都不会让他TLE的情况,,也就是tot很小,而我们想让他TLE,,但是死活TLE不了,也就是我们想让tot尽量大,但是最大情况也是TLE不了的。。。也就是一个break也没有执行,那么肯定是tot最大的。。。所以我们就是构造一组解,让他一个break也执行不了,就最会让他TLE。就行了。

AC代码:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll n,k; int main() {cin>>n>>k;if(n * (n-1) / 2 > k) {for(int i = 1; i<=n; i++) {printf("1 %d\n",i);}}else puts("no solution");return 0 ;}

 

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的【CodeForces - 312C】The Closest Pair (思维)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。