CodeForces-630 M. Turn【求模运算】

本博客探讨了如何通过旋转相机拍摄的图片来最小化垂直偏差,以提高人脸识别系统的准确性。主要关注于实现这一目标的技术细节和算法优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

M. Turn
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face.

One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it better, look into it. And the camera takes their photo at that time. What could be better for high quality identification?

But not everything is so simple. The pictures from camera appear rotated too (on clockwise camera rotation frame the content becomes rotated counter-clockwise). But the identification algorithm can work only with faces that are just slightly deviated from vertical.

Vasya was entrusted to correct the situation — to rotate a captured image so that image would be minimally deviated from vertical. Requirements were severe. Firstly, the picture should be rotated only on angle divisible by 90 degrees to not lose a bit of information about the image. Secondly, the frames from the camera are so huge and FPS is so big that adequate rotation speed is provided by hardware FPGA solution only. And this solution can rotate only by 90 degrees clockwise. Of course, one can apply 90 degrees turn several times but for the sake of performance the number of turns should be minimized.

Help Vasya implement the program that by the given rotation angle of the camera can determine the minimum number of 90 degrees clockwise turns necessary to get a picture in which up direction deviation from vertical is minimum.

The next figure contains frames taken from an unrotated camera, then from rotated 90 degrees clockwise, then from rotated 90 degrees counter-clockwise. Arrows show direction to "true up".

The next figure shows 90 degrees clockwise turn by FPGA hardware.

Input

The only line of the input contains one integer x ( - 1018 ≤ x ≤ 1018) — camera angle in degrees. Positive value denotes clockwise camera rotation, negative — counter-clockwise.

Output

Output one integer — the minimum required number of 90 degrees clockwise turns.

Examples
input
60
output
1
input
-60
output
3
Note

When the camera is rotated 60 degrees counter-clockwise (the second example), an image from it is rotated 60 degrees clockwise. One90 degrees clockwise turn of the image result in 150 degrees clockwise total rotation and deviation from "true up" for one turn is 150degrees. Two 90 degrees clockwise turns of the image result in 240 degrees clockwise total rotation and deviation from "true up" for two turns is 120 degrees because 240 degrees clockwise equal to 120 degrees counter-clockwise. Three 90 degrees clockwise turns of the image result in 330 degrees clockwise total rotation and deviation from "true up" for three turns is 30 degrees because 330 degrees clockwise equal to 30 degrees counter-clockwise.

From 60150120 and 30 degrees deviations the smallest is 30, and it it achieved in three 90 degrees clockwise turns.


题意:

给出一幅画的正常位置对应的初始角度,每次可以逆时针旋转90度,问最少旋转多少次可以使得画的角度更接近于正常位置

正常位置:你家里怎么挂表的?


题解:

主要是看懂题意,然后注意各种取余,不算复杂的一道题,主要是细节!


#include<stdio.h>
typedef long long ll;
ll abs(ll x)
{
    return x>0?x:-x;
}
ll num(ll x)//角度
{
	if(x>180)
	{
		return 360-x;
	}
	return x;
}
int main()
{
    ll x,y;
    //freopen("shuju.txt","r",stdin);
    while(~scanf("%I64d",&x))
    {
        y=(abs(x))%360;//有效度数
        if(x<0)
        {
            y=-y+360;
        }
        ll ans=0,deg=num(y),tp=y;
        for(ll i=1;i<4;++i)
        {
            tp=(tp+270)%360;
            if(deg>num(tp))
            {
                deg=num(tp);
                ans=i;
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值