hdu 3022 Sum of Digits
http://acm.hdu.edu.cn/showproblem.php?pid=3022
题意:
#include<cstdio>
#include<algorithm> using namespace std; #define N 901
#define M 8101 int dp[N][M],dp2[N][M]; void pre()
{
for(int i=;i<=;++i) dp[i][i*i]=,dp2[i][i*i]=i;
for(int i=;i<N;++i)
for(int j=;j<M;++j)
if(dp[i][j] && dp[i][j]!=)
for(int k=;k<=;++k)
if(!dp[i+k][j+k*k] || dp[i+k][j+k*k]>dp[i][j]+)
{
dp[i+k][j+k*k]=dp[i][j]+;
dp2[i+k][j+k*k]=k;
}
else if(dp[i+k][j+k*k]==dp[i][j]+) dp2[i+k][j+k*k]=min(dp2[i+k][j+k*k],k);
} int main()
{
pre();
int T,n,m,d;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
if(n>=N || m>=M || !dp[n][m]) printf("No solution\n");
else
{
while(n)
{
printf("%d",d=dp2[n][m]);
n-=d;
m-=d*d;
}
putchar('\n');
}
}
return ;
}
hdu 3022 Sum of Digits的更多相关文章
- CodeForces 489C Given Length and Sum of Digits... (贪心)
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...
- Sum of Digits / Digital Root
Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root i ...
- Maximum Sum of Digits(CodeForces 1060B)
Description You are given a positive integer nn. Let S(x) be sum of digits in base 10 representation ...
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- Hdu3022 Sum of Digits
Sum of Digits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDOJ(HDU).1258 Sum It Up (DFS)
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...
- codeforces#277.5 C. Given Length and Sum of Digits
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- cf#513 B. Maximum Sum of Digits
B. Maximum Sum of Digits time limit per test 2 seconds memory limit per test 512 megabytes input sta ...
随机推荐
- 浅谈iOS 自动调节文本高度
文字展示是任何GUI开发的一个最常规的编程任务.可能一提及文字我们脑中想到的无非就是 Label 和 Text 这两个关键词,今天我们就谈谈 Label. 无论在 Windows 或者 Web 开发中 ...
- JNI探秘-----FileInputStream的read方法详解
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 上一章我们已经分析过File ...
- VMware Tools安装和卸载
1.卸载 a.查找 vmware-uninstall-tools.pl 路径:sudo find / -name 'vmware-uninstall-tools.pl' b.切换到 vmware-un ...
- Python中 list, numpy.array, torch.Tensor 格式相互转化
1.1 list 转 numpy ndarray = np.array(list) 1.2 numpy 转 list list = ndarray.tolist() 2.1 list 转 torch. ...
- TKmath Package gp数据类型
点,向量,方向 二维:gp_Pnt2d, gp_Vec2d, gp_Dir2d:它们的内部都存储 gp_XY 三维:gp_Pnt, gp_Vec, gp_Dir:它们的内部都存储 gp_XYZ 轴向与 ...
- 使用kubeadm安装kubernetes高可用集群
kubeadm安装kubernetes高可用集群搭建 第一步:首先搭建etcd集群 yum install -y etcd 配置文件 /etc/etcd/etcd.confETCD_NAME=inf ...
- 在windows10上搭建caffe
caffe环境的搭建一直是让我最头疼的,最近在Windows10上成功搭建了caffe,在此对搭建过程进行记录. 安装主要是按照caffe github上的安装说明进行的,caffe的github主页 ...
- Flask入门的第一个项目
前言: Flask简介:Flask是一个使用 Python 编写的轻量级 Web 应用框架,基于 WerkzeugWSGI工具箱和 Jinja2模板引擎. 想要学习flask,又非常迷茫,不知如何下手 ...
- 使用不同的namespace让不同的kafka/Storm连接同一个zookeeper
背景介绍: 需要部署2个kafka独立环境,但是只有一个zookeeper集群. 需要部署2个独立的storm环境,但是只有一个zookeeper集群. ----------------------- ...
- Beta博客集合
Beta博客集合 Task1:beta冲刺准备 冲刺准备 Task2:Beta阶段冲刺合集 Beta阶段冲刺一 Beta阶段冲刺二 Beta阶段冲刺三 Beta阶段冲刺四 Beta阶段冲刺五 Task ...