题目传送门

 /*
杭电一题(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的更多相关文章

  1. zoj 2313 Chinese Girls' Amusement 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求 ...

  2. ACdream 1210 Chinese Girls' Amusement(高精度)

     Chinese Girls' Amusement Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & ...

  3. Acdream Chinese Girls' Amusement

    A - Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Jav ...

  4. ACDream:1210:Chinese Girls' Amusement【水题】

    Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Oth ...

  5. 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 ...

  6. 2016NEFU集训第n+5场 A - Chinese Girls' Amusement

    Description       You must have heard that the Chinese culture is quite different from that of Europ ...

  7. acdream 1210 Chinese Girls' Amusement (打表找规律)

    题意:有n个女孩围成一个圈从第1号女孩开始有一个球,可以往编号大的抛去(像传绣球一样绕着环来传),每次必须抛给左边第k个人,比如1号会抛给1+k号女孩.给出女孩的人数,如果他们都每个人都想要碰到球一次 ...

  8. 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& ...

  9. [BZOJ1263][SCOI2006]整数划分(数学+高精度)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1263 分析:数学老师上课讲过啦= =,就是尽可能3越多越好.然后就写个高精度就行了.

随机推荐

  1. Bootstrap速学教程之简要介绍

    Bootstrap是Twitter推出的一个用于前端开发的开源工具包,由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架,不用请UI设计师也能 ...

  2. Python字符串基础操作

    ==============字符串======== >>> s1='www.baidu.com' >>> type(s1) <type 'str'> & ...

  3. 一个csrf实例漏洞挖掘带你了解什么是csrf

    [-]CSRF是个什么鬼? |___简单的理解: |----攻击者盗用了你的身份,以你的名义进行某些非法操作.CSRF能够使用你的账户发送邮件,获取你的敏感信息,甚至盗走你的财产. |___CSRF攻 ...

  4. hrb 2134 素数

    分拆素数和 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 176(99 users) Total Accepted: 106(93 u ...

  5. poj1182(食物链)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 49320   Accepted: 14385 Description ...

  6. javascript对象转化为基本数据类型规则

    原文:Object-to-Primitive Conversions in JavaScript 对象转化为基础数据类型,其实最终都是用调用对象自带的valueOf和toString两个方法之一并获得 ...

  7. js 函数声明方式以及javascript的历史

    1.function  xx(){} 2.匿名方式   window.onload=function(){dslfjdslfkjdslf}; 3.动态方式  var demo=new Function ...

  8. static-const 类成员变量

    [本文链接] http://www.cnblogs.com/hellogiser/p/static-const.html [分析] const数据成员必须在构造函数初始化列表中初始化; static数 ...

  9. After Effects的4种抠像插件比较分析

    前景 背景 1.keylight(1.2) 2.Primatee Keyer Pro4.0 3.Zbig [边界生硬] 4.Power Matte v2 [速度很慢,边界生硬]

  10. Linux设置IP

    进入 vi /etc/sysconfig/network-scripts/ifcfg-eth0  root # ifconfig eth0 192.168.22.232 root # route ad ...