【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 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441114.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【牛客 - 272A】Phrase String(构造,水题)

题干&#xff1a; 给出v, k&#xff0c;请你找到最小的正整数n&#xff0c;满足&#xff1a; n的二进制表示下存在一个长度为v的回文串&#xff0c;该回文串首尾都是1且n的二进制表示中至少有k个1。保证v,k均为偶数&#xff01; 由于n可能很大&#xff0c;你只需要输出对取模的…

【HDU - 1025】Constructing Roads In JGShining's Kingdom(dp最长上升子序列模型 + 二分优化)

题干&#xff1a; Constructing Roads In JGShinings Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29933 Accepted Submission(s): 8496 Problem Description JGShinings kingdom consists of 2n…

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】小乐乐吃糖豆 (fIb博弈)

题干&#xff1a; 小乐乐是一个比较喜欢吃糖豆的小孩子&#xff0c;小乐乐的哥哥大乐乐也同样爱吃糖豆。 作为一个小孩子&#xff0c;他们永远觉得谁吃掉了最后一个糖豆&#xff0c;谁吃的糖豆最多。 为了公平起见小乐乐与大乐乐商量吃糖豆的规则如下&#xff1a; 1. …

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】小乐乐切割方块(思维,水题)

题干&#xff1a; 小乐乐的作业本是2n*2n的方格本。 某天小乐乐的童鞋&#xff0c;想要考验一下小乐乐。 他将小乐乐的一张方格纸中的某个格子(x,y)涂成黑色&#xff0c; 小乐乐能否在将4*4的方格本沿着方格边缘且切割线与黑色方格不存在公共交点的情况下将方格本切割成两…

java web svn_如何搭建svnadmin,一个简单的svnWEB页面

Svn Admin是一个Java开发的管理Svn服务器的项目用户的web应用。安装好Svn服务器端好&#xff0c;把Svn Admin部署好&#xff0c;就可以通过web浏览器管理Svn的项目&#xff0c;管理项目的用户&#xff0c;管理项目的权限。使得管理配置Svn简便&#xff0c;再也不需要每次都到服…

java 递归 时间复杂度_递归到底是怎么实现的?它的时间复杂度怎么算?

递归到底是个啥&#xff1f;常听见的一句话就是&#xff1a;自己调用自己。按照这个说法&#xff0c;写个简单的递归自己推导一下的确可以&#xff0c;但是总是有点绕&#xff0c;推着推着自己把自己陷进去了。递归函数运行时&#xff0c;实际上会进行一个压栈(思考栈的特点&am…

Java 重定向 无法写入_java IO 文件读入,写入,重定向

Java代码 packagestar20110526;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importjava.io.BufferedReader;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io…

【CodeForces - 298C】Parity Game (思维,有坑)

题干&#xff1a; You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and &q…

java中能构成循环的语句_《编程导论(Java)#183;3.2.4 循环语句》

本文全然复制《编程导论(Java)3.2.4 循环语句》的内容。除【】中的说明文字。请阅读和比較其它编程教材。我知道。假设我是一个刚開始学习的人&#xff0c;《编程导论(Java)》非常不适合自学。建议同学们阅读时&#xff0c;一定选择一本其它的书同一时候看&#xff0c;或上网。…

*【CodeForces - 1088 ABC】套题比赛,A水题B模拟C构造D交互

A. Input The only line contains the integer xx (1≤x≤100)(1≤x≤100). Output You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (wit…

算法讲解 -- 区间dp经典模型与优化(石子归并)

石子合并问题是最经典的DP问题。首先它有如下3种题型&#xff1a; PPT讲解&#xff1a;点击打开链接 (1)有N堆石子&#xff0c;现要将石子有序的合并成一堆&#xff0c;规定如下&#xff1a;每次只能移动任意的2堆石子合并&#xff0c;合并花费为新合成的一堆石子的数量。求将…

cpu影响matlab仿真速度吗,Proteus仿真速度很慢的分析

类型&#xff1a;行业软件大小&#xff1a;1.1M语言&#xff1a;中文 评分&#xff1a;6.5标签&#xff1a;立即下载这篇文章是我的个人实践经验&#xff1a;很多朋友在做Proteus硬件仿真的时候可能都碰上了仿真速度慢的问题&#xff0c;在点击了开始仿真之后&#xff0c;CPU过…

mysql 7天自动拒单功能,mysql查询最近7天的数据,没有数据自动补0

select DATE( createtime) date , createtime, count(1) as count from order表 where DATEDIFF( now(), createtime)<7group by date ;12 月九号没有;给他在关联一张日期的表;--生成从今天开始完整的7天日期DECLARE LastSevenDaytable(day date)DECLARE StartDaydate …

基于维纳滤波的语音增强算法 matlab,基于维纳滤波语音增强算法的改进实现

通过对维纳滤波的介绍,实现了基本维纳滤波效果;利用两级维纳滤波和两级滤波器组滤波方法实现了语音增强,达到了良好的效果。维普资讯 http://doc.docsou.com文章编号&#xff1a;0 2 8 8 (o 7 0 - 0 4 0 10—6 4 2 o )1 0 4 - 3基于维纳滤波语音增强算法的改进实现白文雅&#…

php7 获取文件类型,太简单了!PHP获取文件扩展名的7中方法

PHP中获取文件扩展名的方法第一种&#xff1a;$file x.y.z.png;echo substr(strrchr($file, .), 1);解析&#xff1a;strrchr($file, .)strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置&#xff0c;并返回从该位置到字符串结尾的所有字符第二种&#xff1a;$file…

【EOJ Monthly 2018.12 - A,B,C】套题训练,部分题解

A. 题干&#xff1a; A. 仰望星空 单测试点时限: 2.0 秒 内存限制: 512 MB 你就这样静坐在草地上&#xff0c;离我稍远的地方。 我用眼角瞅着你&#xff0c;你什么话也别说。 语言是误会的根源。 但是&#xff0c;每天&#xff0c;你可以坐得离我近一些…… 你和她一起仰头…

php百度搜索框代码,基于jquery的仿百度搜索框效果代码_jquery

先看看整个的效果图&#xff1a;图一&#xff1a;图二&#xff1a;图三&#xff1a;图四&#xff1a;大概的效果图就这样&#xff0c;接下来直接看源码页面&#xff1a;CSS&#xff1a;.autoSearchText{border:solid 1px #CFCFCF;height:20px;color:Gray;}.menu_v{margin:0;pad…

matlab大作业题题单,2011MATLAB大作业-题目-

(1)求解线性规划问题&#xff1a;minZ 4x1 x2 7x3s.t.x1 x2 x3 53x1 x2 x3 4x1 x2 4x3 7x1,x2 0问各xi分别取何值时&#xff0c;Z有何极小值。(2)编写一个函数&#xff0c;使其能够产生如下的分段函数&#xff1a;0.5x&#xff0c;x 2f(x) 1.5 0.25x&#xff0c;2 x 6&#xff…

php webshell编写,php webshell学习

一、环境kali 192.168.43.177开户apache /etc/init.d/apache2 start/var/www/html/目录下编辑php代码hackbarhttps://github.com/Mr-xn/hackbar2.1.3二、php基础输出函数:echo - 可以输出一个或多个字符串print - 只允许输出一个字符串&#xff0c;返回值总为 1提示&#xff1a…

【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)

题干&#xff1a; Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Outp…