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
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
贪心
代码:
1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 #include<functional>
5 #include<iostream>
6 using namespace std;
7 int str[120];
8 int main()
9 {
10 int n,i,res;
11 while(scanf("%d",&n)!=EOF)
12 {
13 res=10;
14 for(i=0;i<n;i++)
15 {
16 scanf("%d",&str[i]);
17 if(str[i]&1==1&&res>str[i])
18 res=str[i];
19 }
20 if(res==10){
21 printf("-1n");
22 continue;
23 }
24 sort(str,str+n,greater<int>());
25 int fir=-1,st=res;
26 for(i=0;i<n;i++)
27 {
28 if(res==str[i]) res=-1;
29 else
30 {
31 fir=str[i];
32 break;
33 }
34 }
35 if(fir==0) printf("-1n");
36 else
37 {
38 if(fir!=-1)
39 printf("%d",fir);
40 for( i++; i<n;i++)
41 if(res==str[i])res=-1;
42 else
43 printf("%d",str[i]);
44 printf("%dn",st);
45 }
46 }
47 return 0;
48 }
- centos7.2部署vnc服务记录
- nginx访问报错:Too many open files accept:
- iptables之NAT端口转发设置
- 使用Combres 库 ASP.NET 网站优化
- jQuery和asp.net mvc相关资源链接
- JavaScriptSerializer 序列化json 时间格式
- Nginx反向代理+负载均衡简单实现(https方式)
- 在网页中给Flash加上超级链接
- ASP.NET MVC HandleErrorAttribute 和 远程链接
- javascript实现数字转大写金额的函数
- 如何在GridView的Footer内显示总计?
- 自定义WCF的配置文件
- Centos中动态扩容lvm逻辑卷的操作记录
- Visual Round Trip Analyzer
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 克隆图
- LeetCode 03无重复字符的最长子串(滑动窗口)
- elasticSearch学习(五)
- MySQL进阶:索引与优化
- CentOS7搭建Zabbix4.2系统
- vue项目更换favicon.ico
- 一种O(n)的排序——计数排序引发的围观风波
- LeetCode 04寻找两个正序数组的中位数(困难)二分法
- Java程序员面试必备:Volatile全方位解析
- HTTP协议基础及发展历史
- Vi 和 Vim 的使用
- k8s删除Terminating状态的命名空间
- CentOS7下vsftpd over SSL/TLS加密传输配置实践
- Xargs Sh -c Skipping the First Argument
- Centos系统安装