ZOJ 2313(思路+大数)

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.

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
打了这几次比赛,发现还是自己刷的题太少了,一直被虐,心里有点不爽,不想说什么,刷题吧…
题意:这道题的意思是先一个t组输入,每组一个数n,代表有n个女孩围成一个圈,然后传递球,每个人只能向左边的人传递,要求每个人传递的距离一样(就是等距离传球),而且要求最后球每个人都传过,然后最后传到第一个开始传的人结束,问每个人最大传球的距离是多大
思路:通过找规律可以发现有3种情况,如果是奇数的话直接除以2就是答案,偶数的话有两种情况,一种是可以被4(2*2)整除,然后这个数除以2减去1就是答案,还有一种是不能被4整除,就除以2减去2就是答案,就举8和10这两个例子,8的话除以2是4,4-1=3,符合条件,但是10除以2是5,5-1=4,发现4的话就不符合条件了,会一直循环,不能使每个人都传到球,所以就再减1就符合条件了,思路就是这样,然后再注意一下输出的换行符就行了

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char v[2005];
int s[2005],q[2005];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",v);
        int m=strlen(v);
        for(int a=0;a<m;a++)
          {
            s[a]=v[a]-'0'; 
          }
        for(int a=0;a<m;a++)
          {
            q[a]=s[a]/2;
            if(s[a]-q[a]*2!=0)
              {
                s[a+1]=10+s[a+1];
              }
          }
        if(v[m-1]%2!=0)  //如果是奇数的情况
        {
            int k=0;
            for(int a=0;a<m;a++)
            {
                if(q[a]!=0) //排除最大位为0的情况
                {
                    k=1;  
                }
                if(k==1)
                {
                    printf("%d",q[a]);
                }
            }
            printf("\n");
        }
        else if(q[m-1]%2==0) //如果是可以被4整除的情况
        {
           int n;
           if(q[m-1]>=1)
           {
               q[m-1]-=1;
           }
           else
           {
              for(int a=m-2;a>=0;a--)
               {
                 if(q[a]>=1)
                 {
                    n=a;break;  //找出除了个位往后第一个不为0的数
                 }
               }
               for(int a=n;a<m;a++)
               {
                   if(a==n)
                   {
                       q[a]-=1;
                   }
                   else
                   {
                       q[a]=9;
                   }
               }
           }
           int k=0;
           for(int a=0;a<m;a++)
            {
                   if(q[a]!=0)
                   {
                       k=1;
                   }
                   if(k==1)
                   {
                       printf("%d",q[a]);
                   }
            }
               printf("\n");
        }
        else     //能被2整除但不能被4整除
        {
            int n;
            if(q[m-1]>=2)
            {
                q[m-1]-=2;
            }
            else
            {
                for(int a=m-2;a>=0;a--)
                {
                    if(q[a]>0)
                    {
                        n=a;break;
                    }
                }
                for(int a=n;a<m;a++)
                {
                    if(a==n)
                    {
                        q[a]-=1;
                    }
                    else if(a==m-1)
                    {
                        q[a]+=8;
                    }
                    else
                    {
                        q[a]=9;
                    }
                }
            }
            int k=0;
            for(int a=0;a<m;a++)
            {
                if(q[a]!=0)
                {
                    k=1;
                }
                if(k==1)
                {
                    printf("%d",q[a]);
                }
            }
            printf("\n");
        }
        if(t)
        printf("\n");  //注意格式输出
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值