hackerrank Week of Code Target
2015-11-30 13:58
344 查看
Problem Statement
Let's consider a standard darts target that consists of
K
concentric circles with the corresponding radiuses
R1,R2,...,RK
with the common center in the origin (0,0).
If your shot lands inside the smallest circle, you will get
K
points. Landing between the ith
and the (i+1)th
circle will give you i
points. This means your shot includes the ith
circle, but excludes the (i+1)th
circle. If the shot lands on the boundary of the circle, it will be considered to have landed inside that circle.
Finally, if you are unable to land inside or on the boundary of the
1st
circle, you will get 0
points for that shot.
You are given coordinates xi,yi
of N
shots. Calculate the final score (the sum of all the points).
Input Format
The first line contains two space-separated integers:
K
and N.
The second line contains K
space-separated integers: R1,R2,...RK.
The following N
lines contain two-space separated integers xi,
yi,
the coordinates of the ith
shot.
Constraints
1≤K≤104
1≤N≤5×105
1≤RK<RK−1<...<R1≤5×104
|xi|,|yi|≤5×104
In test data worth 40% of points, 1≤N≤103
holds in addition.
Output Format
Output one integer on a single line: The sum of all the points scored.
Sample Input
Sample Output
Explanation
The partial scores are: 5+5+4+3+3+2=22
代码:
Let's consider a standard darts target that consists of
K
concentric circles with the corresponding radiuses
R1,R2,...,RK
with the common center in the origin (0,0).
If your shot lands inside the smallest circle, you will get
K
points. Landing between the ith
and the (i+1)th
circle will give you i
points. This means your shot includes the ith
circle, but excludes the (i+1)th
circle. If the shot lands on the boundary of the circle, it will be considered to have landed inside that circle.
Finally, if you are unable to land inside or on the boundary of the
1st
circle, you will get 0
points for that shot.
You are given coordinates xi,yi
of N
shots. Calculate the final score (the sum of all the points).
Input Format
The first line contains two space-separated integers:
K
and N.
The second line contains K
space-separated integers: R1,R2,...RK.
The following N
lines contain two-space separated integers xi,
yi,
the coordinates of the ith
shot.
Constraints
1≤K≤104
1≤N≤5×105
1≤RK<RK−1<...<R1≤5×104
|xi|,|yi|≤5×104
In test data worth 40% of points, 1≤N≤103
holds in addition.
Output Format
Output one integer on a single line: The sum of all the points scored.
Sample Input
5 6 10 8 6 4 2 0 0 1 1 2 2 3 3 4 4 5 5
Sample Output
22
Explanation
The partial scores are: 5+5+4+3+3+2=22
代码:
#include<iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int maxn=500000+100; int a[maxn]; struct point { long long x,y; double v; }b[maxn]; bool cmp(point w,point u) { return w.v>u.v; } int main() { int n,k; while(~scanf("%d%d",&k,&n)) { for(int i=1;i<=k;i++) { scanf("%d",&a[i]); } for(int i=0;i<n;i++) { cin>>b[i].x>>b[i].y; b[i].v=sqrt(b[i].x*b[i].x+b[i].y*b[i].y); } sort(b,b+n,cmp); long long ans=0; int cur=2; for(int i=0;i<n;i++) { if(b[i].v>=a[1]) continue; if(b[i].v<=a[k]) { ans+=k; continue; } if(b[i].v>a[cur]) ans+=(cur-1); else { while(b[i].v<=a[cur]&&cur<=k) cur++; ans+=(cur-1); } // cout<<ans<<endl; } cout<<ans<<endl; } return 0; }
相关文章推荐
- [Tools]WinRAR 3.71 解压加密文件出错, 7z可以正常work.
- Android图片处理
- 运算符优先级-PHP运算符优先级
- 纯代码搭建首页,不实用storyboard作为window的根视图控制器
- Android四种启动模式
- ldap验证用户(java)<不能以simple协议来获取连接进行连接>
- 垃圾回收机制GC知识再总结兼谈如何用好GC
- 二叉树的四种遍历实现
- Java 内部类中使用局部变量必须是final
- js获取html内容
- Android开发-UI控件:实现ListView过滤功能,继承于BaseAdapter,非ArrayAdapter。
- JiuDuOj——1051
- C-(001-006).C语言基础总结
- linux安装软件依赖性问题
- Android 动画之ScaleAnimation应用详解
- Elasticsearch 集群配置单播模式
- 从Android运行时出发,打造我们的脱壳神器
- 运算符优先级-Python 运算符优先级
- iOS 解决单击手势与UItableviewCell表格手势冲突
- VSFTPD全攻略(/etc/vsftpd/vsftpd.conf文件详解)