玲珑学院problem1068

来源:互联网 发布:python 机器人 编辑:程序博客网 时间:2024/04/29 15:20
DESCRIPTION

Mr. Van is given a regular polygon of size N, which is a positive odd number. At each vertex there is a guard which can be rotated. Initially, all the guards face to the inner center of the vertex. Now Mr. Van wants to rotate all guards faced to the outside. A guard can only be rotated 180 degree in one step. When he rotates the a guard 180 degree, the guard itself and the two guards which are opposite to it will also rotate 180 degree. Now given N, please tell Mr.Van the minimum steps of rotating in order to turn all the guards faced to the outside.

INPUT
The first line is a single integer TT, indicating the number of test cases.
For each test case:
The input contains a single odd integer N (3N1000)N (3≤N≤1000).
OUTPUT
For each test case, output the answer in a single line.
SAMPLE INPUT
2
5
3
SAMPLE OUTPUT
5
1
思路还是挺简单的:每一次的旋转,都会有三个点的旋转,当每个点的旋转次数都为奇数次的时候也就达到目的了。所以可以直接从1开始枚举操作次数,假设多边形的边数是n,当操作次数i满足条件:i*3能被n整除,且i*3/n(表示每个定点被操作的次数)为奇数时就得到答案了,我们不用去管怎么操作,只用知道最少操作这么多次就可达到目的。
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;int T;void init(){freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);}void readdata(){scanf("%d", &T);}void work(){int n;while(T--){scanf("%d", &n);for(int i = 1; ; i++){int cnt = i*3;if(cnt%n == 0 && cnt/n%2 == 1){printf("%d\n", i);break;}}}}int main(){init();readdata();work();return 0;}

0 0