hdu----(5055)Bob and math problem(贪心)
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
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".
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 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.
0 1 3
3
5 4 2
3
2 4 6
425
-1
#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(贪心)的更多相关文章
- HDU 5055 Bob and math problem(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
- HDU 5055 Bob and math problem(简单贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的 ...
- hdu 5055 Bob and math problem (很简单贪心)
给N个数字(0-9),让你组成一个数. 要求:1.这个数是奇数 2.这个数没有前导0 问这个数最大是多少. 思路&解法: N个数字从大到小排序,将最小的奇数与最后一位交换,把剩下前N-1位从大 ...
- hdu 5055 Bob and math problem
先把各个数字又大到小排列,如果没有前导零并且为奇数,则直接输出.如果有前导零,则输出-1.此外,如果尾数为偶数,则从后向前找到第一个奇数,并把其后面的数一次向前移动,并把该奇数放到尾部. 值得注意的是 ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
- 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 ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 5615 Jam's math problem
Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
随机推荐
- 【转载】ADO,OLEDB,ODBC,DAO的区别
原文:ADO,OLEDB,ODBC,DAO的区别 ODBC(Open Database Connectivity,开放数据库互连) 1992年,微软公司开放服务结构(WOSA,Windows Open ...
- 【转载】linux内核笔记之进程地址空间
原文:linux内核笔记之进程地址空间 进程的地址空间由允许进程使用的全部线性地址组成,在32位系统中为0~3GB,每个进程看到的线性地址集合是不同的. 内核通过线性区的资源(数据结构)来表示线性地址 ...
- Android 杂记 - 存货盘点用的客户端
最近有个盘点用的东西,要放到移动设备,本来用 .Net Compact Framework,CAB 部署在 CE 系统的移动条码设备.技术太旧,我用了这个周末两天时间,把这东西在试试实现在安卓上面,给 ...
- [SAP ABAP开发技术总结]SD销售订单定价过程
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- SQL疑难杂症【2】解决SQL订阅过程中找不到已经创建的订阅
之前有写过一篇博客,主要是图解SQL复制技术:图解SQL 2008数据库复制,当时的测试环境是在我本地同一个服务器上面,所以测试的时候可谓是一帆风顺,最近公司要做一个数据同步的事物,所以再次在不同的服 ...
- php获取在线xml的数据
因为连接百度地图的API,然后通过经纬度得到位置信息,可是得到的位置信息是通过将经纬度嵌在url里面,生成xml文件后,因为是在线的,当时就想到在不下载的情况下获取里面的数据,因为使用代码下载是可以下 ...
- iOS - OC NSTimeZone 时区
前言 @interface NSTimeZone : NSObject <NSCopying, NSSecureCoding> NSTimeZone 表示时区信息. 1.NSTimeZon ...
- Oracle存储过程中异步调用的实际操作步骤
本文标签:Oracle存储过程 我们都知道在Oracle数据库的实际应用的过程中,我们经常把相关的业务处理逻辑,放在Oracle存储过程中,客户端以通过ADO来进行相关的调用 .而有些相关的业务逻辑 ...
- Poco C++——JSON解析
#include <iostream> #include "Poco/Dynamic/Var.h" #include "Poco/Dynamic/Pair.h ...
- php PDO链接SQL SERVER
操作系统Windows7 apache 2.2 php php-5.4.45-Win32-VC9-x86 sqlserver 2008 下载SQLSRV32 https://www.microsoft ...