UVA10344 23 out 5
来源:互联网 发布:阴阳师攻击力数据排行 编辑:程序博客网 时间:2024/05/22 23:58
给你5个数字 要求你能随意使用 + - *三个运算符是这五个数的结果为23(每个数只能使用一次)
先排序,再用nenx_premutation函数枚举每一个全排列
对于每一个全排列 通过递归来暴力检查
<pre name="code" class="cpp">#include<stdio.h>#include<iostream>#include<algorithm>#include<string>using namespace std;int con[5];int temp = 0;bool dfs(int cur,int temp){if (cur == 5){if (temp == 23)return true;else return false;}if (dfs(cur + 1, temp + con[cur])) return true;if (dfs(cur + 1, temp * con[cur])) return true;if (dfs(cur + 1, temp - con[cur])) return true;return false;}bool cmp(int a,int b){return a < b;}int main(){while (true){int x = 0;for (int i = 0; i < 5; i++){cin >> con[i];x += con[i];}if (x == 0)break;bool flag = true;sort(con,con+5,cmp);for (int i = 0; i < 5; i++)cout <<" "<< con[i];cout << endl;do{if (dfs(1, temp)){cout << "Possible" << endl;flag = false;break;}} while (next_permutation(con, con + 5));if (flag)cout << "Impossible" << endl;}return 0;}
0 0
- UVA10344 23 out 5
- uva10344 - 23 out of 5
- uva10344 - 23 out of 5
- uva10344 23 out of 5
- UVA10344----算23点
- UVa10344
- UVA10344
- uva10344
- uva10344
- UVA10344
- UVa10344
- uva10344
- 23 Out of 5
- UVA10344五个数从前往后进行加减乘运算能否得到23
- uva10344 一次AC
- uva10344(全排列+dfs)
- 10344--23 out of 5
- 10344 - 23 out of 5(***)
- ModelSim 与Debussy联调
- PKU1273Drainage Ditches
- 标志寄存器 x86汇编
- ZooKeeper单机模式(stand-alone)
- 关于html页面布局
- UVA10344 23 out 5
- 宏定义
- <<Hive编程指南>>读书笔记
- 【SQL Server】SQL2005的安装与配置、简单使用
- JAVA ServiceLoader详解
- Reflector反编译.NET文件后修复
- Python编写数据结构中的二分查找
- linux系统的7种运行级别
- 四大组件之BroadcastReceiver(广播)