首先能被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. ExecutorService与Executors例子的简单剖析(转)

    对于多线程有了一点了解之后,那么来看看java.lang.concurrent包下面的一些东西.在此之前,我们运行一个线程都是显式调用了 Thread的start()方法.我们用concurrent下 ...

  2. Cocos2d-X中字符串的处理

    CCString 用惯了NSString,你会严重高估自己处理字符串的能力.使用Cocos2d-X后只能用char*或者string来代替.诸如字符串的拼接,替换,查找都比NSString麻烦不少. ...

  3. display_errors & error_reporting(php调试安全)

    这两个选项对应的值即都可以在php.ini文件中设置,也都可以在php代码中使用相应的函数来设置. 在php.ini文件中的设置如下:

  4. Spring AOP体系学习总结:

    二.Spring AOP体系学习总结: 要理解AOP整体的逻辑需要理解一下Advice,Pointcut,Advisor的概念以及他们的关系. Advice是为Spring Bean提供增强逻辑的接口 ...

  5. .NET中的消息队列

    下文参考:http://hi.baidu.com/21tian/blog/item/ce5464097ddf10cb3ac76335.html为何使用消息队列 您可能认为您能够通过一个简单的数据库表( ...

  6. Java5中的线程池实例讲解

    Java5增加了新的类库并发集java.util.concurrent,该类库为并发程序提供了丰富的API多线程编程在Java 5中更加容易,灵活.本文通过一个网络服务器模型,来实践Java5的多线程 ...

  7. rest例子

    http://www.xdemo.org/spring-restful/(可用) http://www.open-open.com/lib/view/open1389075258125.html(有例 ...

  8. jQuery 遍历同胞(siblings)

    同胞拥有相同的父元素. 通过 jQuery,您能够在 DOM 树中遍历元素的同胞元素. 在 DOM 树中水平遍历 有许多有用的方法让我们在 DOM 树进行水平遍历: siblings() next() ...

  9. return、break、continue的区别

    一.定义 return:语句用于终止当前方法运行,返回到调用该方法的语句处.如有返回值,则在return后面提供相应的返回值. break:其主要用于循环语句和switch语句,其作用均是强行终止语句 ...

  10. js keycode大全

    JS KeyCode数字对应键盘以及应用大全   时间:2014-07-11 10:37    点击:851次 keycode    8 = BackSpace BackSpacekeycode    ...