Nearby Bicycles
时间限制: 1 Sec
内存限制: 128 MB
提交: 335
解决: 56
[ 提交][ 状态][ 讨论版][命题人:
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
提示
来源
ICPC 2017 HongKong
模拟:sscanf比较好写,我直接读入的字符串
#include
#define ll long long
using namespace std;
const int maxn=1e3+10;
int m,n;
struct node{
ll x,y;
}nn[maxn],mm[maxn];
string s;
int ans[maxn];
ll fan(ll x){
return x*x;
}
ll dis( int k1,int k2 ){
return fan(mm[k1].x - nn[k2].x)+fan(mm[k1].y - nn[k2].y);
}
/*
http://exam.upc.edu.cn/problem.php?id=5560
*/
int main(){
while(~scanf("%d%d",&m,&n) && m+n){
int len;
int cnt=1;
for(int k=1;k<=m;k++){
cin >> s;
len=s.size();
for(int i=0;i= '0' && s[j] <= '9';j++){
mm[cnt].x=mm[cnt].x*10+(s[j]-'0');
}
if(flag) mm[cnt].x*=(-1);
}
if(s[i]==','){
mm[cnt].y=0;
int flag=0;
if(s[ i+1 ]=='-'){
i++;
flag=1;
}
for(int j=i+1;s[j] >= '0' && s[j] <= '9';j++){
mm[cnt].y=mm[cnt].y*10+(s[j]-'0');
}
if(flag) mm[cnt].y*=(-1);
cnt++;
}
}
}
cnt=1;
for(int k=1;k<=n;k++){
cin >> s;
len=s.size();
for(int i=0;i= '0' && s[j] <= '9';j++){
nn[cnt].x=nn[cnt].x*10+(s[j]-'0');
}
if(flag) nn[cnt].x*=(-1);
}
if(s[i]==','){
nn[cnt].y=0;
int flag=0;
if(s[ i+1 ]=='-'){
i++;
flag=1;
}
for(int j=i+1;s[j] >= '0' && s[j] <= '9';j++){
nn[cnt].y=nn[cnt].y*10+(s[j]-'0');
}
if(flag) nn[cnt].y*=(-1);
cnt++;
}
}
}
/*printf("***********\n");
for(int i=1;i<=m;i++) printf("%d %d\n",mm[i].x,mm[i].y);
printf("############\n");
for(int i=1;i<=n;i++) printf("%d %d\n",nn[i].x,nn[i].y);
printf("*************\n");*/
for(int i=1;i<=n;i++){
ll tmp;
scanf("%lld",&tmp);
tmp=tmp*tmp;
int cnt=0;
for(int j=1;j<=m;j++){
if(dis(j,i) <= tmp){
cnt++;
}
}
ans[i]=cnt;
}
printf("%d",ans[1]);
for(int i=2;i<=n;i++) printf(" %d",ans[i]);
printf("\n");
}
return 0;
}