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; }