您的位置:首页 > 其它

文章标题 Chinese Girls' Amusement

2017-04-18 21:25 357 查看
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个人围一个圈,从第一个人开始往左传递给第k个人,求k最大为几使再次传到第一个人时,每个人都接到过球

规律:n为奇数,则k=n/2;

n为偶数,且n/2为偶数,k=n/2-1;

n为偶数,且n/2为奇数,k=n/2-2;

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int a[2009],b[2009],k;
int bb[2009];
int cc[2009];
void w()
{
memset(cc,0,sizeof(cc));
int m=0;
for(int i=k-1; i>=0; i--)
{
cc[i]=b[i]-bb[i]-m;
if(cc[i]<0&&cc[i+1]>=0)
{
cc[i]=cc[i]+10;
m=1;
}
else
{
m=0;
}
}
}
void init(int l)
{
int x=0;
k=0;
for(int i=0; i<l; i++)
{
int y=x*10+a[i];
if(y<2&&i!=0)
{
x=y;
b[k++]=0;
}
else if(y<2&&i==0)
x=y;
else
{
b[k++]=y/2;
x=y%2;
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(bb,0,sizeof(bb));
string s;
cin>>s;
int l=s.size();
for(int i=0; i<l; i++)
a[i]=s[i]-'0';
int j=0;
if(a[l-1]%2==0)
{
init(l);
if(b[k-1]%2==0)
{
bb[k-1]=1;
w();
for(int i=0;i<k;i++)
{
if(cc[i]!=0)
{
j=i;
break;
}
}
for(int i=j;i<k;i++)
printf("%d",cc[i]);
}
else
{
bb[k-1]=2;
w();
for(int i=0;i<k;i++)
{
if(cc[i]!=0)
{
j=i;
break;
}
}
for(int i=j;i<k;i++)
printf("%d",cc[i]);
}
}
else
{
init(l);
for(int i=0; i<k; i++)
printf("%d",b[i]);
}
printf("\n");
if(T!=0)
printf("\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: