[AtCoderContest075F]Mirrored
[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的更多相关文章
- 最长回文子串(Mirrored String II)
Note: this is a harder version of Mirrored string I. The gorillas have recently discovered that the ...
- Consistent 与 Mirrored 视角
Consistent 与 Mirrored 视角 在进行分布式训练时,OneFlow 框架提供了两种角度看待数据与模型的关系,被称作 consistent 视角与 mirrored 视角. 本文将介绍 ...
- CentOS RabbitMQ 高可用(Mirrored)
原文:https://www.sunjianhua.cn/archives/centos-rabbitmq.html 一.RabbitMQ 单节点 1.1.Windows 版安装配置 1.1.1 安装 ...
- 【arc075F】Mirrored
Portal --> arc075_f Solution 一开始抱着"我有信仰爆搜就可以过"的心态写了一个爆搜.. 但是因为..剪枝和枚举方式不够优秀愉快T掉了q ...
- 【ARC075F】Mirrored 搜索/数位dp
Description 给定正整数DD,求有多少个正整数NN,满足rev(N)=N+Drev(N)=N+D,其中rev(N)rev(N)表示将NN的十进制表示翻转来读得到的数 Input 一个 ...
- ARC075 F.Mirrored
题目大意:给定D,询问有多少个数,它的翻转减去它本身等于D 题解做法很无脑,利用的是2^(L/2)的dfs,妥妥超时 于是找到了一种神奇的做法. #include <iostream> u ...
- AT2582 Mirrored
传送门 智障爆搜题 可以发现题目给出的式子可以移项 然后就是\(rev(N)-N=D\) 然后假设\(N=a_1*10^{n-1}+a_2*10^{n-2}+...+a_{n}\) 那么\(rev(N ...
- Atcoder F - Mirrored(思维+搜索)
题目链接:http://arc075.contest.atcoder.jp/tasks/arc075_d 题意:求rev(N)=N+D的个数,rev表示取反.例如rev(123)=321 题解:具体看 ...
- 【arc075f】AtCoder Regular Contest 075 F - Mirrored
题意 给定一个数x,问有多少个正整数y,使得rev(y)-y==x 其中rev(x)表示x按位翻转之后得到的数. x<=1e9 做法 首先通过打表发现,这个答案不会很大. 这就说明解相当地松弛. ...
随机推荐
- 如何用JavaScript实现2+2=5?
我大学毕业找工作时,经常做一些稀奇古怪的面试题.这不,给大家分享一道整蛊的面试题,它其实不能算一道正式的面试题,大家可以用它来捉弄你们那些程序员朋友. 题目:如何用JavaScript实现2+2=5? ...
- Java变量、Java对象初始化顺序
局部变量与成员变量: 局部变量分为: 行参:在方法签名中定义的局部变量,随方法的结束而凋亡. 方法内的局部变量:必须在方法内对其显示初始化,从初始化后开始生效,随方法的结束而凋亡. 代码块内的局部变量 ...
- python3.6.2利用pyinstaller发布EXE
我的环境是Ubuntu 16.04,系统自带Python2和Python3 安装 pip3 install pyinstaller 发布exe pyinstaller -F helloworld.py ...
- python_99_面向对象多态
#多态:一种接口,多种实现.主要作用:实现接口重用 #方法1: class Animal(object): def __init__(self,name): self.name=name class ...
- springboot超详细笔记
一.Spring Boot 入门 1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,m ...
- 如何下载js类库
https://bower.io/ 这个已经淘汰 https://learn.jquery.com/jquery-ui/environments/bower/ Web sites are made ...
- JavaScript深入浅出第2课:函数是一等公民是什么意思呢?
摘要: 听起来很炫酷的一等公民是啥? <JavaScript深入浅出>系列: JavaScript深入浅出第1课:箭头函数中的this究竟是什么鬼? JavaScript深入浅出第2课:函 ...
- untiy3d action管理机制的编写
使用unity3d对于一些可视化强迫者来说,是一个不错的选择,但unity3d没有cocos2d的action管理机制,比如cocos2dx的CCMoveTo,CCScale等action,所以笔者通 ...
- C/C++ 数组与指针
#include <iostream>using namespace std;int main(){ char *a[]={"ab","ccs",& ...
- 05tar命令详解
tar 命令用于对文件进行打包压缩或解压,格式为"tar [选项][文件]". 在Linux 系统中,常见的文件格式比较多,其中主要使用的是 .tar 或者 .tar.gz 或 ...