Bob and math problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 401    Accepted Submission(s): 149

Problem Description
Recently, Bob has been thinking about a math problem.
There are N Digits, each digit is between 0 and 9. You need to use this N Digits to constitute an Integer.
This Integer needs to satisfy the following conditions:

    • 1. must be an odd Integer.
    • 2. there is no leading zero.
  • 3. find the biggest one which is satisfied 1, 2.

Example:
There are three Digits: 0, 1, 3. It can constitute six number of
Integers. Only "301", "103" is legal, while "130", "310", "013", "031"
is illegal. The biggest one of odd Integer is "301".

 
Input
There are multiple test cases. Please process till EOF.
Each case starts with a line containing an integer N ( 1 <= N <= 100 ).
The second line contains N Digits which indicate the digit $a_1, a_2, a_3, \cdots, a_n. ( 0 \leq a_i \leq 9)$.
 
Output
The
output of each test case of a line. If you can constitute an Integer
which is satisfied above conditions, please output the biggest one.
Otherwise, output "-1" instead.
 
Sample Input
3
0 1 3
3
5 4 2
3
2 4 6
 
Sample Output
301
425
-1
 
Source
 
贪心
代码:
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<iostream>
using namespace std;
int str[];
int main()
{
int n,i,res;
while(scanf("%d",&n)!=EOF)
{
res=;
for(i=;i<n;i++)
{
scanf("%d",&str[i]);
if(str[i]&==&&res>str[i])
res=str[i];
}
if(res==){
printf("-1\n");
continue;
}
sort(str,str+n,greater<int>());
int fir=-,st=res;
for(i=;i<n;i++)
{
if(res==str[i]) res=-;
else
{
fir=str[i];
break;
}
}
if(fir==) printf("-1\n");
else
{
if(fir!=-)
printf("%d",fir);
for( i++; i<n;i++)
if(res==str[i])res=-;
else
printf("%d",str[i]);
printf("%d\n",st);
}
}
return ;
}

hdu----(5055)Bob and math problem(贪心)的更多相关文章

  1. HDU 5055 Bob and math problem(结构体)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...

  2. HDU 5055 Bob and math problem(简单贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的 ...

  3. hdu 5055 Bob and math problem (很简单贪心)

    给N个数字(0-9),让你组成一个数. 要求:1.这个数是奇数 2.这个数没有前导0 问这个数最大是多少. 思路&解法: N个数字从大到小排序,将最小的奇数与最后一位交换,把剩下前N-1位从大 ...

  4. hdu 5055 Bob and math problem

    先把各个数字又大到小排列,如果没有前导零并且为奇数,则直接输出.如果有前导零,则输出-1.此外,如果尾数为偶数,则从后向前找到第一个奇数,并把其后面的数一次向前移动,并把该奇数放到尾部. 值得注意的是 ...

  5. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

  6. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  7. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. HDU 5615 Jam's math problem

    Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...

  9. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

随机推荐

  1. 如何选择正确的DevOps工具

    坦白的讲:世界上没有哪种工具能够像DevOps这么神奇(或敏捷,或精益).DevOps在开发和运营团队之间建立了完美的合作与沟通,因此与其说这是一种神奇的工具,不如说是一种文化的转变. 然而,团队之间 ...

  2. mimikatz2.0抓取WINDOWS密码

    看吾爱的,刚好问同事说这个也用过,以后内网渗透的话比较方便 http://www.52pojie.cn/thread-264895-1-1.html ========================= ...

  3. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  4. hdu 0-1背包

    题目地址http://acm.hdu.edu.cn/showproblem.php?pid=2602 #include <stdio.h> #include <string.h> ...

  5. Singelton单例模式

    单例,相当于一个全局变量,在整个应用程序中保证只有一个类的实例存在. 线程池.数据库连接池.缓存.日志等对象常被设计成单例 实例: 1.懒汉式单例 /** * 懒汉式单例Singelton:是一种创建 ...

  6. HTML笔记(六)文档类型

    <!DOCTYPE>声明帮助浏览器正确显示网页.一般放在页面的最前面. DTD是Document Type Definition的缩写,是一套关于标记符的语法规则,是一种文档验证机制. H ...

  7. 杭电1466------简单的dp

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=1466 #include<iostream> #include<cstdio> # ...

  8. FLASH CC 2015 CANVAS 导出音频问题

    1,导入音频无法成功发布(软件假死) 解决办法:先用个格式工厂重新压缩 在导入软件 发布 2, 音频 长度小于1秒(左右)的时候,导出后音频会变成  “哧”的一声,  估计和FLASH软件内部的音频编 ...

  9. iOS - OC RunLoop 运行循环/消息循环

    1.RunLoop 1)运行循环: 运行循环在 iOS 开发中几乎不用,但是概念的理解却非常重要. 同一个方法中的代码一般都在同一个运行循环中执行,运行循环监听 UI 界面的修改事件,待本次运行循环结 ...

  10. Java中正则Matcher类的matches()、lookAt()和find()的区别<转>

    在Matcher类中有matches.lookingAt和find都是匹配目标的方法,但容易混淆,整理它们的区别如下: matches:整个匹配,只有整个字符序列完全匹配成功,才返回True,否则返回 ...