加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

ZOJ2313 Chinese Girls' Amusement(大数运算,找规律)

发布时间:2020-12-14 03:14:36 所属栏目:大数据 来源:网络整理
导读:题目: Chinese Girls' Amusement Time Limit:? 2 Seconds ????? Memory Limit:? 65536 KB 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

题目:

Chinese Girls' Amusement

Time Limit:?2 Seconds ????? Memory Limit:?65536 KB

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



Author:? Andrew Stankevich
Source:?
Andrew Stankevich's Contest #1
Submit???? Status
思路:

这道题,主要是找规律,数据量太大,果断上模板,在这里顺便存一下,大数减法和除法的代码

代码:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define N 100+20
#define M 1000000+10
#define ll long long
using namespace std;
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;
}
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; i++)
        if(c[i]!=0)
            break;
    for(j=i; j<len; j++)
        ans=ans+(char)(c[j]+'0');
    if(!flag)
        ans='-'+ans;
    return ans;

}
int main()
{
    string s;
    int t;
    cin>>t;
    while(t--)
    {
        cin>>s;
        int num=(s[s.length()-1]-'0')+(s[s.length()-2]-'0')*10;
        if(s.length()==1)
        {
            if(((s[s.length()-1])-'0')%2)
                cout<<division(s,2)<<endl;
            else
            {
                if(((s[s.length()-1]-'0')/2-1)%2)
                    cout<<sub(division(s,2),"1")<<endl;
                else
                    cout<<sub(division(s,"2")<<endl;
            }
        }
        else
        {
            if(num%2)
            {
                cout<<division(s,2)<<endl;
            }
            else
            {
                if((num/2-1)%2)
                    cout<<sub(division(s,"2")<<endl;
            }
        }
        if(t)puts("");
    }
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读