首先能被2,5整除的数结尾必须是0;

如果没有0肯定不行;

然后判断他们的和ans%3:

如果==0,直接从大到小输出就行;

如果==1,要么删除它们之间最小的那个%3==1的,要么删除两个小的并且%3==2的;

如果==2,要么删除它们之中最小的那个%2==2的,要么删除两个小的并且%3==1的;

代码:

 #include<iostream>
using namespace std;
int n,d[],a,u;
main()
{
cin>>n;
while(n--)cin>>a,++d[a],u+=a;
if(u%)
{
for(int i=; i<; ++i)
if(i%==u% && d[i])
--d[i],u-=i,i=;
for(n=; n<; ++n)
for(int i=; i<; ++i)
if(u%&&i%&&d[i])
--d[i],u-=i,i=;
}
if(!u)d[]=;
if(!d[]||u%)cout<<-;
else
for(int i=; i>=; --i)
while(d[i]--)
cout<<i;
return ;
}

Codeforces Round #131 (Div. 2) : B的更多相关文章

  1. Codeforces Round #131 (Div. 1) B. Numbers dp

    题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...

  2. Codeforces Round #131 (Div. 2) B. Hometask dp

    题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...

  3. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  4. Codeforces Round #131 (Div. 2)

    A. System of Equations \(a\)的范围在\(\sqrt n\)内,所以暴力枚举即可. B. Hometask 需要被2.5整除,所以末位必然为0,如果0没有出现,则直接返回-1 ...

  5. Codeforces Round #131 (Div. 1) A - Game

    A. Game time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. Windows 下启动Apache服务(转)

    Win下apache出现问题:“No services installed”安装完apache之后(不是按照默认路径安装的,我的是 D:\ )右下方那个小羽毛图标是没有启动的,左键不好使,而且提示“N ...

  2. 通过strace 监控 fdatasync

    通过strace 监控 Redis AOF文件的系统调用 Redis中主要的AOF设置 「appendonly yes」 开启每次更新操作后进行日志记录 「appendfilename appendo ...

  3. UNIX环境高级编程---标准I/O库

    前言:我想大家学习C语言接触过的第一个函数应该是printf,但是我们真正理解它了吗?最近看Linux以及网络编程这块,我觉得I/O这块很难理解.以前从来没认识到Unix I/O和C标准库I/O函数压 ...

  4. hadoop错误ERROR namenode.NameNode (NameNode.javamain(1657)) - Failed to start namenode java.net.BindException:Port in use:host1:50070

    解决方法: 1.通过lsof -i:50070(lsof可以通过yum install lsof安装)查看,发现是mysql被占用了 2.修改mysql端口 从/usr/share/mysql/my- ...

  5. SVN/GIT源代码泄露

    造成SVN源代码漏洞的主要原因是管理员操作不规范.在使用SVN管理本地代码过程中,会自动生成一个名为.svn的隐藏文件夹,其中包含重要的源代码信息.但一些网站管理员在发布代码时,不愿意使用‘导出’功能 ...

  6. java 数组注意点

    int[] array1 = new int[4]; int[] array2 = new int[6]; int[] array3 = new int[8]; array2 = array1; ar ...

  7. ASP.NET操作DataTable

    .创建 datatable DataTable dt=new Datable();//可以给表创建一个名字,tb .给表加个列名: dt.Columns.Add("id", typ ...

  8. checkbox复选框

    改变checkbox状态 所有的jquery版本都可以这样赋值:// $("#cb1").attr("checked","checked") ...

  9. CSS中Position属性

    也许你看到这个标题觉得很简单,确实这是一篇关于CSS中Position属性基础知识的文章,但是关于Position的一些细节也许你不了解. 1.简介 position有五个属性: static | r ...

  10. js--小结②