玲珑杯-1068-Lights【规律】

本文探讨了一道编程题目,该题目要求找到将所有多边形顶点从指向内侧翻转到指向外侧所需的最少操作次数。通过分析发现,当多边形的边数为3的倍数时,所需的操作次数为边数除以3;否则,所需的操作次数等于边数。

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

题目链接:点击打开链接

1068 - Lights

Time Limit:1s Memory Limit:1024MByte

Submissions:205Solved:106

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

大意:给出一个奇多边形,每次操作可以使一个顶点和这个顶点所对应的对面的两个顶点旋转 180 度,每个点的初始状态都是朝向多边形中心,问最少需要几次操作使得所有的顶点都朝向外边。

思路:规律题,3 的倍数时需要 n/3 次,其他需要 n 次。

#include<cstdio>
using namespace std;
int n; 
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		if(n%3==0)
			printf("%d\n",n/3);
		else
			printf("%d\n",n);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值