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 ...
随机推荐
- linux面试题2
1. 在Linux系统中,以文件的方式访问设备 2. Linux内核引导时,从文件 /etc/fstab 中读取要加载的文件系统 3. Linux文件系统中每个文件用inode来标识 4. 链接分为 ...
- android下ListView的奇异异常大集合(持续更新)
使用ListView的addFooterView或者addHeaderView报错或者不知名的异常:at android.widget.ListView.clearRecycledState(List ...
- Arc Engine 中添加气泡提示框
一.在ArcMap中的定位操作 已知若干点的经纬度坐标,要求在地图中进行定位: 1.通过Tool >Add X Y data 定位点,注意选择地理坐标系下的wgs 1984坐标系: 2.定位后的 ...
- Generate Parentheses java实现
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632
http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...
- Ubuntu 12.04中文输入法的安装
Ubuntu 12.04中文输入法的安装 Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu ...
- 关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法
先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这 ...
- 【原】Storm Local模式和生产环境中Topology运行配置
Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...
- gcc编译器基本命令和vi编辑器2
!1 os fen时 看电影 聊天.支持多核处理器 分任务 已经绝迹cpu Trobe c 分任务操作系统三大组成部分内核,命令解释器(shell外壳),文件系统2修改文件日期或(创建文件)命令:to ...
- 如何给10^7个数据量的磁盘文件排序--bitset
题目: 输入:给定一个文件,里面最多含有n个不重复的正整数(也就是说可能含有少于n个不重复正整数),且其中每个数都小于等于n,n=10^7.输出:得到按从小到大升序排列的包含所有输入的整数的列表. 分 ...