UCF Local Programming Contest 2017 E题

题目链接:https://nanti.jisuanke.com/t/44821
题目大意:现给出一个圆形飞镖靶,分成等大小的w块扇形,且每个扇形分为3部分,半径为b以内的是靶心,半径在b到d之间的为双倍区,半径在d到s之间的为单倍区。现给出每次飞镖的落点,问最终总得分是多少。
思路:用自带函数atan或acos即可判断出落点与x轴的夹角,并可通过夹角判断出是在哪一片扇形,然后计算出落点离圆心的距离判断是靶心,双倍,单倍或靶外,最后把得分相加即可。
做了这个题我才知道 atan2(y, x) * 180 / PI 是可以直接算角度的, 其中y是纵坐标,x是横坐标,PI是acos(-1.0)。
队友代码(队友超棒!!)

   #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 8;
const int inf = 0x3f3f3f3f;
#define PI acos(-1.0)
#define mod %1000000007
double t[28];
void init(int p)
{
	t[1] = 360.0 / (p * 1.0);
	for(int i = 2; i <= p; i++)
		t[i] = t[1] * i * 1.0;
}
int sea(double q, int o)
{
	for(int i = 1; i <= o; i++)
	{
		if(t[i] > q)
			return i;
	}
}
int main()
{
	int n;
	int w, b, d, s;
	scanf("%d", &n);
	while(n--)
	{
		int tt;
		ll ans = 0;
		double x, y;
		scanf("%d%d%d%d", &w, &b, &d, &s);
		init(w);
		double bb = b * b * 1.0, dd = d * d * 1.0, ss = s * s * 1.0;
		scanf("%d",&tt);
		for(int i = 1; i <= tt; i++)
		{
			scanf("%lf%lf", &x, &y);
			if(fabs(x) > (s * 1.0) || fabs(y) > (s * 1.0))
				continue;
			double hu = atan2(y, x) * 180 / PI;
			double xx = x * x, yy = y * y;
			if(hu < 0)
				hu = 360.0 + hu;
			//cout << hu << endl;
			if(xx + yy < bb)
				ans += 50;
			else if(xx + yy > bb && xx + yy < dd)
			{
				ans += (sea(hu, w) * 2);
				//cout << "sea = " << sea(hu, w) << endl;
			}
			else if(xx + yy > dd && xx + yy < ss)
			{
				ans += sea(hu, w);
				//cout << "sea = " << sea(hu, w) << endl;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

我写完之后找bug找到崩溃,最后还是没有找完,TAT!!wsl!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值