hdu 5055 Bob and math problem
2015-02-06 20:09
323 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5055
思路:贪心,先排序,然后找到一个奇数与最后以为交换,然后把前n-1位从大到小排序,看看是否符合。
View Code
思路:贪心,先排序,然后找到一个奇数与最后以为交换,然后把前n-1位从大到小排序,看看是否符合。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n; int a[10000]; bool cmp(int a,int b) { return a>b; } int main() { while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); bool flag=false; for(int i=1; i<=n; i++) { scanf("%d",&a[i]); if(a[i]%2) { flag=true; } } if(!flag) { printf("-1\n"); } else { sort(a+1,a+n+1,cmp); for(int i=n; i>=1; i--) { if(a[i]%2) { swap(a[i],a ); break; } } sort(a+1,a+n,cmp); int j=1; while(a[j]==0) { j++; } if(j>1) { printf("-1\n"); continue; } for(int i=j; i<=n; i++) { printf("%d",a[i]); } printf("\n"); } } return 0; }
View Code
相关文章推荐
- hdu 5055 Bob and math problem
- hdu5055——Bob and math problem
- HDU 5055 Bob and math problem(贪心)——BestCoder Round #11(div.2)
- 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
- [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(构造)
- 【CUGBACM15级BC第11场 B】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(贪心)