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的更多相关文章

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

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

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

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

  3. hdu 5055(坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...

  4. hdu 5055 Bob and math problem

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

  5. hdu 5055(模拟)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

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

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

  7. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. linux 使用笔记3

    解决linux下打开txt乱码问题 在Linux下要阅读windows生成的txt文件,需要通过iconv进行字符转化 iconv -f gb2312 -t utf8 ./读书笔记.txt > ...

  2. 3DES加密及.NET弱密钥处理

    背景 智能pos机开发项目需要指定Key加密某些关键字符串.商定采用3DES加密算法. 实践 网海中很多.NET C#编写3DES加密的函数.采集一段简明.成熟的代码,归置于常用程序集.但当指定Key ...

  3. IOS初级:UIAlertController

    - (IBAction)signOutAction:(id)sender { //初始化,StyleActionSheet是对话框的样式 UIAlertController *alert = [UIA ...

  4. python+selenium—webdriver入门(一)

    一.浏览器最大化 二.设置浏览器分辨率大小 三.打印页面title 四.打印URL 五.控制浏览器前进或后退 #!/usr/bin/env python#-*- coding:utf-8 -*- fr ...

  5. 【RabbitMQ】 RabbitMQ配置开机启动

    环境 系统:Linux(CentOS 7.2) Erlang环境:21.1(安装参考[Erlang]源码安装) RabbitMQ:3.7.9(安装参考[RabbitMQ] RabbitMQ安装) 配置 ...

  6. 【Go】 Go 语言环境安装

    安装环境/工具 1.Linux(CentOS 7.4版) 2.go1.11.2.linux-amd64.tar Go 语言环境安装 1.下载安装包 安装包下载地址为:https://golang.or ...

  7. day05作业---字典

    # 字典找位置 用键, 列表.元组找位置 用索引'''1.有如下变量(tu是个元祖),请实现要求的功能tu = ("alex", [11, 22, {"k1": ...

  8. 关于oracle的锁表解决session marked for kill

    oracle 使用的过程中,有时候会遇到锁表的情况,数据库增.删.改.查都是会锁表的,但是锁的类型会不同, 大多是行锁,部分会是表锁. 在oracle运行中,一直是有表在锁的,只不过很快一个操作结束, ...

  9. HMM(隐马尔可夫模型)不断学习中

    HMM(隐马尔可夫模型)是用来描述隐含未知参数的统计模型,举一个经典的例子:一个东京的朋友每天根据天气{下雨,天晴}决定当天的活动{公园散步,购物,清理房间}中的一种,我每天只能在twitter上看到 ...

  10. 假期训练五(poj-1077bfs+康拓展开,hdu-2577dp)

    题目一:传送门 思路:主要是找到状态, 考虑字母有两种状态,大写和小写, 从小写变为大写的变化方式有两种:保持cap状态,或者按住shift键: 从小写变为大写也有一种变化方式:按住shift键: 看 ...