[AtCoderContest075F]Mirrored

试题描述

For a positive integer \(n\), we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by \(rev(n)\). For example, \(rev(123)=321\) and \(rev(4000)=4\).

You are given a positive integer \(D\). How many positive integers \(N\) satisfy \(rev(N)=N+D\)?

\(rev(n)\) 表示 \(n\) 在十进制表示下的倒过来写的数,对于给定的 \(D\),求有多少个正整数 \(N\) 满足 \(rev(N) = N + D\)。

输入

Input is given from Standard Input in the following format:

D

输出

Print the number of the positive integers \(N\) such that \(rev(N)=N+D\).

输入示例1

63

输出示例1

2

输入示例2

75

输出示例2

0

输入示例3

864197532

输出示例3

1920

数据规模及约定

\(D\) is an integer.

\(1 \le D < 10^9\)

题解

题目地址

考虑从两头向中间依次确定每一位,考虑每一位的贡献。

  abcdefg
- gfedcba

所以 \(a - g\) 的贡献是 \((a - g) * 999999\),下一位贡献是 \((b - f) * 999900\)……所以 \(D\) 必须是 \(9\) 的倍数。令 \(d = D \div 9\)

那么每一位的贡献依次是:

111111
11110
1100

上面是偶数位的情况,偶数位类似。

注意到上面的形式,我们可以根据 \(d\) 确定出每一位的数位差是多少。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 15
#define LL long long int d;
LL ans; int main() {
d = read(); if(d % 9) return puts("0"), 0;
d /= 9;
// printf("d: %d\n", d);
LL ini = 0, ten = 1;
for(int i = 1; i <= 17; i++) {
LL tmp = 1, D = d;
ini = ini * 10 + 1;
LL base = ini, lten = ten, rten = 1;
for(int j = 0; j <= (i >> 1); j++) {
// printf("%lld * %lld [tmp *= %lld] (%lld)\n", base, D % (rten * 10) / rten, 10 - abs(D % (rten * 10) / rten) - (!j ? 1 : 0), D);
tmp *= 10 - abs(D % (rten * 10) / rten) - (!j ? 1 : 0);
D -= base * (D % (rten * 10) / rten);
base -= lten + rten;
lten /= 10; rten *= 10;
}
// printf("%lld * %d (%lld)\n", base, D % (rten * 10) / rten, D);
ten *= 10;
// printf("(%lld %lld)\n", ini, tmp);
if(!D) ans += tmp;
} printf("%lld\n", ans); return 0;
}

[AtCoderContest075F]Mirrored的更多相关文章

  1. 最长回文子串(Mirrored String II)

    Note: this is a harder version of Mirrored string I. The gorillas have recently discovered that the ...

  2. Consistent 与 Mirrored 视角

    Consistent 与 Mirrored 视角 在进行分布式训练时,OneFlow 框架提供了两种角度看待数据与模型的关系,被称作 consistent 视角与 mirrored 视角. 本文将介绍 ...

  3. CentOS RabbitMQ 高可用(Mirrored)

    原文:https://www.sunjianhua.cn/archives/centos-rabbitmq.html 一.RabbitMQ 单节点 1.1.Windows 版安装配置 1.1.1 安装 ...

  4. 【arc075F】Mirrored

    Portal --> arc075_f Solution ​  一开始抱着"我有信仰爆搜就可以过"的心态写了一个爆搜.. ​  但是因为..剪枝和枚举方式不够优秀愉快T掉了q ...

  5. 【ARC075F】Mirrored 搜索/数位dp

    Description ​ 给定正整数DD,求有多少个正整数NN,满足rev(N)=N+Drev(N)=N+D,其中rev(N)rev(N)表示将NN的十进制表示翻转来读得到的数 Input ​ 一个 ...

  6. ARC075 F.Mirrored

    题目大意:给定D,询问有多少个数,它的翻转减去它本身等于D 题解做法很无脑,利用的是2^(L/2)的dfs,妥妥超时 于是找到了一种神奇的做法. #include <iostream> u ...

  7. AT2582 Mirrored

    传送门 智障爆搜题 可以发现题目给出的式子可以移项 然后就是\(rev(N)-N=D\) 然后假设\(N=a_1*10^{n-1}+a_2*10^{n-2}+...+a_{n}\) 那么\(rev(N ...

  8. Atcoder F - Mirrored(思维+搜索)

    题目链接:http://arc075.contest.atcoder.jp/tasks/arc075_d 题意:求rev(N)=N+D的个数,rev表示取反.例如rev(123)=321 题解:具体看 ...

  9. 【arc075f】AtCoder Regular Contest 075 F - Mirrored

    题意 给定一个数x,问有多少个正整数y,使得rev(y)-y==x 其中rev(x)表示x按位翻转之后得到的数. x<=1e9 做法 首先通过打表发现,这个答案不会很大. 这就说明解相当地松弛. ...

随机推荐

  1. uoj#300.【CTSC2017】吉夫特

    题面:http://uoj.ac/problem/300 一道大水题,然而我并不知道$lucas$定理的推论.. $\binom{n}{m}$为奇数的充要条件是$n&m=n$.那么我们对于每个 ...

  2. Set、Map及数组去重

    https://cloud.tencent.com/developer/article/1437254 https://blog.csdn.net/weixin_34247299/article/de ...

  3. 2018.5.8 XML编程

    1.XML的概念 XML(Extensible Markup Language)可扩展性标记语言是一套定义语义标记的规则,这些标记将文档分成许多部件并对这些部件加以标识. 可拓展性标记语言是SGML( ...

  4. Python2 和Python3 的区别

    print Python 2中的print语句被Python 3中的print()函数取代,这意味着在Python 3中必须用括号将需要输出的对象括起来. 在Python 2中使用额外的括号也是可以的 ...

  5. exportfs: /mnt/demo requires fsid= for NFS export

    解决方法:/mnt/demo 10.0.1.57(fsid=0,rw,async) //加入fsid=0参数就可.

  6. helm install

    reference 前提:已安装k8s:v1.10.4 helm install on master(无需下载官方tar包) 链接:https://pan.baidu.com/s/1Ji3Ru1pTQ ...

  7. 安装IAR ewarm

    一  安装准备 (ST方案) 1 嵌入式集成开发环境IAR ewarm 5.41 2 J-Link4.20 3 emberznet-4.3.0协议栈安装包 option1:tools - stm32软 ...

  8. 【思维题 单调栈】loj#2430. 「POI2014」沙拉餐厅 Salad Bar

    t老师的做法好神…… 题目描述 桌面上有 n 个水果,分别是苹果和橘子.Bytea需要从水果中选择连续的一个区间,并从左到右或从右到左拿水果,且过程中橘子的数量必须始终不小于苹果的数量.求最长的区间大 ...

  9. Python入门基本语法

      Python入门 以下主要讲述Python的一些基础语法,包含行的缩进在python中的重要意义,python中常见的保留字和引号的使用,如何实现单行注释和多行注释. print("he ...

  10. leetcode-27-exercise_bit maniputation

    461. Hamming Distance 解题思路: 把两个数的每一位和1比较,如果结果不同说明这两位不同.要比较32次. int hammingDistance(int x, int y) { i ...