Uva 10344 - 23 out of 5
2013-04-26 22:10
369 查看
Problem I 23 Out of 5
Input: standard inputOutput: standard output
Time Limit: 1 secondMemory Limit: 32 MB
这几天做的都是水题,这题也不例外,其实也不要说是水题,如果排列不是靠next_permination,那么也不会这么清楚地做出来,暴力求解生成23点是比较简单,题目的意思就不要多去纠结,只要按顺序计算就是了
Input: standard inputOutput: standard output
Time Limit: 1 secondMemory Limit: 32 MB
这几天做的都是水题,这题也不例外,其实也不要说是水题,如果排列不是靠next_permination,那么也不会这么清楚地做出来,暴力求解生成23点是比较简单,题目的意思就不要多去纠结,只要按顺序计算就是了
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int digit[6]; int ans = 0; void Traverse(int cur, int sum) { if(cur > 5) { if(sum == 23) ans = 1; return; } else { Traverse(cur+1, sum*digit[cur]); Traverse(cur+1, sum+digit[cur]); Traverse(cur+1, sum-digit[cur]); return; } } int main() { while(1) { int flag, i; for(flag=i=0; i<5; ++i) { scanf("%d", &digit[i]); if(digit[i] != 0) flag = 1; } if(!flag) break; sort(digit, digit+5); ans = 0; do { Traverse(1, digit[0]); }while(next_permutation(digit, digit+5)); if(ans) printf("Possible\n"); else printf("Impossible\n"); } return 0; }
相关文章推荐
- UVA - 10344 23 out of 5(回溯+全排列)
- UVA - 10344 23 out of 5
- uva 10344 23 out of 5
- UVa 10344 23 out of 5
- UVA - 10344 23 out of 5
- UVa 10344 - 23 out of 5, 智力小游戏:算23点
- UVa:10344 23 out of 5
- uva 10344 - 23 out of 5
- uva10344 - 23 out of 5
- uva 10344 - 23 out of 5
- uva10344 - 23 out of 5
- UVA - 10344 - 23 out of 5 (暴力)
- uva 10344 23 out of 5
- uva 10344 23 Out of 5
- UVa 10344 23 out of 5 (全排列枚举&回溯)
- UVA 10344- 23 out of 5
- [回溯]23 out of 5 UVA 10344
- uva-10344 - 23 out of 5
- uva 10344 23 out of 5(DFS)
- UVA 10344 - 23 out of 5