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

时间: 2024-11-06 23:05:58

2016NEFU集训第n+5场 A - Chinese Girls' Amusement的相关文章

AS1 A Chinese Girls&#39; Amusement

题意:给你一个大数 ,问你求小于这个数一半且与他互质的数. 解题思路:奇数直接是二分之一,偶数小于它一半的那个最大奇数. 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月21日 星期六 23时08分24秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #i

SGU 193.Chinese Girls&#39; Amusement

/* 实际上就是求一个k,满足k<=n/2,且gcd(n,k)=1 如果n为奇数,k为[n/2] 如果n为偶数,k=n/2-1-(n/2)%2 */ #include <iostream> using namespace std; string s; void div2() { string t; int l = s.size() - 1, tem = s[0] - '0'; if (tem > 1) t += '0' + tem / 2; tem &= 1; for (i

zoj 2313 Chinese Girls&#39; Amusement 解题报告

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求出最大的 K (1 ≤ K ≤ N/2),表示从编号为1的人开始,将球传递给他后一个人数起的第K个人,第K个人又传递给往后数的第K个人......要求这样传递下去,且每个人都有机会接到球.也就是不存在当未使得全部人都接到一次球的情况下,某个人接收到两次以上的球. 详细的解题报告在这里: http:/

Acdream Chinese Girls&#39; Amusement

A - Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chin

Acdream 1210 Chinese Girls&#39; Amusement(大数模板运算 + 找规律)

传送门 Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description You must have heard that the Chinese culture is quite different from that of Europe or Rus

大数+找规律 ACdream1210 Chinese Girls&#39; Amusement

传送门:点击打开链接 题意:对于n个点围成的圈.从一个点出发,顺时针数K个位置,一直进行这个操作直到回到最初的那个点时,恰好把所有的点都访问了一遍,问最大的K(K<=n/2) 思路:很容易就想到了一种方法,找到K<=n/2,且gcd(K,n)=1,有人是用java从n/2向1去枚举的,感觉好暴力,所以当时不敢这样写 后来发现其实是有规律的,从n=3一直算下去,会得到一个这样的序列1 1 2 1 3 3 4 3 5 5 6 5 7 7 8 7 9 9 10 9..... 很明显以4个为一组,一下

acdream 1210 Chinese Girls&#39; Amusement (打表找规律)

题意:有n个女孩围成一个圈从第1号女孩开始有一个球,可以往编号大的抛去(像传绣球一样绕着环来传),每次必须抛给左边第k个人,比如1号会抛给1+k号女孩.给出女孩的人数,如果他们都每个人都想要碰到球一次,那么这个k应该是多少(满足 1 ≤ K ≤ N/2 且 k必须尽量大)?   例如:n=7,那么1号开始拿球,抛球的顺序是 1, 4, 7, 3, 6, 2, 5, 1.  当球重新回到1女孩手中时,每个人刚好只玩了一次.注:这个数字相当大(3 ≤ N ≤ 102000) 思路: 方法(1): 暴

2016NEFU集训第n+3场 E - New Reform

Description Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only th

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

Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n