Chinese Girls' Amusement

本文介绍了一种源自中国的传统游戏算法,旨在通过寻找特定模式来确定最佳的游戏参数K,确保每位参与者都能接到球。文章详细解释了算法背后的逻辑,并提供了一个能够处理大规模数据输入的实现方案。

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

You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chinese habits seem quite unusual or even weird to us.
So it is known that there is one popular game of Chinese girls. N girls stand forming a circle and throw a ball to each other. First girl holding a ball throws it to the K-th girl on her left (1 <= K <= N/2). That girl catches the ball and in turn throws it to the K-th girl on her left, and so on. So the ball is passed from one girl to another until it comes back to the first girl. If for example N = 7 and K = 3, the girls receive the ball in the following order: 1, 4, 7, 3, 6, 2, 5, 1.
To make the game even more interesting the girls want to choose K as large as possible, but they want one condition to hold: each girl must own the ball during the game.

This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.

Input
Input file contains one integer number N (3 <= N <= 10^2000) - the number of Chinese girls taking part in the game.

output
Output the only number - K that they should choose.

Sample Input

2

7

6

Sample Output
3

1

题意:给你一个n,n个数围城一圈,从数字1开始跳k,要求n个数都必须跳到,而且最后跳到1结束。
题解:找规律,多写几个数,发现当n是奇数的时候,k=n/2;当k是偶数的时候,如果k能对4取余等于0,k=n/2-1 ,否则k=n/2-2 .
因为数据太大,接下来需要模拟运算了。
直接上代码。
AC代码:

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	 int a[2005],b[2005];
	 int t;
	 string s;
	 cin>>t;
	 while(t--)
	 {
		  cin>>s;
		  memset(a,0,sizeof(a));
		  memset(b,0,sizeof(b));
		  int len=s.length();
		  for(int i=0;i<len;i++)
			   a[i]=s[i]-'0';
		//  for(int i=0;i<len;i++)
		//   cout<<a[i]<<" ";
		//  cout<<endl; 
		  int cnt=0;
		  for(int i=0;i<len;i++)
		  {
			   b[i]=(a[i]+cnt*10)/2;
			   if(a[i]%2==1)
			   	 cnt=1;
			   else 
			  	  cnt=0;
		  }
		//  for(int i=0;i<len;i++)
		//   cout<<b[i]<<" ";
		//  cout<<endl;
		  int flag=0;
		  int sum=a[len-2]*10+a[len-1];
		 // cout<<sum<<endl;
		  if(sum%2==0)
		  {
			   if(sum%4==0)
			    	flag=1;
			   else
			   	 flag=2;
		  }
		  if(flag==1)
		  {
			   int flag1=0;
			   for(int i=len-1;i>=0;i--)
			   {
			    if(b[i]==0)
			    {
				     flag1=1;
				     continue;
			     } 
			    else
			    {
			     int k=i;
			     for(int j=k;j<len-1;j++)
			     {
				      b[j]--;
				      if(b[j]<0)
				       b[j]+=10;
			     }
			     if(flag1)
			    	  b[len-1]=9;
			     else
			   	   b[len-1]--;
			     break;
			    }
			   }
		  }
		  else if(flag==2)
		  {
			   int flag2=0;
			   if(b[len-1]>=2)
			   {
				    flag2=1;
				    b[len-1]-=2;
			   }
			   else
			   {
				    for(int i=len-2;i>=0;i--)
				    {
				     if(b[i]==0)
				      continue;
				     else
				     {
					      int k=i;
					      for(int i=k;i<len-1;i++)
					      {
						       b[i]--;
						       if(b[i]<0)
						        b[i]+=10;
					      }
				    	  b[len-1]=b[len-1]-2+10;
				      break;
				     }
			    }
			   }
			  }
		  int j=0;
		  while(b[j]==0) j++;
		  for(;j<len;j++)
		  {
		 	  cout<<b[j];
		  }
		  	cout<<endl;
		  if(t!=0) 
			   cout<<endl;
	  }
		 return 0;
	}
		```
		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaHua_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值