ACM ICPC 2017 HongKong -F - Nearby Bicycles (输入问题+模拟)

本文探讨了在自行车共享系统中,如何通过计算用户与自行车之间的距离,为用户提供附近可用自行车的信息。考虑到信息和通信技术的快速发展,许多城市已经建立了自行车共享系统,关键在于提供潜在用户附近自行车的信息。文章描述了一种算法,该算法接收用户位置和阈值,返回用户范围内可租借的自行车数量。

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

F: Nearby Bicycles
时间限制: 1 Sec 内存限制: 128 MB
提交: 329 解决: 55
[提交][状态][讨论版][命题人:admin]
题目描述
With fast developments of information and communication technology, many cities today have established bicycle sharing systems. The key component of the system is to provide information on nearby bicycles to potential users. Consider m bicycles and n customers, where each bicycle is located at coordinate (cj , dj ) for j = 1, 2, …, m, and
each user i is located at coordinate (ai, bi) for i = 1, 2, …, n. The distance between two coordinates (x, y) and (xt, yt) is measured by /(x − xt)2 + (y − yt)2. For each user i = 1, 2, …, n, you are given a threshold si, your task
is to return the total number of bicycles that are within a distance of si from user i.
输入
The test data may contain many test cases. Each test case contains four lines. The first line of each case contains two integers, m and n (0 < m, n ≤ 1000). The second line contains the coordinates, (c1, d1), (c2, d2), …, (cm, dm), of bicycles 1, 2, …, m, respectively, which are separated by a space. The third line contains the coordinates, (a1, b1), (a2, b2), …, (an, bn), of users 1, 2, …, n, respectively, which are separated by a space. The fourth line contains the thresholds, s1, s2, …, sn, of the n users. The last test case is followed by a line of two 0s. All the number of coordinate in the input is in the range [−100000, 100000].
输出
The output for each test case contains a line of n integers, k1, k2, …, kn, where each ki represents the total number of bicycles that are within a distance of si from user i, for i = 1, 2, …, n.
样例输入
4 2

(0,0) (0,1) (1,0) (1,1)

(0,0) (1,1)

1 1

0 0
样例输出
3 3

【水题】
恶心的一匹, 输入问题, 导致输出超限;

单纯的用scanf  是不行的,   解决方法一:  scanf("%s",s)  到 串s 中 在用 sscanf(s,"(%lld,%lld)",&x,&y)

从 s 串流中 获得,  这样是可行的,
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct node{
    int x,y;
};
node a[1005],b[1005];
double s[1005];
int num[1005];
char S[500005];
int main()
{
    while(cin >> n >> m && n && m)
    {
        char str;
        for(int i = 0;i < n;i++)
        {
            scanf("%s",S);
            sscanf(S,"(%d,%d)",&a[i].x,&a[i].y);
        }
        for(int j = 0;j < m;j++)
        {
            scanf("%s",S);//把原来的输入当做字符串处理
            sscanf(S,"(%d,%d)",&b[j].x,&b[j].y);//从输入的字符串提取数字输入格式即可
        }
        for(int i = 0;i < m;i++)
        {
            scanf("%lf",&s[i]);
        }
        memset(num,0,sizeof(num));
        for(int j = 0;j < m;j++)
        {
            for(int i = 0;i < n;i++)
            {
                double d = sqrt((b[j].x - a[i].x)*(b[j].x - a[i].x) +(b[j].y - a[i].y) * (b[j].y - a[i].y));
                if(d <= s[j])
                {
                    num[j]++;
                }
            }
        }
        for(int i = 0;i < m;i++)
        {
            cout << num[i] << " ";
        }
        cout << endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值