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 ...
随机推荐
- 作业16:java枚举类的秘密
JAVA代码 public enum EnumTest { HELLO,WORLD } 字节码 public final class EnumTest extends java.lang.Enum&l ...
- 【原创】大叔经验分享(84)spark sql中设置hive.exec.max.dynamic.partitions无效
spark 2.4 spark sql中执行 set hive.exec.max.dynamic.partitions=10000; 后再执行sql依然会报错: org.apache.hadoop.h ...
- css3flex布局实现商品列表
首先看图 手机商场经常会有商品列表功能,这样其实可以用flex布局实现 注意两个地方: 1.商品列表平衡间距(flex布局的换行加两端对齐) 2.中间文字行数不一样,会出现下方留下空白,如何解决(fl ...
- DAY2新手选品原则及供应商选择
一.新手选品原则(主要是为了起量) 1.净利润率高(容易起量) 2.发货方便,售后方便(发货,打包方便,不易破损,退货率低) 3.具有细分市场优势(衣服->古代衣服,论文排版) 4.市场规模够大 ...
- 【转】ufw 端口
1.扫描端口 用ubuntu自带的网络工具中的端口扫描不够强大,扫描结果可能不全,推荐用nmap,黑客常用的端口扫描利器!安装方法:sudo apt-get install nmap ,想扫描端口nm ...
- Tomcat 启动闪退解决
直接使用cmd进入tomcat 目录下进行启动,直接使用Catalina.bat run运行,查看报啥错.进一步进行解决
- 视觉SLAM关键方法总结
点"计算机视觉life"关注,置顶更快接收消息! 最近在做基于激光信息的机器人行人跟踪发现如果单独利用激光信息很难完成机器人对行人的识别.跟踪等功能,因此考虑与视觉融合的方法,这样 ...
- L1与L2正则化
目录 过拟合 结构风险最小化原理 正则化 L2正则化 L1正则化 L1与L2正则化 参考链接 过拟合 机器学习中,如果参数过多.模型过于复杂,容易造成过拟合. 结构风险最小化原理 在经验风险最小化(训 ...
- 从项目开始的Java开发学习
积累了一些项目中见到的代码,希望见一次之后自己也能写出来. 一.通过cxf JaxWsDynamicClientFactory进行WebService 客户端调用 代码:在项目中从非项目内的接口获取数 ...
- 一步一步pwn路由器之rop技术实战
前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 这次程序也是 DVRF 里面的,他的路径是 pwnable/She ...