HDU 5055Bob and math problem(构造)
来源:互联网 发布:windws10固态硬盘优化 编辑:程序博客网 时间:2024/05/01 20:24
无法输出的情况稍微难处理
其他的只要贪心构造一下就好了
#include<iostream>#include<cstdio>#include<set>#include<string>#include<string.h>#include<cstring>#include<vector>#include<map>#include<queue>#include<stack>#include<cctype>#include<algorithm>#include<sstream>#include<utility>#include<cmath>#include<functional>#define mt(a) memset(a,0,sizeof (a))#define fl(a,b,c) fill(a,b,c)#define SWAP(a,b,t) (t=a,a=b,b=t)#define inf 1000000000+7using namespace std;typedef long long ll;int main(){int n;while (cin >> n){int a[10] = { 0 };int odd = 0;for (int i = 0; i < n; i++){int x;cin >> x;a[x]++;if (x & 1)odd++;}if (odd == 0){ printf("-1\n"); continue; }if (n - odd - a[0] == 0 && odd == 1&&a[0]!=0){ printf("-1\n"); continue; }char ans[130] = { 0 };for (int i = 0; i < 10; i++){if (a[i] && (i & 1)){ ans[n - 1] = (char)(i + '0'); a[i]--; break; }}for (int i = 0; i <n-1; i++){for (int j = 9; j >=0; j--){if (a[j]>0){ans[i] = (char)(j + '0');a[j]--;break;}}}printf("%s\n", ans);}return 0;}
0 0
- HDU 5055Bob and math problem(构造)
- HDU 5055 Bob and math problem(构造)
- HDU 5055 Bob and math problem
- hdu 5055 Bob and math problem
- HDU 5055 Bob and math problem
- [5055]Bob and math problem(hdu)
- hdu--5055 Bob and math problem
- HDU 5055 Bob and math problem 数学题
- hdu 5055 Bob and math problem
- HDU 5055 Bob and math problem
- HDU 5055 Bob and math problem
- HDU 5055 - Bob and math problem(贪心)
- HDU —— 5055 Bob and math problem
- HDU-#5055 Bob and math problem(模拟)
- hdu 5055 Bob and math problem(模拟)
- 【BestCoder】 HDOJ 5055 Bob and math problem
- HDOJ 5055 Bob and math problem
- HDU 5055 Bob and math problem(贪心)——BestCoder Round #11(div.2)
- nyoj119 士兵杀敌(三) (线段树,两个value)
- Spring进阶之路(4)-容器中Bean作用域与集合类型配置
- Android应用程序性能优化
- Java服务器热部署的实现原理——java类的加载方式
- 内存管理
- HDU 5055Bob and math problem(构造)
- 利用VS2013编译C语言程序
- 求最大连续bit数
- grep使用多个查询条件--或
- 配置防火墙
- UI 开关按键
- POJ 1007 DNA Sorting(简单排序)
- Android持久化技术——文件存储
- 对于自己第一天写博客的展望与期许