Gym - 100199C
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的更多相关文章
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- h5获取地理坐标
h5获取地理坐标 方法:h5自带获取地理信息的api api:navigator.geolocation.getCurrentPosition https://developer.mozilla.or ...
- js如何获取数值
获取jsfunction返回的值1,首先,用初始化代码创建一个新的HTML5文件,如下所示.2,创建一个新的H1标记来接收JS中函数休闲鹿的返回值.3,创建一个新的脚本标记并在标记中创建一个新函数.函 ...
- iOS 9.0中UIAlertController的用法。
1.我为什么要写这篇博客记录它? 答:因为 UIAlertView和UIActionSheet 被划线了 苹果不推荐我们使用这两个类了,也不再进行维护和更新,为了以后方便使用我来记录一下.如图所示 正 ...
- stm32 独立看门狗 IWDG
独立看门狗IWDG 独立看门狗简单理解就是一个12位递减计数器,当计数器从某一个值递减到0时,系统就会产生一次复位 独立看门狗由专用低速时钟LSI驱动,其频率一般在30-60KHz之间,通常选择40K ...
- 【微信网页直接下载app】微信跳转-微信浏览器中直接唤起本地浏览器和App
文档传送门:https://github.com/EthanOrange/wechat-redirect demo: http://wxredirect.jslab.fun/call-app
- zabbix-设置邮箱预警
设置预警系统 机器是被监控上了,但是出了问题怎么通知呢?之前学过监控软件的都知道可以使用报警机制啊,如果监控平台zabbix server发现某个机器异常了,可以给运维管理员发邮件啊,通过邮件通知管理 ...
- mysql5.6快速安装及参数详解
一.所需软件 软件名称 版本 下载地址 当前环境 管理员账号/密码 mysql 5.6 yum安装 centOS6.7系统 zxfly/zxfly 二.安装说明 数据库所在目录 /database/m ...
- springboot 部署到tomcat,获取根路径问题。空格变为%20
String path = ResourceUtils.getURL("classpath:").getPath()+"static/upload"; Syst ...
- elasticsearch + kibana + x-pack + logstash_集群部署安装
elasticsearch 部分总体描述: 1.elasticsearch 的概念及特点.概念:elasticsearch 是一个基于 lucene 的搜索服务器.lucene 是全文搜索的一个框架. ...
- 配置Python、Django环境变量教程
配置环境变量 在Windows下你必须配置环境变量! 右击桌面或者你能看到的任何 此电脑.这台电脑或者我的电脑. 右击:属性 点击:高级系统设置 点击:环境变量 找到系统变量下的Path,双击 点击新 ...