A - Chinese Girls' Amusement ZOJ - 2313(大数)
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 - Chinese Girls' Amusement ZOJ - 2313(大数)的更多相关文章
- 数学+高精度 ZOJ 2313 Chinese Girls' Amusement
题目传送门 /* 杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度: 这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2): 1. 若n是奇数,则k ...
- Acdream Chinese Girls' Amusement
A - Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Jav ...
- ACdream 1210 Chinese Girls' Amusement(高精度)
Chinese Girls' Amusement Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & ...
- ACDream:1210:Chinese Girls' Amusement【水题】
Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Oth ...
- 2016NEFU集训第n+5场 A - Chinese Girls' Amusement
Description You must have heard that the Chinese culture is quite different from that of Europ ...
- zoj 2313 Chinese Girls' Amusement 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求 ...
- acdream 1210 Chinese Girls' Amusement (打表找规律)
题意:有n个女孩围成一个圈从第1号女孩开始有一个球,可以往编号大的抛去(像传绣球一样绕着环来传),每次必须抛给左边第k个人,比如1号会抛给1+k号女孩.给出女孩的人数,如果他们都每个人都想要碰到球一次 ...
- SGU 193.Chinese Girls' Amusement
/* 实际上就是求一个k,满足k<=n/2,且gcd(n,k)=1 如果n为奇数,k为[n/2] 如果n为偶数,k=n/2-1-(n/2)%2 */ #include <iostream& ...
- 训练赛第一场A题 (ZOJ 2313)
解题报告:n个人围坐成一圈,并且将这n个人从1到n编号,然后编号为1 的人手上有一个物品,将这个物品往向左传递给第k个人,1<=k<=n/2,当这个物品再次传到编号为1 的人的手上时,游戏 ...
随机推荐
- PHP做分页查询(查询结果也显示为分页)
1.先把数据库里所有的数据分页显示在页面,并在显示数据的表格上方加上查询表单. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...
- 20151024_001_C#基础知识(静态与非静态的区别,值类型和引用类型,堆和栈的区别,字符串的不可变性,命名空间)
1:我们把这些具有相同属性和相同方法的对象进行进一步的封装,抽象出来类这个概念. 类就是个模子,确定了对象应该具有的属性和方法. 对象是根据类创建出来的. 2:类:语法 [public] class ...
- poj 2387 Til the Cows Come Home(dijkstra算法)
题目链接:http://poj.org/problem?id=2387 题目大意:起点一定是1,终点给出,然后求出1到所给点的最短路径. 注意的是先输入边,在输入的顶点数,不要弄反哦~~~ #incl ...
- ribbon设置url级别的超时时间
序 ribbon的超时设置,只能按转发的serviceId来分的,无法像nginx那样直接在每个转发的链接里头设置超时时间.这里hack一下,实现url基本的ribbon超时时间设置.具体的思路就是重 ...
- Android日历开发之右上角标注红点事件
1.效果如下所示: 2.方法: 前提:已经知道如何在右上角画圆点的情况下. 这是一个任务显示器,每个任务都有一个时间,比如2014.01.12. 如果要标注2016.08 ...
- glob模块的使用
glob模块 功能描述:glob模块可以使用Unix shell风格的通配符匹配符合特定格式的文件和文件夹,跟windows的文件搜索功能差不多.glob模块并非调用一个子shell实现搜索功能,而是 ...
- 【数位dp入门】【HDU2089】62
为了我的点歪的技能树…… 所以开始补一些sb的东西…… #include<bits/stdc++.h> typedef long long ll; using namespace std; ...
- axios使用
axios 基于promise用于浏览器和node.js的http客户端 特点 支持浏览器和node.js 支持promise 能拦截请求和响应 能转换请求和响应数据 能取消请求 自动转换JSON数据 ...
- memcached结合php以及memcache共享session
//安装php的memcache扩展 一.使用php自带的pecl安装程序 [root@localhost src]# /usr/local/php/bin/pecl install memcache ...
- maven使用备忘
maven的所有功能本质上都是通过插件来实现的所有的功能.archetype插件就是根据项目类型创建项目的插件.执行archetype:generate命令就会list一系列的项目类型,可以选择一个合 ...