数学+高精度 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越多越好.然后就写个高精度就行了.
随机推荐
- [codeforces 260]B. Ancient Prophesy
[codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...
- Delphi与C语言类型转换对照
When converting C function prototypes to Pascal equivalent declarations, it's important to substitut ...
- STL迭代器笔记
STL迭代器简介 标准模板库(The Standard Template Library, STL)定义了五种迭代器.下面的图表画出了这几种: input output \ ...
- ubuntu 12.04 server编译安装nginx
tar -xvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./config make make install above is for zlib(refers http:// ...
- 从Trie谈到AC自动机
ZJOI的SAM让我深受打击,WJZ大神怒D陈老师之T3是SAM裸题orz...我还怎么混?暂且写篇`从Trie谈到AC自动机`骗骗经验. Trie Trie是一种好玩的数据结构.它的每个结点存的是字 ...
- Android 下载文件及写入SD卡
Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...
- 完整java开发中JDBC连接数据库代码和步骤 JDBC连接数据库
JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.l ...
- windows添加和删除服务
删除系统服务,记得一定要小心用.避免删错sc delete 服务名 加入服务: sc create 服务名 binPath= 路径 start= auto
- php的socket通信(二)
案例一:代码详解 // 设置一些基本的变量$host = "192.168.1.99";$port = 1234;// 设置超时时间set_time_limit(0);// 创建一 ...
- css3学习总结4--CSS3背景
css3背景 1. background-size 2. background-origin 3. background-clip 示例: className { background:url(bg_ ...