ZOJ - 2313 Chinese Girls' Amusement

这篇博客介绍了中国女孩间流行的一种游戏。N个女孩围成一圈传递一个球,从第一个女孩开始,每次向左边第K个女孩传递。为增加游戏趣味性,女孩们希望K尽可能大,同时确保每个女孩都能接住球。文章包含多个测试用例,每个用例给出N的值,并展示球的传递顺序。
摘要由CSDN通过智能技术生成

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个人围成一个圈,编号为1的人有个球,每次向左传给第K个人,问你K最大为几,满足这个球最后回到1手里,并且在此之前经过每个人。

找规律得,如果n是奇数,k=n-1/2,n是偶数的话n/2是偶数的话k=n/2-1   n/2是奇数的话k=n/2-2,然后就是大数相减,大数相除

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int text(string a){
    int len=a.length();


    if(a[len-1]=='0' || a[len-1]=='2' || a[len-1]=='4' || a[len-1]=='6'|| a[len-1]=='8')
        return 1;
    else
        return 0;

}
string sub(string a,string b){
     int i,j,k,s,flag=1;
     int tmpa[10000],tmpb[10000],c[10000];
     string ans;
     if(a.size()<b.size()|| (a.size()==b.size() && a.compare(b)<0)){
        string tmp =a;
        a=b;
        b=tmp;
        flag=0;
     }
     while(a.length()>b.length()) b='0'+b;
     int len=a.length();
     for(i=0;i<len;i++)
     {
        tmpa[i]=a[i]-'0';
        tmpb[i]=b[i]-'0';
     }
     for(i=len-1;i>=0;i--){
        if(tmpa[i]>=tmpb[i])
            c[i]=tmpa[i]-tmpb[i];
        else{
            c[i]=10+tmpa[i]-tmpb[i];
            tmpa[i-1]--;
        }
     }
     for(i=0;i<len-1;i++)
        if(c[i]!=0)
            break;
        for(j=i;j<len;j++)
            ans=ans+(char)(c[j]+'0');
        if(!flag)
            ans='-'+ans;
        return ans;

}
string division(string str,int x){
   string ans="";
   int len=str.length();
   int y=0;
   for(int i=0;i<len;i++){
    ans+=char((y*10+(str[i]-'0'))/x+'0');
    y=(y*10+(str[i]-'0') )%x;
   }
   while(*(ans.begin())=='0' && ans.size()>1)
      ans.erase(ans.begin());
   return ans;
}
int main()
  {
     string s,s1,s2;
     int t,l;
     scanf("%d",&t);
     while(t--){
       // printf("t=%d\n",t);
        cin>>s;
        //printf("t=%d\n",text(s));
        if(text(s)==1){//如果是偶数
             s1=division(s,2);//大数相除
           //  cout<<"s1="<<s1<<endl;
            if(text(s1)==1){
                 s2=sub(s1,"1");
            }
            else{
                s2=sub(s1,"2");
            }
        }
        else{
            //printf("ok\n");
            s1=sub(s,"1");
            //cout<<"s1="<<sub(s,"1")<<endl;
            s2=division(s1,2);
        }

        if(t==0){
             cout<<s2<<endl;
        }
        else{
            cout<<s2<<endl;
            cout<<endl;
        }

     }

  }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值