Gym - 100199C

题意:

其实这么长的英文题面就是想告诉我们这个题是丢手绢。

解法:

找到与 $ N $ 互质的最大整数 $ K $ 即可。当 $ N $ 为奇数时, $ \frac{N-1}{2} $ 即为所求数;当N为偶数时,如果 $ \frac{N}{2} - 1 $ 是奇数,则为所求结果,如果为偶数,$ \frac{N}{2} - 2 $ 为所求结果

不过要注意数据范围很大,需要写高精度。

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> #define LL long long
#define N 2010 using namespace std; const int INF = 1e9;
char s[N];
int a[N],T; int main() {
scanf("%s", s);
int len = strlen(s);
int p = 0;
for (int i = 0; i < len; i++) {
a[i] = (p % 2) * 5 + (s[i] - '0')/2;
p = s[i] - '0';
}
if ((s[len-1] - '0') & 1) {
if (a[0]) printf("%d", a[0]);
for (int i = 1; i < len; i++)
printf("%d", a[i]);
puts("");
} else {
if (a[len-1] & 1) {
if (a[len-1] >= 2) a[len-1] -= 2;
else {
int i;
a[len - 1] += 8;
for (int i = len-2; i >= 0; i--) {
if (a[i] != 0) {
a[i] -= 1;
break;
}
}
for(int i = i + 1; i < len; i++)
a[i] = 9;
}
}
else {
if (a[len-1] >= 1) a[len-1] -= 1;
else {
int i;
a[len-1] += 9;
for (i = len-2; i >= 0; i--) {
if (a[i] != 0) {
a[i] -= 1;
break;
}
}
for (i = i + 1; i < len; i++)
a[i] = 9;
}
}
int i;
for(i = 0 ; i < len && a[i] == 0 ; i++);
for(int j = i; j < len; j++)
printf("%d", a[j]);
puts("");
}
//system("pause");
return 0;
}

Gym - 100199C的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. SQL Server系统函数:系统信息函数

    原文:SQL Server系统函数:系统信息函数 1.会话id,服务器信息.用户信息 select @@SPID, --返回当前连接的会话ID:SPID @@servername, --SQL Ser ...

  2. 浅谈.NET中的类型和装箱、拆箱原理

    谈到装箱拆箱,大概的意思就是值类型和引用类型的相互转换呗---值类型到引用类型叫装箱,反之则叫拆箱.这当然没有问题,可是你只知道这么多,那么建议你花点时间看看楼主这篇文章 1. .NET中的类型 为了 ...

  3. Docker 安装mysql5.6

    1.首先进入命令行现在mysql5.6镜像 E:\>docker pull mysql:5.6 2.把mysql的配置文件放入到本地,供后期做修改用 文件分别为:mysql.cnf 和 mysq ...

  4. undefined reference to `udev_device_get_action'

    /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libusb-1.0.a(libusb_1_0_la-linux_udev.o): In ...

  5. Java实现 Cookie的生成与读取

    今天学习的时候发现Cookie挺有意思的,就自己网上找点例子,自己敲点代码熟练下,现在就记录下来,分享一下. 什么是cookie?? Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服 ...

  6. python之分支和循环

    Day 1-night 三元操作符 语法:a=x if 条件 else y  即:当条件为True时,a的值赋值为x,否则赋值为y eg:small=x if x<y else y <=& ...

  7. int类型按字节打印输出

      今天在项目编程中,遇到一个问题,u32类型的参数,要赋值给一个u8 array[3],想用memcpy()函数进行赋值,由于类型大小不一致,一时不知道怎么做,经过查找,得以解决.说明如下;   项 ...

  8. asp.net的web程序适用后台线程做异步任务

    耗时的任务适用异步线程来完成. 像记录日志,发邮件,发短信,通知其他系统等.可以进行封装,让后台线程来完成,不过最好适用消息队列,redis缓存等中间件,适用定时任务来做.可以保证消息不丢失. usi ...

  9. Flyme密码验证策略升级,忘记锁屏密码及「关机密码」功能

      手机里有很多需要用到密码的地方,比如「手机密码」.「文档锁定区」.「应用加密」.「隐私模式」.忘记密码可是一件麻烦事,以前只能通过清除数据或格式化存储盘来解决.现在有了「关联魅族账号」功能,这些功 ...

  10. 模拟一个http 请求的json格式报文,带 rsa 签名操作

    一.对需要加密的字符串,定义RsaSignUnsign 类,代码如下: 实现了: 1.实现了生成新的pubkey.pri_key方法: 2.将新生成的keys 写入文件: 3.从文件获取pubkey. ...