Codeforces Round #185 (Div. 2) C. The Closest Pair 构造
C. The Closest Pair
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/312/problem/C
Description
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 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 second
d=INF //here INF is a number big enough
tot=0
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
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.
Sample Input
4 3
Sample Output
0 0
0 1
1 0
1 1
HINT
题意
给你一个程序,要求让你出一组数据,使得这组数据会让程序的tot超过k
题解:
很显然我们可以发现,他只是比较了x之间的距离,那么我们可以构造出所有点的x都相同,y都不相同的数据就好了
这样任意两个点的距离一定是大于任意两个点的x坐标之差的
代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std; int main()
{
long long n,k;
cin>>n>>k;
if(k>=((n*(n-1LL))/2LL))
return puts("no solution");
for(int i=;i<n;i++)
printf("1 %d\n",i);
}
Codeforces Round #185 (Div. 2) C. The Closest Pair 构造的更多相关文章
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- Codeforces Round #185 (Div. 1 + Div. 2)
A. Whose sentence is it? 模拟. B. Archer \[pro=\frac{a}{b}+(1-\frac{a}{b})(1-\frac{c}{d})\frac{a}{b}+( ...
- 【Codeforces Round #185 (Div. 2) C】The Closest Pair
[链接] 链接 [题意] 让你构造n个点,去hack一种求最近点对的算法. [题解] 让x相同. 那么那个剪枝就不会起作用了. [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] # ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- 【Codeforces Round #185 (Div. 2) D】Cats Transport
[链接] 链接 [题意] 有n座山,m只猫. 每只猫都在其中的一些山上玩. 第i只猫在h[i]山上玩,且会在t[i]时刻出现在山脚下(然后就一直在那里等) 然后有p个人. 它们听从你的安排. 在某个时 ...
- 【Codeforces Round #185 (Div. 2) B】Archer
[链接] 链接 [题意] 在这里输入题意 [题解] 概率水题. 枚举它是第几轮成功的. 直到满足精度就好 [错的次数] 1 [反思] long double最让人安心. [代码] #include & ...
- 【Codeforces Round #185 (Div. 2) A】 Whose sentence is it?
[链接] 链接 [题意] 告诉你每句话; 然后每句话是谁说的和开头与结尾的一段字符串有关. [题解] 一个一个判断就好; 注意大小<5的情况 [错的次数] 在这里输入错的次数 [反思] 在这里输 ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
随机推荐
- 【转】出現 "PowerCam player support IE browser only!" 的錯誤訊息
原文网址:http://www.camdemy.com/faq/1138 A. 這是由於新版 IE11 針對文件模式設定的改變,衍生 PowerCam5 及6 的教材閱讀問題 ( EverCam 已 ...
- Oracle 手工清除回滚段的几种方法
关于回滚段的问题,之前也小整理过一个,参考: Current online Redo 和 Undo 损坏的处理方法 http://blog.csdn.net/tianlesoftware/articl ...
- 【转】堆栈跟踪中收到一个UnhandledExceptionFilter调用时,如何查找问题异常堆栈
定义没有异常处理程序来处理引发的异常时调用UnhandledExceptionFilter函数.函数通常将异常传递到捕获并处理它所尝试的 Ntdll.dll 文件. 在某些情况下,在其中存在的进程内存 ...
- iE6、7、8、9、10、11兼容的Cookie
<%@ Master Language="C#" Debug="true" AutoEventWireup="true" Inheri ...
- js函数——倒计时模块+无缝滚动
倒计时 效果: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- POJ 1094 Sorting It All Out
题意:给出m对关于n个字母的小于关系,输出通过这些关系能得到的结论,如果可以排序就输出至少知道第几个关系时就可以知道顺序,从小到大输出顺序:如果产生歧义就输出在第几个关系时出现歧义,如果不能得出准确的 ...
- Minimax Triangulation
题意: 按顺序给定一些点,把这些点分割为n - 2个三角形,花费为最大三角形面积,求最小花费 分析: 区间dp,dp[i][j]表示完成区间[i,j]最小花费,dp[i][j]=min(dp[i][j ...
- Loadrunner模拟Json请求
一.loadrunner脚本创建 1.Insert - New step -选择Custom Request - web_custom_request 2.填入相应参数 3.生成脚本,并修改如下(参数 ...
- 学习笔记 - 深究Bitmap压缩避免OOM的核心inSampleSize的最佳取值
/** * 测试代码,通过在SDCard根目录放置几种不同大小的图片, 来自动测试压缩方式是否有效同时看是否会内存不够. * * @since * By:AsionTang * At:2014年3月2 ...
- ARM指令集----寻址方式
ARM指令集可以分为跳转指令,数据处理指令,程序状态寄存器传输指令,LOAD/Store指令,协处理器指令和异常中断产生指令6类 ARM指令集的寻址方式 数据处理指令的操作数的寻址方式 字以及无符号字 ...