hdu 5055(坑)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055
Bob and math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 695 Accepted Submission(s): 263
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)$.
思路:这题有点略坑~思路挺简单,但是细心才能AC,
直接将n个数排序,然后找最小的奇数移出即可;
PS:(1)要注意n==1的情况
(2)You need to use this N Digits to constitute an Integer.
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <cmath>
const int INF=99999999;
#include <algorithm>
using namespace std;int a[110];
bool cmp(int a,int b)
{return a>b;
}
int main()
{int n;while(cin>>n){for(int i=1;i<=n;i++){cin>>a[i];}if(n==1){if(a[1]&1)cout<<a[1]<<endl;elsecout<<-1<<endl;continue;}sort(a+1,a+1+n,cmp);int flag=INF;for(int i=n;i>=1;i--){if(a[i]&1){flag=i;break;}}if(flag==INF){cout<<-1<<endl;continue;}if(flag==1&&a[2]==0){cout<<-1<<endl;continue;}for(int i=1;i<=n;i++){if(i!=flag)cout<<a[i];}cout<<a[flag]<<endl;}return 0;
}
hdu 5055(坑)相关推荐
- hdu 5055(贪心)
题意:给你N个数,每个数的取值范围为[0,9],求这N个数组成的最大奇数,且该奇数不能有前导零. 解题思路:将偶数和奇数分开,然后分别按从小到大排序,将最小的奇数先拿出来,把剩余的数从大到小排好,最后 ...
- HDU 5055 Bob and math problem(构造)
无法输出的情况稍微难处理 其他的只要贪心构造一下就好了 #include<iostream> #include<cstdio> #include<set> #inc ...
- 程序员用学位证吗_如何成为没有学位或新兵训练的开发人员
程序员用学位证吗 Preface: This post is geared towards people interested in being self-taught because boot-ca ...
- HDU 2549 壮志难酬 (水题,但有个小坑!)
壮志难酬 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- hdu 4738 无向图缩点断桥 // 细节坑题
Caocao's Bridges 题意:给个无向图,求出边权最小的桥. 一看,直接缩点,若无桥,输出-1,有桥,遍历下边,更新最小..分分钟搞定,以为IA的..一交wa... 坑点:1:若原图不连通, ...
- HDU 2092 算菜价(结束条件,坑呀!)
算菜价 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 4279 占坑先。。。
RT... 转载于:https://www.cnblogs.com/fakeAcmer/archive/2012/10/18/2729981.html
- hdu 2879【留坑】
看了题解,说的都不太准确,可能是积性函数是为莫比乌斯准备的吧,莫比乌斯真的难 #include <bits/stdc++.h> using namespace std; typedef l ...
- 【HDU - 5468】Puzzled Elena(容斥原理,dfs序,数学,素因子分解,有坑)
题干: Problem Description Since both Stefan and Damon fell in love with Elena, and it was really diffi ...
最新文章
- tomcat苹果版安装步骤_Mac系统安装和配置tomcat步骤详解
- 如果成为一名高级安卓开发_什么是高级开发人员,我如何成为一名开发人员?
- Java 多线程 之 suspend挂起 线程实例
- 腾讯offer是什么样子_记一次腾讯社招前端面试(已拿到offer入职)
- flex 3 使用手册
- Linux高效数据统计命令wc
- 【电影】美丽心灵的永恒阳光
- Spotify模式并非“敏捷涅磐”
- 字节面试官:如何实现Ajax并发请求控制
- python基本语法:序列
- 职称计算机技巧集锦,2014职称计算机考试《Excel》使用技巧集锦(4)
- signature=fa342ee2b7c3e3e9cba3f194df2d59ca,Date of Signature
- java 求向量的均值,标准数组——向量
- 微信小程序在地图上标点 markers 画圈显示范围 circles
- 命令查询职责分离模式 CQRS Command Query Responsibility Segregation
- 炼油化工常用英文缩写
- 数字科技陪伴企业成长|突破封锁,庚顿数据助力中国名牌全球瞩目
- star测试软件,PSTAR准备
- CDATA 数据处理
- Linux下Socket编程之TCP原理