[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 做法 首先通过打表发现,这个答案不会很大. 这就说明解相当地松弛. ...
随机推荐
- Mycat实现读写分离、分库分表
系统开发中,数据库是非常重要的一个点.除了程序的本身的优化,如:SQL语句优化.代码优化,数据库的处理本身优化也是非常重要的.主从.热备.分表分库等都是系统发展迟早会遇到的技术问题问题.Mycat是一 ...
- lca(最近公共祖先(在线)) 倍增法详解
转自大佬博客 : https://blog.csdn.net/lw277232240/article/details/72870644 描述:倍增法用于很多算法当中,通过字面意思来理解 LCA是啥呢 ...
- docker安装gitlab-ce
pull and run docker pull docker.io/gitlab/gitlab-ce docker run -itd --name gitlab -p 10080:80 gitlab ...
- 解决Windows 与Mac 双系统下的蓝牙设备共用的问题
不知道有多少人和我一样用的蓝牙鼠标或者键盘,有的话应该都会遇到同一个问题:即在一个系统下配好对后在另一个系统必须重新配对才能使用,很是麻烦.还要将蓝牙设备进入发现模式,OS下搜索,连接....终于昨天 ...
- 浅谈一类「AC自动机计数」问题
最近写了几道AC自动机的题.这几题主要考察的是对AC自动机的浅层理解套上计数. 几道计数题 [AC自动机]bzoj3172: [Tjoi2013]单词 把被动贡献看成主动贡献. [状态压缩dp]119 ...
- 初识Mysql之基本简单语法总结
一. DDL(data definition language)语句:数据定义语言. 这些语句定义了不同的数据段.数据库.表.列.索引等数据库对象.常用语句关键字:create.drop.alter ...
- 单例模式的几种实现-Java版
目录 关键点 饿汉式 懒汉式 双检锁 静态内部类单例模式 枚举方式 关键点 私有化构造器 通过静态方法或枚举返回单例类对象 确保单例类对象只有一个,尤其在多线程环境下. 确保每个类被序列化不会重新创建 ...
- python入门:简单模拟登陆时UTF-8转换成GBK编码
#!/usr/bin/env python # -*- coding:utf-8 -*- """ 给变量x赋值为字符串‘请输入用户名:’ 变量x_unicode的赋值等于 ...
- Python基础——字典(dict)
由键-值对构建的集合. 创建 dic1={} type(dic1) dic2=dict() type(dic2) 初始化 dic2={'hello':123,'world':456,'python': ...
- python计算机基础(三)
简述Python垃圾回收机制: 当x=10,赋值x=11,的代码,也就是10没有对应的变量名, 10在python眼中相当于垃圾,就会被清理掉,释放内存. 对于下述代码: x = 10 y = 10 ...