URAL 1014 Product of Digits
URAL_1014
基本的贪心思路是留下尽量少的项,而且这些项的字典序尽可能小。因此,要优先生成8,然后优先生成9,6,4,最后生成质数。至于为什么先生成9,再生成6,再生成4,这个可以将2、3的个数分奇偶讨论一下就很清楚了。
此外还有一些细节需要注意,比如N=1的时候输出1,N=0的时候输出10。
#include<stdio.h> #include<string.h> int N, h[15]; void solve() {int i;memset(h, 0, sizeof(h));while(N % 8 == 0)++ h[8], N /= 8;while(N % 9 == 0)++ h[9], N /= 9;while(N % 6 == 0)++ h[6], N /= 6;while(N % 4 == 0)++ h[4], N /= 4;for(i = 2; i < 8; i ++)while(N % i == 0)++ h[i], N /= i;if(N != 1)printf("-1");else{for(i = 2; i < 10; i ++)while(h[i])printf("%d", i), -- h[i];}printf("\n"); } int main() {while(scanf("%d", &N) == 1){if(N == 0)printf("10\n");else if(N == 1)printf("%d\n", N);elsesolve();}return 0; }
转载于:https://www.cnblogs.com/staginner/archive/2012/05/01/2477541.html
URAL 1014 Product of Digits相关推荐
- ural 1014. Product of Digits
1014. Product of Digits Time Limit: 1.0 second Memory Limit: 64 MB Your task is to find the minimal ...
- pku,zju题目分类
哎呦喂,直接ctrl+A了.话说浙江大学的题还见过的呢.. 公告: [意见反馈][官方博客] ural pku Zju 题目分类 收藏 感谢 mugu 的提供.... Ural Problem ...
- TYUT-A专题题解(一)
TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...
- Competitive Programming 3题解
题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...
- AOAPC I: Beginning Algorithm Contests 题解
AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...
- ACM程序设计基础题解
ACM水题一 HDU1262 寻找素数对[素数] - 海岛Blog - CSDN博客 HDU4548 美素数[水题] - 海岛Blog - CSDN博客 HDU2503 a/b + c/d[水题] - ...
- ACM程序设计基础(2)题解
ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》
第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...
最新文章
- python入门教程共四本书籍-Python入门书籍有哪些?
- python 网关配置界面代码_Linux下使用python自动修改本机网关代码分享
- diskgenius扩容c盘重启电脑卡住_电脑使用DiskGenius工具增加C盘空间的方法
- 区块链培训资料(特别是以太坊)
- JVM学习笔记之-JVM性能监控-JVM监控及诊断工具-GUI方式-Visual VM-JProfiler-Arthas
- vue和小程序哪个好学一点_litemall,Spring Boot后端,微信小程序用户前端 + Vue用户移动端...
- 数据库名,全局数据库名,SID区别及有感
- Djanog结合jquery实现ajax
- 无法启用数据库中的 Service Broker,因为已存在启用的具有相同 ID 的 Service Broker。...
- Java项目演示第23期在线购书商城系统
- 重磅!腾讯正式开源 Spring Cloud Tencent
- html 栏目切换幻灯片效果,JS实现的幻灯片切换显示效果
- android系统解锁,android 调用系统解锁方法
- js可以用的万年历API
- SCDPM2019服务器恢复数据
- 我的IOS端SIP电话开发历程
- 端午福福福福福福福福福福福福福福福福利
- python全栈是什么
- 供应链金融的三种模式分析
- Python爬虫初学:报错1:UnicodeEncodeError: 'gbk' codec can't encode character '\xbb'……
热门文章
- 用 ArrayList 还是 LinkedList?
- 有点长的 Java API 设计清单
- 关系数据库是如何工作的
- Android --- 怎么去掉小数后面不必要的 0
- 单模光电转换器怎么接_行业观察 | 硅基光电子与微电子单片集成研究进展
- android 上滑隐藏view,Android CoordinatorLayout + AppBarLayout(向上滚动隐藏指定的View)
- 语言用加法实现加饭运算_「编程之美」用C语言实现状态机(超实用)
- 数据中心水环热泵余热回收系统分析与应用
- 数据中心用多模光纤技术及发展趋势
- Dataset之LSUN:LSUN数据集的下载使用教程