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

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 串流中 获得,  这样是可行的,

    方法二 用 string 输入 cin  然后依次处理,   真心恶心的一匹, 输出超限18遍


 [code]

#include <cstdio>
#include <cstring>
#include <bits/stdc++.h>
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const int MAXN=1e3+5;
 
using namespace std;
 
struct node{
    ll first,second;
}P[MAXN],V[MAXN],t;
ll  dis( node a,node b)
{
    return ( (a.first-b.first)*(a.first-b.first)+ (a.second-b.second)*(a.second-b.second) );
}
ll a[MAXN];
int ans[MAXN];
char s[500000];
int main()
{
    int m,n;
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        getchar();
        if(n==0&&m==0)
            break;
        memset(ans,0,sizeof(ans));
        for(int i=1;i<=m;i++)
        {
            ll x,y;
            scanf("%s",s);
            sscanf(s,"(%lld,%lld)",&x,&y);
            t.first=(x);t.second=(y);
            V[i]=t;
        }
        getchar();
        for(int i=1;i<=n;i++)
        {
            ll x,y;
            scanf("%s",s);
            sscanf(s,"(%lld,%lld)",&x,&y);
            t.first=(x);t.second=(y);
            P[i]=t;
        }
        getchar();
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        for(int j=1;j<=n;j++)
        {
            for(int i=1;i<=m;i++)
            {
                if(dis(P[j],V[i])<=(a[j]*a[j]))
                    ans[j]++;
            }
        }
        for(int i=1;i<=n;i++)
            printf("%d%c",ans[i],i==n?'\n':' ');
    }
    return 0;
}

123

posted @ 2018-04-05 22:02  Sizaif  阅读(255)  评论(0编辑  收藏  举报