Hdu3022 Sum of Digits
Sum of Digits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 810 Accepted Submission(s): 220
9 81
12 9
6 10
7 9
No solution
1122
111112
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int T,s1,s2,f[][],g[][]; void solve()
{
for (int i = ; i <= ; i++)
f[i][i * i] = ,g[i][i * i] = i;
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
if (f[i][j])
{
for (int k = ; k <= ; k++)
{
if (!f[i + k][j + k * k] || f[i + k][j + k * k] > f[i][j] + )
{
f[i + k][j + k * k] = f[i][j] + ;
g[i + k][j + k * k] = k;
}
else if (f[i + k][j + k * k] == f[i][j] + )
g[i + k][j + k * k] = min(g[i + k][j + k * k],k);
}
}
} int main()
{
solve();
scanf("%d",&T);
while (T--)
{
scanf("%d%d",&s1,&s2);
if (s1 > || s2 > || !f[s1][s2] || f[s1][s2] > )
printf("No solution\n");
else
{
while (s1 && s2)
{
printf("%d",g[s1][s2]);
int t = g[s1][s2];
s1 -= t;
s2 -= t * t;
}
printf("\n");
}
} return ;
}
Hdu3022 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 ...
- 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 ...
- CodeForces 489C Given Length and Sum of Digits... (dfs)
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...
随机推荐
- 【Python入门学习】闭包&装饰器&开放封闭原则
1. 介绍闭包 闭包:如果在一个内部函数里,对在外部作用域的变量(不是全局作用域)进行引用,那边内部函数被称为闭包(closure) 例如:如果在一个内部函数里:func2()就是内部函数, 对在外部 ...
- 所见即所得:七大无需编程的DIY开发工具
现如今,各种DIY开发工具不断的出现,使得企业和个人在短短几分钟内就能完成应用的创建和发布,大大节省了在时间和资金上的投入.此外,DIY工具的出现,也帮助广大不具备专业知识和技术的“移动开发粉”创建自 ...
- 用 Python 3 的 async / await 做异步编程
前年我曾写过一篇<初探 Python 3 的异步 IO 编程>,当时只是初步接触了一下 yield from 语法和 asyncio 标准库.前些日子我在 V2EX 看到一篇<为什么 ...
- sqoop 常用命令集
sqoop是一个介于分布式数据系统与关系型系统之间数据转换的一个数据转换工具 常用命令集sqoop2中sqoop-shell 创建link.job sqoop:001> show link 显示 ...
- [C++] Solve "Cannot run program "gdb": Unknown reason" error
In Mac OSX, The Issue Image: 1. Build the project on Eclipse successfully. 2. Run gdb on command lin ...
- 一个简单的rest_framework demo
models.py from django.db import models class UserInfo(models.Model): username = models.CharField(max ...
- lamp一键配置 --转自秋水
https://teddysun.com/lamp LAMP一键安装脚本 最后修改于:2015年11月08日 / 秋水逸冰 / 54,300 次围观 973 本脚本适用环境: 系统支持:CentOS/ ...
- 软工实践第八次作业(课堂实战)- 项目UML设计(第五组)
本次作业博客 团队信息 队名:起床一起肝活队 原组长: 白晨曦(101) 原组员: 李麒 (123) 陈德斌(104) 何裕捷(214) 黄培鑫(217) 王焕仁(233) 林志华(128) 乐忠豪( ...
- BOM对象属性定时器的调用
使count中的内容,自动切换 <body> <h1 id="count"></h1> </body> //获取count var ...
- Java实现的词频统计——单元测试
前言:本次测试过程中发现了几个未知字符,这里将其转化为十六进制码对其加以区分. 1)保存统计结果的Result文件中显示如图: 2)将其复制到eclipse环境下的切分方法StringTokenize ...