【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 dHere,?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 3Output
0 0 0 1 1 0 1 1Input
2 100Output
no solution題目大意:
給你一個(gè)程序,要求讓你出一組數(shù)據(jù),使得這組數(shù)據(jù)會(huì)讓程序的tot超過k。換句話說,給出一個(gè)最大循環(huán)次數(shù)k,并且已知如果tot超過k就會(huì)TLE。問:能不能給出個(gè)樣例,讓這代碼TLE。
解題報(bào)告:
? 先找到無論如何都不會(huì)讓他TLE的情況,,也就是tot很小,而我們想讓他TLE,,但是死活TLE不了,也就是我們想讓tot盡量大,但是最大情況也是TLE不了的。。。也就是一個(gè)break也沒有執(zhí)行,那么肯定是tot最大的。。。所以我們就是構(gòu)造一組解,讓他一個(gè)break也執(zhí)行不了,就最會(huì)讓他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 ;}?
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的【CodeForces - 312C】The Closest Pair (思维)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 个人征信报告怎么看?个人征信报告包含哪些
- 下一篇: 【POJ - 1562】Oil Depo