数学+高精度 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越多越好.然后就写个高精度就行了.
随机推荐
- 那些不是秘密的微信earning方法
微信这个新兴的移动平台着实培养了一些自媒体大号,让个人也能成为媒体中心,当然微信也成为了集富利器.他们是怎么做到的呢?让我们探究一下微信earn的方法吧,一起发散思维. ★微信公众平台推广功能公测,大 ...
- CKEditor使用笔记
相关资源 1. 首页地址:http://ckeditor.com/ 2. 下载地址:http://ckeditor.com/download 3. SDK地址:http://sdk.ckeditor. ...
- IOS AFNetworking
http://www.coneboy.com/?p=716 AFNetworking 使用总结 (用法+JSON解析) 2013 年 4 月 11 日 No comments Article 这几天 ...
- :( Call to a member function Table() on a non-object 错误位置
:( Call to a member function Table() on a non-object 错误位置 $Model不是模板,是你自己先前链接数据库返回的对象...我的是改为$Form
- PHP中magic_quotes_gpc动态关闭无效的问题
昨天浏览线上项目,发现了一个问题:部分文本输出中的引号前多了一道反斜杠,比如: 引号内容多了\"反斜杠\" 单从页面展现的结果来看,猜测应该是PHP中的magic_quotes_g ...
- 【OpenStack】OpenStack系列4之Glance详解
下载安装 参考:http://www.linuxidc.com/Linux/2012-08/68964.htm http://www.it165.net/os/html/201402/7246.htm ...
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- CodeForces - 420A (字符对称问题)
Start Up Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- BaseColumns以及自定义Column
android provider 包下自带的BaseColumn /* * Copyright (C) 2006 The Android Open Source Project * * License ...
- 转圈游戏(codevs 3285)
题目描述 Description n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...