数学+高精度 ZOJ 2313 Chinese Girls' Amusement
/*
杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度;
这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2);
1. 若n是奇数,则k = (n-1) / 2;
2. 若n是偶数,讨论(n-1)/2 的奇偶性,若不是奇数,则是n/2-2;
详细解释(证明):http://www.xuebuyuan.com/1552889.html
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 2e3 + ;
const int INF = 0x3f3f3f3f;
string s;
string ans; void div_2(void)
{
int len = s.length ();
int tmp = s[] - '';
if (tmp > ) ans += char (tmp/ + '');
tmp &= ;
for (int i=; i<len; ++i)
{
tmp = tmp * + (s[i] - '');
ans += char (tmp/ + '');
tmp &= ;
}
} void sub_1(void)
{
int i = ans.length () - ;
while (ans[i] == '')
{
ans[i] = ''; i--;
}
ans[i] -= ;
} void print(void)
{
int i = ;
while (ans[i] == '') i++;
for (; i<ans.length (); ++i) cout << ans[i]; cout << endl;
} int main(void) //ZOJ 2313 Chinese Girls' Amusement
{
//freopen ("ZOJ_2313.in", "r", stdin); int t;
cin >> t;
while (t--)
{
s = ""; ans = "";
cin >> s;
div_2 ();
if ((s[s.length ()-]-'') & ) cout << ans << endl;
else
{
sub_1 ();
if ((ans[ans.length ()-]-'') & ) print ();
else
{
sub_1 (); print ();
}
}
if (t) puts ("");
} return ;
}
数学+高精度 ZOJ 2313 Chinese Girls' Amusement的更多相关文章
- zoj 2313 Chinese Girls' Amusement 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求 ...
- ACdream 1210 Chinese Girls' Amusement(高精度)
Chinese Girls' Amusement Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & ...
- 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: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Oth ...
- 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 ...
- 2016NEFU集训第n+5场 A - Chinese Girls' Amusement
Description You must have heard that the Chinese culture is quite different from that of Europ ...
- 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& ...
- [BZOJ1263][SCOI2006]整数划分(数学+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1263 分析:数学老师上课讲过啦= =,就是尽可能3越多越好.然后就写个高精度就行了.
随机推荐
- 完美串(区间dp)
完美串 Description 爱美之心人皆有之,GG也不例外.所以GG他对于完美串有一种热衷的爱.在GG眼中完美串是一个具有无比魅力的01子串.这个子串有之其魅力之处,对它取反后水平翻转,它又和它原 ...
- 实战 -- Redis2.4.2集成spring3.2.2
redis.host=... redis.port= redis.pass= redis.timeout= #最大能够保持idel状态的对象数 redis.maxIdle= #最大分配的对象数 red ...
- crontab报错
$mail 选择对应的数字查看邮件 File "/opt/app/python/tv-cms-for-ch/current/scripts/sync_cms_for_ch.py", ...
- 在 OpenGL ES 2.0 上实现视差贴图(Parallax Mapping)
在 OpenGL ES 2.0 上实现视差贴图(Parallax Mapping) 视差贴图 最近一直在研究如何在我的 iPad 2(只支持 OpenGL ES 2.0, 不支持 3.0) 上实现 视 ...
- 3Sum & 4Sum
3 Sum Given an array S of n integers, are there elements a, b, c in Ssuch that a + b + c = 0? Find a ...
- kettle job通过javascript进行循环控制
任何一种编程语言都少不了循环,kettle中的job也一样.那么kettle中的job是怎么通过JavaScript来达到类似于编程语言中的for循环呢? var max = parent_job.g ...
- mysql in 查询优化
2014年11月29日21:01:01 场景:有的时候查询数据库的select in 语句中会有非常多不连续的数值,会很影响查询效率 方法:将select in 查询转换成多个select betwe ...
- 重温CSS之背景、文本样式
CSS背景样式: 背景色:background-color属性,设置元素的背景色,如:div {background:blue;}--设置所有div元素的背景为蓝色: 背景图像:background- ...
- HDU1717小数化分数2
小数化分数2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- google maps js v3 api教程(2) -- 在地图上添加标记
原文链接 google maps javascript官方文档:https://developers.google.com/maps/documentation/javascript/ 我们在创建地图 ...