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 ...
随机推荐
- Linux Centos7配置mysql8.0数据库
本文转至:672530440 在此感谢博主,撒花!!! 本文主要从以下几个方面对自己在centos7 下安装mysql8过程做如下总结: CentOS7 安装mysql8 步骤: window下的Na ...
- MySQL: Can’t connect to MySQL server on (111 “Connection refused”)
1. Mysql连接问题 远程访问mysql或者通过docker访问宿主机mysql经常会碰到下面的问题: Can't connect to MySQL server on (111 "Co ...
- Postman --> YApi
初始 Postman,才知其如此强大,慢慢接触学习吧~ “Modern software is built on APIs,Postman helps you develop APIs faster” ...
- Linux CentOS7 httpd 配置注释
本文首发:https://www.somata.work/2019/LinuxCentOShttpdConfigComment.html 如果没看懂可以去看看官方发布的文档 apache官方文档 co ...
- 开启 clr enabled
'; GO RECONFIGURE; GO '; GO RECONFIGURE; '; GO
- 复杂sql书写方法
给你一个复杂sql连接不同的表,多个嵌套查询条件等的语句时,你是非常的胆怯由于对语法的不熟悉以及没有经验和自信,现在我们来学习一下如何写复杂的sql,我们把它分解为很多小的步骤进行 一.集中最后的输出 ...
- NLP学习(1)---Glove模型---词向量模型
一.简介: 1.概念:glove是一种无监督的Word representation方法. Count-based模型,如GloVe,本质上是对共现矩阵进行降维.首先,构建一个词汇的共现矩阵,每一行是 ...
- vscode开发
基于 Electron 开发.typescript编写.底层 Node.js 打造的一个编辑器 , 不是IDE,被称为“披着IDE外衣的编辑器”
- python中常用的九种预处理方法
本文总结的是我们大家在python中常见的数据预处理方法,以下通过sklearn的preprocessing模块来介绍; 1. 标准化(Standardization or Mean Removal ...
- java语言实现对程序设计语言源文件统计字符数、单词数、行数及其他拓展功。
本次作业Github项目地址:https://github.com/YiChenglong2018/WordCount 一.项目简介 本项目的需求可以概括为:对程序设计语言源文件统计字符数.单词数.行 ...