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. Django rest-framework框架-组件之视图

    视图: a. django class Test(View): ... b. rest_framework class Test(APIView): ... c. GenericAPIView 一般不 ...

  2. 学HTML第二晚 登录框的制作

    进天来弄个登录框 首先,登录框要有登录的账号.密码.和确定.取消的,密码也是要隐藏的. 然后,我们就做: 这是理想中的样子,有了想法,就开始写了 <!dotcype html> <h ...

  3. flex应用实例

    代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...

  4. $.ajax()属性详解

    $.ajax()方法详解 jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为Strin ...

  5. 安装window、linux双系统

    一.安装windows,从主硬盘中分出40G空间: 二.下载linux ios镜像; 三.安装UltraISO,把下载好的linux镜像写入u盘: ‘写入硬盘镜像’->写入方式‘usb-HDD+ ...

  6. EventBus使用教程

    如图准备工作: 父子(子父)组件触发 EventBus.$emit('sub') EventBus.$on('sub',()=>{ console.log(1111222232211122) } ...

  7. 二〇一八-美团工程师面试解析(Java)

    一轮面试: 小数是怎么存的 算法题:N二进制有多少个1 Linux命令(不熟悉 JVM垃圾回收算法 C或者伪代码实现复制算法 volatile 树的先序中序后序以及应用场景 Mysql存储记录的数据结 ...

  8. Paper Reading:Faster RCNN

    Faster R-CNN 论文:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks 发表时间: ...

  9. jQuery——jQuery对象与DOM对象

    1.jQuery对象与DOM对象的区别 通过jQuery方法包装后的对象,是一个类数组对象.它与DOM对象完全不同,唯一相似的是它们都能操作DOM. 通过jQuery处理DOM的操作,可以让开发者更专 ...

  10. Vue -- element-ui FileSaver.js 导出

    html <el-button type="danger" @click="exportRs">导出Excel报表</el-button> ...