CodeForces 1004A

本文介绍了一个算法问题:如何计算在给定多个旅馆位置的情况下,能够新建多少个旅馆,使它们与现有旅馆之间的最小距离达到指定值。通过排序和比较相邻旅馆间的距离来确定可能的建设位置。

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

题目链接

https://vjudge.net/problem/CodeForces-1004A

题意

给n个旅馆的位置,要新建一个旅馆,使得它到其他旅馆的最小距离为k,问可以建多少个这样的旅馆。

思路

给n个旅馆排序,对相邻的两个旅馆

  • 如果距离大于2k,则中间可以建两个。
  • 如果距离等于2k,则中间可以建一个。
  • 如果距离小于2k,则不能建。
AC代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI=atan(1.0)*4;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1000000007;
const int maxn = 210;

int a[maxn];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n, d, ans = 2;
    scanf("%d%d", &n, &d);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a + n);
    for(int i = 1; i < n; i++)
    {
        int x = a[i] - a[i - 1];
        if(x > 2 * d)
            ans += 2;
        else if(x == 2 * d)
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}

### 关于Codeforces平台编号为1004的比赛或题目详情 对于编号为1004的具体比赛或题目,在给定的信息中并没有直接提及该编号的相关细节。然而,通常情况下,Codeforces上的每场比赛或问题都有详细的描述页面,其中包括题目列表、提交记录以及讨论区等内容。 为了获取关于编号为1004的确切信息,建议访问Codeforces官方网站并搜索对应编号的比赛或题目[^1]。通过这种方式可以找到最准确和最新的资料。如果这是一个特定的比赛,则其URL可能类似于`https://codeforces.com/contest/1004`;如果是某个具体的问题,则可能是像`https://codeforces.com/problemset/problem/1004/A`这样的形式[^2]。 另外值得注意的是,Codeforces会定期举办不同类型的竞赛活动,包括常规赛、教育赛以及其他特别赛事。因此,了解具体的上下文有助于更精确地定位所需资源。例如,某些特殊日期举办的愚人节大赛也会有独特的编号体系[^3]。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://codeforces.com/contest/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') title_tag = soup.find('div', class_='title').find_next_sibling('div') problems_section = soup.find(id='problems-section') print(f"Title: {title_tag.text.strip()}") print("Problems:") for row in problems_section.select('.problemindexholder tr')[1:]: cols = row.select('td') index = cols[0].text.strip() name = cols[1].a['href'].split('/')[-1] points = cols[-1].text.strip() print(f"{index}: {name} ({points})") get_contest_info(1004) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值