A
来源:互联网 发布:淘宝店包邮怎么做 编辑:程序博客网 时间:2024/05/17 04:07
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
//大数加和大数除再加上找规律//总体上分为两种情况://(1) 如果n是奇数的话,K=(n-1)/2//(2) 如果n是偶数又分两种情况:(2.1) 如果n/2是偶数的话 K=n/2-1 (2.2) 如果n/2是奇数的话 K=n/2-2#include<map>#include<set>#include<queue>#include<stack>#include<vector>#include<math.h>#include<cstdio>#include<sstream>#include<numeric>//STL数值算法头文件#include<stdlib.h>#include <ctype.h>#include<string.h>#include<iostream>#include<algorithm>#include<functional>//模板类头文件using namespace std;typedef long long ll;const int maxn=110000;const int INF=0x3f3f3f3f;void jminus(int a[],int len,int b){ a[len-1]-=b; for(int i=len-1; i>0; i--)//借位 { if(a[i]<0) { a[i]+=10; a[i-1]-=1; } }}void divide(int a[],int len )//大数除{ for(int i=0; i<len-1; i++) { if(a[i]%2==0) a[i]=a[i]/2; else { a[i]=a[i]/2; a[i+1]+=10; } } a[len-1]/=2;}int main(){ int t; scanf("%d",&t); while(t--) { char str[2010]; cin>>str; int len=strlen(str); int a[len]; for(int i=0; i<len; i++) a[i]=str[i]-'0'; if(a[len-1]%2==1) { divide(a,len); int start=0; while(a[start]==0) start++; for(int i=start; i<len; i++) cout<<a[i]; cout<<endl; } else { if(len==1) { int temp=a[0]; if(temp%4==2)//n是偶数,n/2是奇数的情况 { divide(a,len); jminus(a,len,2); } else//n是偶数,n/2是偶数 { divide(a,len); jminus(a,len,1); } } else { int temp=a[len-1]+10*a[len-2]; if(temp%4==2) { divide(a,len); jminus(a,len,2); } else { divide(a,len); jminus(a,len,1); } } int start=0; while(a[start]==0) start++; for(int i=start; i<len; i++) cout<<a[i]; cout<<endl; } if(t>0) cout<<endl; } return 0;}
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- A
- A*
- a
- A
- a
- angularjs --- 自定义时间格式的过滤器
- git
- mvc:exclude-mapping
- swing选择文件并获取文件路径
- 01背包第K最优解 HDU
- A
- MySQL数据表相关操作-创建与测试数据类型
- 计算机基础之牛客网刷题第三篇
- 创建后台任务的两种代码模式
- 关于高德地图获取Key失败
- Canvas之translate、scale、rotate、skew方法讲解!
- 若格的全志R8开发板配置为rtl8188eusV1.0(分色排版)
- LintCode 424-逆波兰表达式求值
- 开启Java8来启用Lambda表达式在Android Studio的一些配置