题目链接: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!!!