2016NEFU集训第n+5场 A - Chinese Girls' Amusement

Posted 邻家那小孩儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016NEFU集训第n+5场 A - Chinese Girls' Amusement相关的知识,希望对你有一定的参考价值。

Description

      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.

Input

Input 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

7
6

Sample Output

3
1

#include <iostream>
#include <cstring>
using namespace std;
char data[3005];
int a[3005],d,c[3005];

int main()
{
    while(cin>>data)
    {
        memset(a,0,sizeof(a));
        int len1=strlen(data);
        for(int i=0;i<len1;i++)
        a[i]=data[len1-i-1]-0;
        d=0;
        for(int i=len1-1;i>=0;i--)
        {
            d=d*10+a[i];
            c[i]=d/2;
            d=d%2;
        }
        if(a[0]%2==1){
        while(c[len1-1]==0&&len1>1) len1--;
        for(int i=len1-1;i>=0;i--)
        cout<<c[i];
        cout<<endl;}
        else
        {
            if(c[0]%2==1)//得到奇数减2
            {
                if(c[0]>=2)
                c[0]-=2;
                else
                {
                    for(int i=0;i<len1;i++)
                    {
                        if(c[i]<=1)
                        {
                            c[i+1]--;
                            c[i]=(c[i]+10)-2;
                        }
                        else
                        break;
                    }
                }
            }
            else //得到偶数减1
            {
                if(c[0]>=1)
                c[0]-=1;
                else
                {
                    for(int i=0;i<len1;i++)
                    {
                        if(c[i]<=0)
                        {
                            c[i+1]--;
                            c[i]=(c[i]+10)-1;
                        }
                        else
                        break;
                    }
                }
            }
            while(c[len1-1]==0&&len1>1) len1--;
        for(int i=len1-1;i>=0;i--)
        cout<<c[i];
        cout<<endl;
        }
    }
    return 0;
}

 

以上是关于2016NEFU集训第n+5场 A - Chinese Girls' Amusement的主要内容,如果未能解决你的问题,请参考以下文章

2016NEFU集训第n+3场 G - Tanya and Toys

NOIP2016提高A组集训第13场11.11最大匹配

NOIP2016提高A组集训第4场11.1平衡的子集

Jzoj 4889NOIP2016提高A组集训第14场11.12暴力贪心最长公共回文子序列

NOIP2016提高A组集训第3场10.31高维宇宙

NOIP2016提高A组集训第1场10.29完美标号