hdu 5055
http://acm.hdu.edu.cn/showproblem.php?pid=5055
n个digit能组合出的最大无前导0奇数
无聊的模拟
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int s[105];
bool vis[105];
void work(int n)
{
clr0(vis);
for(int i = 0;i < n;++i)
RD(s[i]);
sort(s,s+n);
bool flag = false;
int last;
for(int i = 0;i < n;++i){
if(s[i]&1){
vis[i] = true;
flag = true;
last = s[i];
break;
}
}
if(!flag){
puts("-1");
return;
}
if(n == 1){
printf("%d\n",last);
return;
}
flag = false;
for(int i = n-1;i >= 0;--i){
if(!vis[i]){
if(s[i] == 0)
flag = true;
else
flag = false;
break;
}
}
if(flag){
puts("-1");
return;
}
for(int i = n - 1;i >= 0;--i)if(!vis[i]){
printf("%d",s[i]);
}
printf("%d\n",last);
return;
}
int main() {
int n;
while(~RD(n)){
work(n);
}
return 0;
}
hdu 5055的更多相关文章
- 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(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
- hdu 5055(坑)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...
- hdu 5055 Bob and math problem
先把各个数字又大到小排列,如果没有前导零并且为奇数,则直接输出.如果有前导零,则输出-1.此外,如果尾数为偶数,则从后向前找到第一个奇数,并把其后面的数一次向前移动,并把该奇数放到尾部. 值得注意的是 ...
- hdu 5055(模拟)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 5055 Bob and math problem (很简单贪心)
给N个数字(0-9),让你组成一个数. 要求:1.这个数是奇数 2.这个数没有前导0 问这个数最大是多少. 思路&解法: N个数字从大到小排序,将最小的奇数与最后一位交换,把剩下前N-1位从大 ...
- BestCoder Round #11 (Div. 2) 前三题题解
题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- stl中顺序性容器,关联容器两者粗略解释
什么是容器 首先,我们必须理解一下什么是容器,在C++ 中容器被定义为:在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对像的指针,这种对象类型就叫做容器.很简单,容器就是保存其它对象的对象 ...
- spring MVC中Dubbo的配置
1.服务提供方的bubbo配置: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=& ...
- oracle表或视图不存在和标识符无效的问题解决
通过dbvisualizer修改表的名字时,一定要改成大写,否则会报错,数据库中没有该表的错误. 如果新的表名为小写,不行! select的时候,可以用小写名. 标识符无效解决:字段名默认都是大写的, ...
- VirtualBox安装android-x86-4.4-r2
https://jingyan.baidu.com/album/a681b0de1373133b184346cf.html?picindex=10
- python 正则表达式 group() groups()
参考地址: http://www.cnblogs.com/kaituorensheng/archive/2012/08/20/2648209.html
- Max Chunks To Make Sorted LT769
Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into som ...
- IOS初级:NSTimer
@property (nonatomic, strong) NSTimer *timer; 添加定时器 self.timer = [NSTimer scheduledTimerWithTimeInte ...
- SpringMVC学习八 @ResponseBody注解
(一)在方法上只有@RequestMapping 时,无论方法返回值是什么认为需要跳转,代码实例如下 @RequestMapping("demo10") public People ...
- linux安装dpkg安装缺少依赖项的解决
问题: dpkg: error processing package rxvt:i386 (--install): dependency problems - leaving unconfigured ...
- MVCS框架的注意点
1.Service最好用一个接口对应一个service(便于增加扩展方法) 2.除Services和Model外都需继承自各自对应的父类 3.View不要轻易重写Start和Awake方法(含与启动有 ...