hackerrank Week of Code Target

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 i th and the (i+1) th circle will give you i points. This means your shot includes the i th 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 1 st 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 i th shot.

Constraints

  • 1K104
  • 1N5×105
  • 1RK<RK1<...<R15×104
  • |xi|,|yi|5×104

In test data worth 40% of points, 1N103 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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值