Acdream Chinese Girls' Amusement
A - Chinese Girls' Amusement
Problem Description
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.
Input
Output
Sample Input
7
6
Sample Output
3
1
Hint
/*
* this code is made by 987690183
* Problem: 1210
* Verdict: Accepted
* Submission Date: 2014-10-14 13:59:15
* Time: 0MS
* Memory: 1680KB
*/
#include<iostream>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
using namespace std; #define MAXN 9999
#define MAXSIZE 1000
#define DLEN 4 class BigNum
{
private:
int a[MAXSIZE]; //可以控制大数的位数
int len; //大数长度
public:
BigNum(){ len = ;memset(a,,sizeof(a)); } //构造函数
BigNum(const int); //将一个int类型的变量转化为大数
BigNum(const char*); //将一个字符串类型的变量转化为大数
BigNum(const BigNum &); //拷贝构造函数
BigNum &operator=(const BigNum &); //重载赋值运算符,大数之间进行赋值运算 friend istream& operator>>(istream&, BigNum&); //重载输入运算符
friend ostream& operator<<(ostream&, BigNum&); //重载输出运算符 BigNum operator+(const BigNum &) const; //重载加法运算符,两个大数之间的相加运算
BigNum operator-(const BigNum &) const; //重载减法运算符,两个大数之间的相减运算
BigNum operator*(const BigNum &) const; //重载乘法运算符,两个大数之间的相乘运算
BigNum operator/(const int &) const; //重载除法运算符,大数对一个整数进行相除运算 BigNum operator^(const int &) const; //大数的n次方运算
int operator%(const int &) const; //大数对一个int类型的变量进行取模运算
bool operator>(const BigNum & T)const; //大数和另一个大数的大小比较
bool operator>(const int & t)const; //大数和一个int类型的变量的大小比较 void print(); //输出大数
};
BigNum::BigNum(const int b) //将一个int类型的变量转化为大数
{
int c,d = b;
len = ;
memset(a,,sizeof(a));
while(d > MAXN)
{
c = d - (d / (MAXN + )) * (MAXN + );
d = d / (MAXN + );
a[len++] = c;
}
a[len++] = d;
}
BigNum::BigNum(const char*s) //将一个字符串类型的变量转化为大数
{
int t,k,index,l,i;
memset(a,,sizeof(a));
l=strlen(s);
len=l/DLEN;
if(l%DLEN)
len++;
index=;
for(i=l-;i>=;i-=DLEN)
{
t=;
k=i-DLEN+;
if(k<)
k=;
for(int j=k;j<=i;j++)
t=t*+s[j]-'';
a[index++]=t;
}
}
BigNum::BigNum(const BigNum & T) : len(T.len) //拷贝构造函数
{
int i;
memset(a,,sizeof(a));
for(i = ; i < len ; i++)
a[i] = T.a[i];
}
BigNum & BigNum::operator=(const BigNum & n) //重载赋值运算符,大数之间进行赋值运算
{
int i;
len = n.len;
memset(a,,sizeof(a));
for(i = ; i < len ; i++)
a[i] = n.a[i];
return *this;
}
istream& operator>>(istream & in, BigNum & b) //重载输入运算符
{
char ch[MAXSIZE*];
int i = -;
in>>ch;
int l=strlen(ch);
int count=,sum=;
for(i=l-;i>=;)
{
sum = ;
int t=;
for(int j=;j<&&i>=;j++,i--,t*=)
{
sum+=(ch[i]-'')*t;
}
b.a[count]=sum;
count++;
}
b.len =count++;
return in; }
/*ostream& operator<<(ostream& out, BigNum& b) //重载输出运算符
{
int i;
cout << b.a[b.len - 1];
for(i = b.len - 2 ; i >= 0 ; i--)
{
cout.width(DLEN);
cout.fill('0');
cout << b.a[i];
}
return out;
}*/ BigNum BigNum::operator+(const BigNum & T) const //两个大数之间的相加运算
{
BigNum t(*this);
int i,big; //位数
big = T.len > len ? T.len : len;
for(i = ; i < big ; i++)
{
t.a[i] +=T.a[i];
if(t.a[i] > MAXN)
{
t.a[i + ]++;
t.a[i] -=MAXN+;
}
}
if(t.a[big] != )
t.len = big + ;
else
t.len = big;
return t;
}
BigNum BigNum::operator-(const BigNum & T) const //两个大数之间的相减运算
{
int i,j,big;
bool flag;
BigNum t1,t2;
if(*this>T)
{
t1=*this;
t2=T;
flag=;
}
else
{
t1=T;
t2=*this;
flag=;
}
big=t1.len;
for(i = ; i < big ; i++)
{
if(t1.a[i] < t2.a[i])
{
j = i + ;
while(t1.a[j] == )
j++;
t1.a[j--]--;
while(j > i)
t1.a[j--] += MAXN;
t1.a[i] += MAXN + - t2.a[i];
}
else
t1.a[i] -= t2.a[i];
}
t1.len = big;
while(t1.a[len - ] == && t1.len > )
{
t1.len--;
big--;
}
if(flag)
t1.a[big-]=-t1.a[big-];
return t1;
} BigNum BigNum::operator*(const BigNum & T) const //两个大数之间的相乘运算
{
BigNum ret;
int i,j,up;
int temp,temp1;
for(i = ; i < len ; i++)
{
up = ;
for(j = ; j < T.len ; j++)
{
temp = a[i] * T.a[j] + ret.a[i + j] + up;
if(temp > MAXN)
{
temp1 = temp - temp / (MAXN + ) * (MAXN + );
up = temp / (MAXN + );
ret.a[i + j] = temp1;
}
else
{
up = ;
ret.a[i + j] = temp;
}
}
if(up != )
ret.a[i + j] = up;
}
ret.len = i + j;
while(ret.a[ret.len - ] == && ret.len > )
ret.len--;
return ret;
}
BigNum BigNum::operator/(const int & b) const //大数对一个整数进行相除运算
{
BigNum ret;
int i,down = ;
for(i = len - ; i >= ; i--)
{
ret.a[i] = (a[i] + down * (MAXN + )) / b;
down = a[i] + down * (MAXN + ) - ret.a[i] * b;
}
ret.len = len;
while(ret.a[ret.len - ] == && ret.len > )
ret.len--;
return ret;
}
int BigNum::operator %(const int & b) const //大数对一个int类型的变量进行取模运算
{
int i,d=;
for (i = len-; i>=; i--)
{
d = ((d * (MAXN+))% b + a[i])% b;
}
return d;
}
BigNum BigNum::operator^(const int & n) const //大数的n次方运算
{
BigNum t,ret();
int i;
if(n<)
exit(-);
if(n==)
return ;
if(n==)
return *this;
int m=n;
while(m>)
{
t=*this;
for( i=;i<<<=m;i<<=)
{
t=t*t;
}
m-=i;
ret=ret*t;
if(m==)
ret=ret*(*this);
}
return ret;
}
bool BigNum::operator>(const BigNum & T) const //大数和另一个大数的大小比较
{
int ln;
if(len > T.len)
return true;
else if(len == T.len)
{
ln = len - ;
while(a[ln] == T.a[ln] && ln >= )
ln--;
if(ln >= && a[ln] > T.a[ln])
return true;
else
return false;
}
else
return false;
}
bool BigNum::operator >(const int & t) const //大数和一个int类型的变量的大小比较
{
BigNum b(t);
return *this>b;
} void BigNum::print() //输出大数
{
int i;
//cout << a[len - 1];
printf("%d",a[len-]);
for(i = len - ; i >= ; i--)
{
/*cout.width(DLEN);
cout.fill('0');
cout << a[i];*/
printf("%04d",a[i]);
}
//cout << endl;
printf("\n");
}
int main()
{
char zero[]={""};
char one[]={""};
char two[]={""};
char hxl[];
BigNum z,ZERO(zero),ONE(one),TWO(two);
while(gets(hxl)>)
{
BigNum x(hxl);
z=x%;
if(z>)/**奇数**/
{
z=(x-ONE)/;
}
else /**偶数**/
{
x=x/;
z=x%;
if(z>)/**奇数**/
{
z=x-TWO;
}
else /**偶数**/
{
z=x-ONE;
}
}
z.print();
}
return ;
}
Acdream Chinese Girls' Amusement的更多相关文章
- 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 ...
- 数学+高精度 ZOJ 2313 Chinese Girls' Amusement
题目传送门 /* 杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度: 这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2): 1. 若n是奇数,则k ...
- 2016NEFU集训第n+5场 A - Chinese Girls' Amusement
Description You must have heard that the Chinese culture is quite different from that of Europ ...
- A - Chinese Girls' Amusement ZOJ - 2313(大数)
You must have heard that the Chinese culture is quite different from that of Europe or Russia. So so ...
- 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& ...
- zoj 2313 Chinese Girls' Amusement 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求 ...
- ASC #1
开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...
随机推荐
- AJAX简单的数据增删改与分页应用
运行截图: PageBar.js: /* * 说明: * 整体思想,1.第一页时不显示:首页,上一页, * 2.最后一页时不显示:下一页,尾页 * 3.中间有 5 页导航, * 若:3.1.(总页数& ...
- C++之路进阶——codevs4416(FFF的后宫)
4416 FFF 团卧底的后宫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 你在某日收到了 FFF 团卧底的求 ...
- 面向切面编程AOP:基于XML文件的配置
除了使用AspectJ注解声明切面,Spring也支持在bean的配置文件中声明切面,这种声明是通过aop scheme中的XML元素完成的. 首先建立一个类: package com.sevenhu ...
- JQ 动态加载多选框--随记
=====================html <table> <tr> <td style="Width: 100px; text-align: righ ...
- thinphp讲解(三)——空操作、空控制器、跨控制器、命名空间
一.“空操作”本质意思:一个对象(控制器)调用本身不存在的操作方法 一般网站处于安全考虑不给用户提示任何错误信息 在tp里面控制器controller.class.php里有个_call()方法 所以 ...
- JSP-05- JSP总结
1 客户端请求新页面 <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- Servlet工作原理(转)
Servlet运行在Servlet容器中,由容器负责Servlet实例的查找及创建工作,并按照Servlet规范的规定调用Servlet的一组方法,这些方法也叫生命周期的方法.具体调用过程如下图所示: ...
- android 应用架构随笔四(View、ViewGroup)
View表示了用户界面的基本构建模块. 一个View占用了屏幕上的一个矩形区域并且负责界面绘制和事件处理.手机屏幕上所有看得见摸得着的都是View. Activity是四大组件中唯一一个用来和用户进行 ...
- linux驱动的入口函数module_init的加载和释放【转】
本文转载自:http://blog.csdn.net/zhandoushi1982/article/details/4927579 就像你写C程序需要包含C库的头文件那样,Linux内核编程也需要包含 ...
- flex 加载arcgis 的地图json
var fs:FeatureSet=FeatureSet.fromJSON(JSONUtil.decode(e.result.toString())); for each(var gra:Graphi ...