传送门

智障爆搜题

可以发现题目给出的式子可以移项

然后就是\(rev(N)-N=D\)

然后假设\(N=a_1*10^{n-1}+a_2*10^{n-2}+...+a_{n}\)

那么\(rev(N)=a_n*10^{n-1}+a_{n-1}*10^{n-2}+...+a_{1}\)

就容易得到\(\sum_{i=1}^{n/2}(a_n-a_{n-i+1})*(10^{n-i}-10^{i-1})\)

随便dfs一下就好了,注意一下一个n位的数可能由比n位大的数得到

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
void read(int &x){
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;
int mm,m,n,a[60];
long long f[60];
long long ans;
void dfs(int x,int n,long long sum){
if(x==n/2+1){
if(sum==m){
long long now=a[1]>=0?(9-a[1]):(9+a[1]);
for(rg int i=2;i<x;i++)now=now*(a[i]>=0?(10-a[i]):(10+a[i]));
ans+=n&1?now*10:now;
}
return ;
}
if(sum+10ll*(f[n-x]-f[x-1])<m||sum-10ll*(f[n-x]-f[x-1])>m)return ;
for(rg int i=-9;i<10;i++){
a[x]=i;
dfs(x+1,n,sum+1ll*a[x]*(f[n-x]-f[x-1]));
}
}
int main(){
read(m),mm=m;f[0]=1;
while(mm)n++,mm/=10;
for(rg int i=1;i<=18;i++)f[i]=f[i-1]*10;
for(rg int i=n;i<=18;i++)dfs(1,i,0);
printf("%lld\n",ans);
}

AT2582 Mirrored的更多相关文章

  1. AT2582 [ARC075D] Mirrored

    首先因为这个问题的解的范围我们是不清楚的,可以先考虑一下解的范围以便后面的解题. 那么我们可以大胆猜测这个数的位数应该不会很长,否则除非使用一条与 \(D\) 有关的式子外,不论我们用什么方法都计算不 ...

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

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

  3. [AtCoderContest075F]Mirrored

    [AtCoderContest075F]Mirrored 试题描述 For a positive integer \(n\), we denote the integer obtained by re ...

  4. Consistent 与 Mirrored 视角

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

  5. CentOS RabbitMQ 高可用(Mirrored)

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

  6. 【arc075F】Mirrored

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

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

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

  8. ARC075 F.Mirrored

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

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

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

随机推荐

  1. buildroot mysql mysql.mk hacking

    /*********************************************************************** * buildroot mysql mysql.mk ...

  2. P1364 医院设置

    题目描述 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为l.如上 ...

  3. InvalidOperationException: out of sync

    C#中不能在集合的迭代中修改集合数据

  4. [转]为什么GOF的23种设计模式里面没有MVC?

    GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software>/<设计 ...

  5. yeoman,grunt,bower

    Yeoman主要有三部分组成:yo(脚手架工具).grunt(构建工具).bower(包管理器).这三个工具是分别独立开发的,但是需要配合使用,来实现我们高效的工作流模式. http://www.cn ...

  6. POJ2513(字典树+图的连通性判断)

    //用map映射TLE,字典树就AC了#include"cstdio" #include"set" using namespace std; ; ;//26个小 ...

  7. Java中Redis入门(1)

    Redis是一个开源的,先进的 key-value 存储可用于构建高性能,可扩展的 Web 应用程序的解决方案. Redis官方网网站是:http://www.redis.io/,如下: Redis ...

  8. 关于overflow:hidden (转)

    关于overflow:hidden   (本文只针对hidden这个值的用处进行阐述) 关于overflow:hidden;很多人都知道他是溢出隐藏的一个属性,但是并不是很多人知道它的一些神奇的地方! ...

  9. 3java面试题 传智 发的 有用

    第一章内容介绍 20 第二章JavaSE基础 21 一.Java面向对象 21 1. 面向对象都有哪些特性以及你对这些特性的理解 21 2. 访问权限修饰符public.private.protect ...

  10. 20.Ecshop 2.x/3.x SQL注入/任意代码执行漏洞

    Ecshop 2.x/3.x SQL注入/任意代码执行漏洞 影响版本: Ecshop 2.x Ecshop 3.x-3.6.0 漏洞分析: 该漏洞影响ECShop 2.x和3.x版本,是一个典型的“二 ...