牛客练习赛69 A 时间复杂度

H y p e r l i n k Hyperlink Hyperlink

https://ac.nowcoder.com/acm/contest/7329/A


D e s c r i p t i o n Description Description

n n n分钟后时针与分针夹角的大小(取不大于180度那部分),答案四舍五入


S o l u t i o n Solution Solution

先乘,单独加0.5,作差,再特判


C o d e Code Code

#include
#include
#include
#include
#include
#define LL long long
using namespace std;int t,x,cz,czz;
inline int solve(int a,int b)
{
     
	double a1=a,b1=b;
	if(x&1) b1+=0.5;
	if(a1>180) a1=a1-360;
	if(b1>180) b1=b1-360;
	double ans=fabs(a1-b1);
	if(ans>180) ans=360-ans;
	return ans+(x&1);
}
signed main()
{
     
	scanf("%d",&t);
	while(t--)
	{
     
		scanf("%d",&x);
		cz=x*6%360;czz=x/2%360;
		printf("%d\n",solve(cz,czz));
	}
}

你可能感兴趣的:(牛客练习赛69,A)