【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,一经查实,立即删除!

相关文章

java request 封装对象_java通过request自动封装复杂对象

参考&#xff1a;Jfinal源码&#xff0c;在上面基础上改的&#xff0c;然后分享出来适用JAVAEE平台[Java]代码/*** 实现深层封装对象的实例 从request封装对象* 举例&#xff1a;* House.class 属性有三个 ID:id 名称&#xff1a;name 门类&#xff1a;Door doorDoor类: id nam…

【UVA - 10020 】Minimal coverage (贪心,区间覆盖问题)

题干&#xff1a;&#xff08;Uva题不给题干了&#xff09; t组样例&#xff0c;每组首先给出一个M&#xff0c;然后给出一些线段&#xff08;0 0结束&#xff09;&#xff0c;然后问怎么取能使得最少的线段覆盖区间[0, M]。 Sample Input 2 1 -1 0 -5 -3 2 5 0 0 1 -1 0 0 1 …

java邮箱地址正则表达式_Java 中用正则表达式修改 Email 地址

需求系统中有一列会用来存储 email 地址&#xff0c;现在需要对输入的字符串进行过滤&#xff0c;要求是&#xff0c;把无效的地址过滤掉。有一些需要说明的是这些地址是通过图像识别得到的&#xff0c;有些是用户自己输入的已有历史记录已经存在了脏数据&#xff0c;需要替换这…

【CodeForces - 305C】Ivan and Powers of Two(思维,STL,set,优先队列)

题干&#xff1a; Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number …

【CodeForces - 1082B】Vova and Trophies (贪心模拟,暴力)

题干&#xff1a; Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wan…

java mac 转换 整形_JAVA的整型与字符串相互转换

1如何将字串 String 转换成整数 int?A. 有两个方法:1). int i Integer.parseInt([String]); 或i Integer.parseInt([String],[int radix]);2). int i Integer.valueOf(my_str).intValue();注: 字串转成 Double, Float, Long 的方法大同小异.2 如何将整数 int 转换成字串 St…

【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

题干&#xff1a; Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for e…

java迷宫生成算法_DFS算法迷宫生成器

我正在尝试使用DFS算法在ASCII中创建迷宫(&#xff03;表示墙和自由空间)&#xff0c;其左上角开始&#xff0c;右下角出口 . 问题是迷宫开始创建&#xff0c;然后它被阻止&#xff0c;因为它的所有邻居都已被访问过 .我从左上角开始&#xff0c;将单元格标记为已访问并放置一个…

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

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

eclipse 跑maven命令_maven编写命令行执行mvn package没问题,eclipse执行报错

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼报错是这样的“[ERROR] Unknown lifecycle phase "Systemout3". You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sou…

【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)

题干&#xff1a; Mike has always been thinking about the harshness of social inequality. Hes so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A  [a1, a2, ..., an…

erlang odbc mysql参数_Erlang在Redhat 5.3下使用unixODBC连接Oracle数据库的配置

个人在安装配置时遇到一些麻烦&#xff0c;特此记录如下&#xff1a; 环境 数据库服务器操作系统&#xff1a;Windows 2003 数据库&#xff1a;Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 erlang运行的服务器操作系统&#xff1a;Redhat 5.3 erlang:Erlang R1…

【POJ - 2533】Longest Ordered Subsequence(四种方法解决最长上升子序列 含二分优化版本)

题干&#xff1a; Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 41944 Accepted: 18453 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any se…

halcon图片上传到mysql_C# 10个线程并发执行Halcon图像算法 报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”...

如题&#xff0c;这个问题本人已经纠结了快三个工作日了。本人不同WinFrom程序一起动就会开启10个线程&#xff0c;并发对10张图片进行算法处理&#xff0c;问题是只要程序一起动就会报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”异常。本人试过将8个线程停掉…

【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…

java list详解_Java 中 list 用法案例详解

LIST是个容器接口可以理解为动态数组&#xff0c;传统数组必须定义好数组的个数才可以使用&#xff0c;而容器对象无须定义好数组下标总数&#xff0c;用add()方法即可添加新的成员对象&#xff0c;他可以添加的仅仅只能为对象&#xff0c;不能添加基本数据类型&#xff0c;容器…

【牛客 - 301哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级)】小乐乐的组合数+(取模,数学,思维)

题干&#xff1a; 小乐乐得知一周有7天之后就对7产生了兴趣。 小乐乐得到了两堆数字数字时连续的。 第一堆包含[1,n]n个数字&#xff0c;第二堆包含[1,m]m个数字。 小乐乐想要从两堆中各挑选出一个整数x,y&#xff0c;使得x,y的和为7的倍数。 请问小乐乐有多少种组合的方式…

java 写文件 属性吗_使用JAVA读写Properties属性文件

自己定义一个属性文件&#xff1a;例如prop.propertiesbaseFilePathD\:/kuanter/resourcetesxabcd我们要做的第一步就是要将文件读取到Properties类对象中&#xff0c;由于load有一个参数是InputStream&#xff0c;所以我们可以用 InputStream的子类FileInputStream将属性文件读…

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】 小乐乐算数字(水题,快速幂,lowbit)

题干&#xff1a; 小乐乐最喜欢玩数字了。 小乐乐最近迷上了2这个整数&#xff0c;他觉得2的幂是一种非常可爱的数字。 小乐乐想知道整数x的最大的 2的幂 &#xff08;2^y&#xff09;的因子。 y为整数。 输入描述: 输入整数x。(1<x<1e18) 输出描述: 输出整数x的最…

java date 相差_java 比较时间相差多少分钟

/** * 返回二个时间相差的分分钟数,如果一个为空&#xff0c;返回为0&#xff1b; * param startDate&#xff0c;比如08&#xff1a;09 * param endDate&#xff0c;如18&#xff1a;09 * return */ public static int getMinutesDiff(String startDate,String endDate){ int …