UVA1034423 out of 5
来源:互联网 发布:怎样在淘宝网卖闲置品 编辑:程序博客网 时间:2024/06/17 01:55
UVA-10344
题意:求(((((a1 o a2) o a3)o a4 )o a5),其中o的选择范围{+,- ,*},a1-a5由给定的5个数中任意顺序。看能不能使得结果为23。
解题思路:先枚举a1-a5的顺序(STL 里的 next_permutation 简直强大),然后再枚举每个o选+-*中的哪一个。
/************************************************************************* > File Name: UVA-10344.cpp > Author: Narsh > > Created Time: 2016年07月27日 星期三 14时52分46秒 ************************************************************************/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int temp[9],num[9],flag;void dfs(int i,int res) { if (i > 5) { if (res == 23) flag = 1; return ; } dfs(i+1,res-num[i]); dfs(i+1,res+num[i]); dfs(i+1,res*num[i]);}int main() { while (true) { flag = 0; for (int i = 1; i <= 5;i++) { scanf("%d",&num[i]); flag += num[i]; } if (flag == 0) break; flag=0; sort(num+1,num+6); do { dfs(2,num[1]); if (flag) break; }while (next_permutation(num+1,num+6)); if (flag) printf("Possible\n"); else printf("Impossible\n"); }}
0 0
- UVA1034423 out of 5
- 23 Out of 5
- 10344--23 out of 5
- 10344 - 23 out of 5(***)
- 10344 - 23 out of 5
- uva10344 - 23 out of 5
- UVaOJ10344 - 23 out of 5
- uva10344 - 23 out of 5
- 10344 - 23 out of 5
- UVA 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
- uva 10344 - 23 out of 5
- UVa 10344 23 out of 5
- glog
- Linux第二弹
- 【Mongodb】morphia与spring结合使用详解
- Android之简易天气预报小应用(xml解析练手)
- 优秀的第三方库
- UVA1034423 out of 5
- median-of-two-sorted-arrays
- jdbc数据库操作
- Opencv中视频播放与进度控制
- 单片机 基础概念
- 82.You are managing an Oracle Database 11g database with the following backup strategy: 1) On Sunday
- hdoj1969Pie
- 栈之括号匹配
- c++primer读书笔记:2.5 类型处理