CF 312C. The Closest Pair 简单构造

本文介绍了一种构造n个不同点的方法,确保给定代码片段的时间复杂度超过k。通过设置所有点的横坐标相同,简化了计算过程,并确保了算法效率。适用于竞赛编程和算法分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:
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


给出n和k,构造n个不同的点,使得这段代码的时间复杂度(tot)大于k. n<=2000,k<=1e9, 
构造的点范围为[-1e9,1e9].


构造:让n个点的横坐标距第一相等,则任意两个横坐标之差为0 都不可能大于最短距离 跑满(n-1)*(n-1+1)/2次

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,mod=1e9+7;
int n,k;
int main()
{
    cin>>n>>k;
    int num=n*(n-1)/2;
    if(k>=num)
    {
        puts("no solution");
        return 0;
    }
    for(int i=1;i<=n;i++)
        printf("%d %d\n",0,i);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值