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 ...
随机推荐
- redis 批量删除操作
redis 批量删除操作 需要在redis里面清空一批数据,redis没有支持通配符删除, 只有del key1 key2 ... 但是可以通配符获取 KEYS PATTERN 然后利用linux管道 ...
- Teaching Machines to Understand Us 让机器理解我们 之三 自然语言学习及深度学习的信仰
Language learning 自然语言学习 Facebook’s New York office is a three-minute stroll up Broadway from LeCun’ ...
- JAVA学习笔记--接口
一.抽象类和抽象方法 在谈论接口之前,我们先了解一下抽象类和抽象方法.我们知道,在继承结构中,越往下继承,类会变得越来越明确和具体,而往上回溯,越往上,类会变得越抽象和通用.我们有时候可能会需要这样一 ...
- 《英文版c++语言程序设计》
compatibility [kəm,pætɪ'bɪlɪtɪ] n.兼容 compatible [kəm'pætɪb(ə)l] adj. 兼容的:能共处的:可并立的 interdependent [ɪ ...
- PHP 函数总结
感觉对函数了解的不够深,从头到尾梳理一遍(更新中....) 1,class_exists(),interface_exists(),method_exists(),get_class(),get_pa ...
- 寒假作业2——Pintia小作业及编程题
编程题(电梯) Click to Github 听华一大大说可以用回溯算法,熟练运用搜索引擎的我就百度了一下,琢磨了很多天以为自己会了,真的看到题目还是一脸懵逼(#`-_ゝ-) ...
- P4语法(5) Package
Package 对于package这个概念,类似于将一个框架中各组成部件以一个规律进行打包,以正常运转. 基于一个架构去编写一个新的pipeline的时候,需要先了解初始化的时候需要提供那些东西,pa ...
- Rsyslog-legacy(旧版本语法)配置说明及举例
1. RULES-书写规则 格式:日志设备(类型).日志级别 日志处理方式 (1)日志类型分类 auth pam产生的日志 authpriv ssh,ftp等登录信息的验证信息 ...
- 技嘉主板+AMD CPU开启CPU虚拟化方法
硬件环境:技嘉AB350+AMD Ryzen 5 1600X 由于安装虚拟机的需要,所以要开启CPU的虚拟化. 首先进入BIOS. 然后如图:(M.I.T-高级频率设定-CPU超频进阶设置-SVM M ...
- Windows下基于http的git服务器搭建-gitstack
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Windows下基于http的git服务器搭建-gitstack 本文地址:http: ...