传送门

智障爆搜题

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

然后就是\(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. Struts2 - 文件的上传和下载

    1.  前言 这个章节是Struts2框架应用最广泛的三个版块(上传下载.国际化.校验输入)之一,所以这一版块的学习还蛮重要的. 2.  具体内容 回到顶部 2.1Struts2文件上传 2.1.1单 ...

  2. jQuery插件:图片放大镜--jQuery Zoom

    本文转载于http://blog.csdn.net/xinhaozheng/article/details/4085644, 这是一款非常不错的给图片添加放大镜效果,可以应用在诸如zen cart,m ...

  3. HihoCoder1664 01间隔方阵([Offer收割]编程练习赛40)(DP)

    给定一个NxM的01矩阵,小Hi希望从中找到一个01间隔的子方阵,并且方阵的边长越大越好. 例如对于 0100100 1000101 0101010 1010101 0101010 在右下角有一个4x ...

  4. 【LeetCode】018 4Sum

    题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...

  5. spring IOC 注解@Required

    @Required注解适用于bean属性的setter方法,使用@Required的方法必须在xml中填充,负责报错 例如下面的例子中,student中的setAge和setName有@Require ...

  6. poj 1208 Web Navigation(堆栈操作)

    一.Description Standard web browsers contain features to move backward and forward among the pages re ...

  7. C++STL 库中set容器应用

    #include<iostream> #include<cstdio> #include<set> using namespace std; set<int& ...

  8. 开源一个windows消息队列查看器

    windows消息简单易用,在异步消息发送场景的使用还是比较适合.为了方便查看队列中的消息和删除一些异常消息,开发了一个简单的小工具拿出来分享下. 源码地址:https://gitee.com/eab ...

  9. LAMP 1.4 PHP编译安装问题解决

    环境:centos X64 最小化安装 php版本:php-5.4.3 安装前.先安装些软件和库文件 yum install -y gcc gcc-c++ make zlib zlib-devel p ...

  10. shell入门-awk-3

    awk的内置变量 NR 表示行 NF 表示段 显示第十行 [root@wangshaojun ~]# awk -F ':' 'NR==10' 1.txtuucp:x:10:14:uucp:/var/s ...