lucky sum of digit
来源:互联网 发布:6月淘客不计入淘宝权重 编辑:程序博客网 时间:2024/05/17 23:08
A. Lucky Sum of Digits
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.
Input
<p< p="">The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.
Output
<p< p="">Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.
Sample test(s)
<p< p=""><p< p="">input
11
output
47
input
10
output
-1
一开始没想清楚,乱打bfs和dfs,后面想了下 发现DFS和BFS明显不行。。随便一下就会爆掉。
其实构成n的数只有4,7那么直接把最大的4,和7的个数求出来。然后在这里面暴力就可以解决了。然而最小的数肯定是把4放在最前面。
下面是AC代码:
#include<iostream>#include<string>#include<queue>using namespace std;int n,i,j,k,flag,sum;int main(){int s4,s7;cin>>n;s4=n/4; s7=n/7;for(i=0;i<=s4;i++){for(j=0;j<=s7;j++){if(i*4+j*7==n){flag=1;break;}}if(flag) break;}if(!flag)cout<<-1<<endl;else{for(k=1;k<=i;k++)printf("4");for(k=1;k<=j;k++)printf("7");printf("\n");}return 0;}
- lucky sum of digit
- Lucky Sum of Digits
- A. Lucky Sum of Digits
- 1952-Lucky Sum of Digits
- codeforces#84_div2_C Lucky Sum of Digits
- Codeforces 110C Lucky Sum Of Digits 暴力
- EOJ 2568 Sum of digit [2009年研究生机试]
- codeforces Lucky Sum
- CF Lucky Sum
- [projecteuler]Factorial digit sum
- Sicily 7969. Digit Sum
- HDU 5710 Digit-Sum
- HDU 5710 Digit-Sum
- HDU5710-Digit-Sum
- Digit-Sum HDU
- HDU 5710 Digit-Sum
- UVALive6497 Digit Sum【贪心】
- Number of Digit One
- 如何学习java
- poj2452
- POJ1350 Cabric Number Problem [模拟]
- 算法应用
- 纪念为“第九维”而死的脑细胞
- lucky sum of digit
- ★☆【二分圖最佳匹配】丘比特的煩惱
- Redis源代码分析之二:散列表——Dict(上)
- VB工程--百例49--显示文件路径
- CentOS 网络配置
- 用boost asio 获取本地IP遇到"host not found"的问题
- 又在折腾SQL05的安装
- android 启动线程注意的问题
- 整理项目代码