A. Jeff and Digits(cf)
1 second
256 megabytes
standard input
standard output
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
4
5 0 5 0
0
11
5 5 5 5 5 5 5 5 0 5 5
5555555550
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int n,x;
while(~scanf("%d",&n))
{
int cnt5 = ,cnt0 = ,max = ;
while(n--)
{
scanf("%d",&x);
if (x==)
cnt5++;
else
cnt0++;
if(cnt5%==&&cnt5)//能被9整除的数其各位数之和是9的倍数,故5的个数应是9的倍数
{
if (cnt5 > max)
max = cnt5;
}
}
if (cnt0==)//能被90整除的数末尾必含0
puts("-1");
else if (!max)//若5的个数小于9个且cnt0!=0,则最大的数为0
puts("");
else
{
while(max--)
cout<<"";
while(cnt0--)
cout<<"";
puts("");
} }
return ;
}
A. Jeff and Digits(cf)的更多相关文章
- cf A. Jeff and Digits
http://codeforces.com/contest/352/problem/A #include <cstdio> #include <cstring> #includ ...
- CF352A Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and ...
- B. Jeff and Periods(cf)
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 『题解』Coderforces352A Jeff and Digits
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Jeff's got n cards, each card contains ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
- Codeforces Round #204 (Div. 2) A.Jeff and Digits
因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
随机推荐
- HDU_5723_最小生成树+任意两点距离的期望
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- TCP报文到达确认(ACK)机制
TCP数据包中的序列号(Sequence Number)不是以报文段来进行编号的,而是将连接生存周期内传输的所有数据当作一个字节流,序列号就是整个字节流中每个字节的编号.一个TCP数据包中包含多个字节 ...
- C# 获得 当年1月1号
//默认当年1月1号 ViewBag.time1 = , ).ToString("yyyy-MM-dd"); ViewBag.time2 = DateTime.Now.ToStri ...
- u-boot常用命令
查看ip地址等信息 print tftp相关 设置ip地址 set ipaddr 192.168.1.5 设置tftp所在电脑ip set serverip 192.168.1.8 最后必须输入sav ...
- ImageMagick的下载和配置
2. 新建一个VC++的工程,项目->属性 VC++目录中 包含目录中加入4项,ImageMagick安装路径下的include文件夹,和include里边的三个文件夹. 库目录中加入1项,Im ...
- pandas.DataFrame.quantile
pandas.DataFrame.quantile 用于返回数据中的 处于1/5 1/2(中位数)等数据
- python爬虫20 | 小帅b教你如何使用python识别图片验证码
当你在爬取某些网站的时候 对于你的一些频繁请求 对方会阻碍你 常见的方式就是使用验证码 验证码的主要功能 就是区分你是人还是鬼(机器人) 人 想法设法的搞一些手段来对付技术 而 技术又能对付人们的想法 ...
- vs2015 配置 cplex
首先设置模式为Release, 根据软件选择x86或x64 附加库目录(链接器 - 常规) C:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\lib\x6 ...
- 【5】Django项目配置settings.py详解
夫唯不争,故天下莫能与之争 --老子<道德经> 本节内容 1.项目配置文件settings.py介绍 2.数据库配置[MySQL] 3.创建模型对象并和数据库同步 4.python官方提供 ...
- 【郑轻邀请赛 H】 维克兹的进制转换
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2134 [题意] [题解] 设f[i]表示数字i分解为二进制数的方案数; 则 如果i为 ...