51nod 1433 0和5
来源:互联网 发布:宝宝取名软件 破解 编辑:程序博客网 时间:2024/05/17 04:10
小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5。小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数。使得这个数尽可能大,而且可以被90整除。
注意:
1.这个数没有前导0,
2.小K不需要使用所有的牌。
Input
每个测试数据输入共2行。
第一行给出一个n,表示n张牌。(1<=n<=1000)
第二行给出n个整数a[0],a[1],a[2],…,a[n-1] (a[i]是0或5 ) 表示牌上的数字。
Output
共一行,表示由所给牌组成的可以被90整除的最大的数,如果没有答案则输出”-1”(没有引号)
Input示例
4
5 0 5 0
Output示例
0
思路:
先打了下表,发现只要5的个数是9倍数就可以被9整除,(其实只要各位数字相加是9的倍数就能被9整除,和3一个道理),然后题目要求被90,所以一定要有个0,没有0则-1.
最大的话把5全放前面就好了。
#include<cstring>#include<string>#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#include<queue>#include<vector>#include<map>#include<stack>#include<climits>#include<bitset>#include<set>using namespace std;#define mod 1000000007#define PI acos(-1.0)#define INF 0x3f3f3f3ftypedef long long LL;int main(){ int n,t; int a,b; a=b=0; scanf("%d",&n); while(n--){ scanf("%d",&t); if(t==0)a++; else b++; } if(a==0)cout<<-1<<endl; else { if(b<9){ cout<<0<<endl; } else { for(int i=0;i<9*(b/9);i++){ cout<<5; } for(int i=0;i<a;i++){ cout<<0; } cout<<endl; } } return 0;}
0 0
- 51nod 1433:0和5
- 51nod 1433 0和5
- 51nod----1433 0和5
- 51nod 1433 0和5
- 51nod 1433 0和5
- 51nod-【1433 0和5】
- 51nod-1433 0和5
- 51Nod 1433 0和5
- 51nod 1433 0和5
- 51nod 1433 0和5
- 【51Nod】1433 0和5
- 51nod 1433 0和5
- 51nod 1433 0和5
- 51nod 1433 0和5
- 51nod 1433 0和5
- 0和5 51Nod-1433
- 51Nod 1433 0和5 倍数
- 51nod 0 和 5
- node.js学习笔记(4)_极客学院_MongoDB的使用
- 联想System X 3650M5 服务器装机问题记录
- 小米智能家居之Yeelight智能灯开放API开发尝试
- Centos7与Fedora24安装mysql后无法启动,提示 Unit mysql.service failed to load:No such file or directory
- Word不能切换输入法,只能输入英文怎么办?
- 51nod 1433 0和5
- 懂得尊重别人,才值得别人尊重
- ScheduledExecutorService概念
- 使用消息队列的理由总结
- 深度学习UFLDL教程翻译之BP算法
- At Commands:从白痴到大师的修炼历程(一)
- MxNet : use the MxNet windows versioin
- 眼睛区域提取研究
- 注解方式配置Spring实现Ioc