Chaarshanbegaan at Cafebazaar 水题

题目描述
Chaarshanbegaan is a gathering event at Cafebazaar similar to TGIF events at Google. Some entertainment programs like pantomime, foosball, Xbox/PS4, and several board games are part of the event. You are going to set up a dart game in Chaarshanbegaan. As a techie organizing a game for techies, you would rather use a smart screen and write a program to calculate the scores instead of hanging a traditional dartboard and scoring the shots manually. Your program must get the coordinates of dart shots for a player and calculate his/her total score. The score for each dart shot (at point (x, y)) is calculated based on its distance from the center of the dartboard (point (0, 0)). If the distance is d millimeters, the score is calculated based on the following table:
Chaarshanbegaan at Cafebazaar 水题

输入
The first line of the input contains a single integer N as the number of dart shots for a player (1 ⩽ N ⩽ 100). Each of the next N lines contains two space-separated integers as the coordinates (x, y) of a dart shot. The coordinates are in millimeters and their absolute values will not be greater than 300.

输出
Print a single line containing the total score of the player.

样例输入
2
4 7
-31 -5
样例输出
18

给你一些点,求到原点的距离,根据距离大小对应的分值,输出总分即可,这里用到了一个函数hypotl(),用来直接求到(0,0)点的距离,原来函数的用法是计算x和y平方和的平方根,而不会在计算的中间阶段发生不适当的上溢或下溢。这里直接拿来求到原点的距离,效果和拆开写是一样的。

AC代码

#include<iostream>
#include<stdio.h>
#include<math.h> 
using namespace std;
int main()
{
	int t;
	cin>>t;
	int ans=0;
	while(t--)
	{
		int x,y;
		cin>>x>>y;
		double dis=hypotl(x,y);
		if(dis<=10)
			ans+=10;
		else if(dis>10&&dis<=30)
			ans+=9;
		else if(dis>30&&dis<=50)
			ans+=8;
		else if(dis>50&&dis<=70)
			ans+=7;
		else if(dis>70&&dis<=90)
			ans+=6;
		else if(dis>90&&dis<=110)
			ans+=5;
		else if(dis>110&&dis<=130)
			ans+=4;
		else if(dis>130&&dis<=150)
			ans+=3;
		else if(dis>150&&dis<=170)
			ans+=2;
		else if(dis>170&&dis<=190)
			ans+=1;
		else if(dis>190)
			ans+=0;
	}
	cout<<ans<<endl;
	return 0;
}