CF84C I - Biathlon
来源:互联网 发布:输入法 ubuntu 编辑:程序博客网 时间:2024/06/06 21:31
I - Biathlon
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of course, biathlon as any sport, proved very difficult in practice. It takes much time and effort. Workouts, workouts, and workouts, — that's what awaited Valera on his way to great achievements in biathlon.
As for the workouts, you all probably know that every professional biathlete should ski fast and shoot precisely at the shooting range. Only in this case you can hope to be successful, because running and shooting are the two main components of biathlon. Valera has been diligent in his ski trainings, which is why he runs really fast, however, his shooting accuracy is nothing to write home about.
On a biathlon base where Valera is preparing for the competition, there is a huge rifle range with n targets. Each target have shape of a circle, and the center of each circle is located on the Ox axis. At the last training session Valera made the total of m shots. To make monitoring of his own results easier for him, one rather well-known programmer (of course it is you) was commissioned to write a program that would reveal how many and which targets Valera hit. More specifically, for each target the program must print the number of the first successful shot (in the target), or "-1" if this was not hit. The target is considered hit if the shot is inside the circle or on its boundary. Valera is counting on you and perhaps, thanks to you he will one day win international competitions.
Input
The first line of the input file contains the integer n (1 ≤ n ≤ 104), which is the number of targets. The next n lines contain descriptions of the targets. Each target is a circle whose center is located on the Ox axis. Each circle is given by its coordinate of the center x ( - 2·104 ≤ x ≤ 2·104) and its radius r (1 ≤ r ≤ 1000). It is guaranteed that no two targets coincide, intersect or are nested into each other, but they can touch each other.
The next line contains integer m (1 ≤ m ≤ 2·105), which is the number of shots. Next m lines contain descriptions of the shots, which are points on the plane, given by their coordinates x and y ( - 2·104 ≤ x, y ≤ 2·104).
All the numbers in the input are integers.
Targets and shots are numbered starting from one in the order of the input.
Output
Print on the first line a single number, the number of targets hit by Valera. Print on the second line for each of the targets the number of its first hit or "-1" (without quotes) if this number does not exist. Separate numbers with spaces.
Sample Input
Input
3
2 1
5 2
10 1
5
0 1
1 3
3 0
4 0
4 0
Output
2
3 3 -1
Input
3
3 2
7 1
11 2
4
2 1
6 0
6 4
11 2
Output
3
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of course, biathlon as any sport, proved very difficult in practice. It takes much time and effort. Workouts, workouts, and workouts, — that's what awaited Valera on his way to great achievements in biathlon.
As for the workouts, you all probably know that every professional biathlete should ski fast and shoot precisely at the shooting range. Only in this case you can hope to be successful, because running and shooting are the two main components of biathlon. Valera has been diligent in his ski trainings, which is why he runs really fast, however, his shooting accuracy is nothing to write home about.
On a biathlon base where Valera is preparing for the competition, there is a huge rifle range with n targets. Each target have shape of a circle, and the center of each circle is located on the Ox axis. At the last training session Valera made the total of m shots. To make monitoring of his own results easier for him, one rather well-known programmer (of course it is you) was commissioned to write a program that would reveal how many and which targets Valera hit. More specifically, for each target the program must print the number of the first successful shot (in the target), or "-1" if this was not hit. The target is considered hit if the shot is inside the circle or on its boundary. Valera is counting on you and perhaps, thanks to you he will one day win international competitions.
Input
The first line of the input file contains the integer n (1 ≤ n ≤ 104), which is the number of targets. The next n lines contain descriptions of the targets. Each target is a circle whose center is located on the Ox axis. Each circle is given by its coordinate of the center x ( - 2·104 ≤ x ≤ 2·104) and its radius r (1 ≤ r ≤ 1000). It is guaranteed that no two targets coincide, intersect or are nested into each other, but they can touch each other.
The next line contains integer m (1 ≤ m ≤ 2·105), which is the number of shots. Next m lines contain descriptions of the shots, which are points on the plane, given by their coordinates x and y ( - 2·104 ≤ x, y ≤ 2·104).
All the numbers in the input are integers.
Targets and shots are numbered starting from one in the order of the input.
Output
Print on the first line a single number, the number of targets hit by Valera. Print on the second line for each of the targets the number of its first hit or "-1" (without quotes) if this number does not exist. Separate numbers with spaces.
Sample Input
Input
3
2 1
5 2
10 1
5
0 1
1 3
3 0
4 0
4 0
Output
2
3 3 -1
Input
3
3 2
7 1
11 2
4
2 1
6 0
6 4
11 2
Output
3
1 2 4
题解:
求每个靶的第一个命中的子弹是第几个。。。
数据大。二分查找。。。最后不要忘了按原来顺序排列
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL __int64struct node{LL xw,r;int fafe;int kkp; }yuan[10100];int n,m;bool cmp(node xx,node yy){return xx.xw<yy.xw;}bool cmp22(node xx,node yy){return xx.kkp<yy.kkp;}int zhao(LL xx){int L=0,R=n-1,M;int li; while (L<=R){M=(L+R)/2;if (yuan[M].xw<=xx){li=M;L=M+1;}elseR=M-1;}return li;}int main(){while (~scanf("%d",&n)){int ss=0;for (int i=0;i<n;i++){scanf("%I64d%I64d",&yuan[i].xw,&yuan[i].r);yuan[i].kkp=i;yuan[i].fafe=-1;}sort(yuan,yuan+n,cmp);scanf("%d",&m);LL x,y;for (int i=1;i<=m;i++){scanf("%I64d%I64d",&x,&y);if (x<=yuan[0].xw){if (yuan[0].fafe==-1&&(yuan[0].xw-x)*(yuan[0].xw-x)+y*y<=yuan[0].r*yuan[0].r){ ss++;yuan[0].fafe=i;}}else if(x>=yuan[n-1].xw){if (yuan[n-1].fafe==-1&&(x-yuan[n-1].xw)*(x-yuan[n-1].xw)+y*y<=yuan[n-1].r*yuan[n-1].r){ss++;yuan[n-1].fafe=i;}}else{int p=zhao(x);if (yuan[p].fafe==-1&&(x-yuan[p].xw)*(x-yuan[p].xw)+y*y<=yuan[p].r*yuan[p].r) { ss++;yuan[p].fafe=i;} if (yuan[p+1].fafe==-1&&(yuan[p+1].xw-x)*(yuan[p+1].xw-x)+y*y<=yuan[p+1].r*yuan[p+1].r){ss++;yuan[p+1].fafe=i;}}}sort(yuan,yuan+n,cmp22);printf("%d\n%d",ss,yuan[0].fafe);for (int i=1;i<n;i++)printf(" %d",yuan[i].fafe);printf("\n");}return 0;}
0 0
- CF84C I - Biathlon
- ural 1821. Biathlon
- URAL 1821 Biathlon(模拟)
- codeforces D - Biathlon Track
- URAL - 1821 Biathlon(水题)
- codeforces #72 div2 C. Biathlon
- CF 424D Biathlon Track
- codeforces 424 D Biathlon Track
- codeforces 424D. Biathlon Track(dp+ brute force)
- I
- I
- ++i
- I
- I
- i
- ++i
- i++
- (++i) + (++i) + (++i) + (++i)
- wireshark
- 分词词云 logistic相关研究 2016.05.16回顾
- 利用SpringAOP+注解记录日志
- ROS中service 与action 的区别
- git开源库——调试
- CF84C I - Biathlon
- 代码设置setLayoutParams(lp);总崩溃
- iOS 拨打电话的三种方法
- RxJava入门指引,易懂
- Java获取xml格式字段内容
- jqgrid快速入门之三:单元格输入文字的获取
- NYOJ 1233 差值
- Python 3.5 基于ACM问题的语法笔记
- Combination Sum II