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 ...
随机推荐
- Panorama——H5实现全景图片原理
前言 H5是怎么实现全景图片播放呢? 正文 全景图的基本原理即 "等距圆柱投影",这是一种将球体上的各个点投影到圆柱体的侧面上的一种投影方式,投影后再展开就是一张 2:1 的矩形图 ...
- Flask学习-Flask app启动过程
因为0.1版本整体代码大概只有350行,比较简单.所以本篇文章会以Flask 0.1版本源码为基础进行剖析Flask应用的启动过程. Flask参考资料flask,官网有一个最简单app: from ...
- Python网络数据采集
一.正则表达式 * 表匹配0次或者多次 a*b* + 表至少一次 [ ] 匹配任意一个 ( ) 辨识一个编组 {m,n} m或者n 次 [^] 匹配任意不在中括号里的字符 | ...
- SDN交换机迁移2
关于迁移过程中迁移目标(被迁移的交换机和目标控制器)的选择 SDN中基于过程优化的交换机竞争迁移算法 通信学报 交换机:请求速率大于域内平均请求速率的交换机集合: 控制器:综合网络中时延.流量和控制器 ...
- Inside the Social Network’s (Datacenter) Network
摘要: 大量服务提供商投资越来越多的更大数据中心来保证基础计算需求以支持他们的服务.因此,研究人员和行业从业者都集中了大量的努力设计网络结构有效互连和管理流量以保证这些数据中心的性能.不幸的是,数据中 ...
- 电梯V1.0
电梯V1.0 GitHub仓库地址 Problem 一栋3层的大楼(楼层编号0-2),设有一台无限载重的电梯,初始时电梯停在0层.电梯移动1层的耗时为1,在某一层停靠的耗时为1(时间初始为0).电梯不 ...
- Alpha发布评价
1.奋斗吧兄弟组 食物链系统 是一个比较成熟的工具,可以应用于生物课程的辅助讲解,具有很强的软件目的性和实用性. 2.Newbee 俄罗斯方块 因为选了很经典的游戏,所以在创新上下了一定功夫,可是没有 ...
- PAT 1064 朋友数
https://pintia.cn/problem-sets/994805260223102976/problems/994805267416334336 如果两个整数各位数字的和是一样的,则被称为是 ...
- js 判断是否选中
js的方法 window.onload = function(){ var oDiv = document.getElementById('div1'); alert(oDiv.checked) } ...
- 外媒速递:系统管理员必须掌握的20条Linux命令
[51CTO.com原创稿件]外媒速递是核子可乐精选的近日国外媒体的精彩文章推荐,希望大家喜欢! 今天推荐的内容包括:系统管理员必须掌握的20条Linux命令.五款最佳Linux屏幕记录应用.MySQ ...