数学+高精度 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越多越好.然后就写个高精度就行了.
随机推荐
- reverse array java
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- nginx lua处理图片
user apache apache; worker_processes 4; worker_rlimit_nofile 100000; #error_log logs/error.log; #err ...
- 如何用ssh挂载远程目录
如何用ssh挂载远程目录 标签: sshserver服务器linux网络 2011-06-24 10:05 2979人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. ...
- Xenomai
http://blog.csdn.net/robertsong2004/article/details/43889249 嵌入式系统的开发,如果对实时性要求不高,就可以使用Linux自身的实时补丁实现 ...
- 【leetcode】Interleaving String
Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Fo ...
- MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'
mybatis3 : mysql文如下,传入参数为string类型时‘preCode’,运行报错为:There is no getter for property named 'preCode' i ...
- python中的引用
作为一个python初学者,今天被一个python列表和词典引用的问题折磨了很久,但其实了解了缘由也很简单,记录在此备忘. 首先背书python中的引用对象问题: 1. python不允许程序员选择采 ...
- 45. Singleton类的C++/C#实现[Singleton]
[题目] 设计一个类,我们只能生成该类的一个实例. [分析] 单例模式的意图是保证一个类仅有一个实例,并提供一个访问它的全局访问点.让类自身负责保存它的唯一实例.这个类可以保证没有其他实例可.以被创建 ...
- Sass 中的 @ 规则
一. @import Sass 扩展了 CSS 的 @import 规则,让它能够引入 SCSS 和 Sass 文件. 所有引入的 SCSS 和 Sass 文件都会被合并并输出一个单一的 CSS 文件 ...