UVA 10344
来源:互联网 发布:香港买mac口红多少钱 编辑:程序博客网 时间:2024/06/08 08:44
题目大意:输入五个数, 判断是否存在情况使得式子( ( a(1) o a(2) ) o a(3) ) o a(4) ) o4 a(5)等于23。五个数的任意排序,o为运算符‘+’,‘-’,或‘*’。
解题思路:运算符的顺序用三进制来表示,五个数的全排序用next_permutation来计算。
ac代码:
#include <iostream>#include <cmath>#include <algorithm>using namespace std;int a[10], re[4], sum, flag;int compute(){int sum = a[0];for (int i=0; i<4; i++){if (re[i] == 0)sum += a[i+1];else if (re[i] == 1)sum -= a[i+1];elsesum *= a[i+1];}return sum;}int main(){while (scanf("%d", &a[0])!=EOF){flag = 0;for (int i=1; i<5; i++)scanf("%d", &a[i]);if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4])break;for (int i=0; i<pow(3, 4); i++){sort(a, a+5);for (int j=0,cnt=1; j<4; j++,cnt*=3)re[j] = i / cnt % 3;do{if (compute() == 23)flag = 1;}while (next_permutation(a, a+5));}if (flag)printf("Possible\n");elseprintf("Impossible\n");}return 0;}
阅读全文
0 0
- uva 10344
- UVA 10344
- uva 10344
- uva(10344)
- uva 10344
- UVA 10344
- UVA 10344 (13.07.19)
- uva 10344(暴力求解)
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- 关于EasyUI与富文本编辑器结合使用的问题(kindueditor与uueditor)
- 漏洞挖掘
- 直接通过网页jsp导出Excel文件
- makefile使用函数
- 阿里云服务器部署正式web环境
- UVA 10344
- [LeetCode]653. Two Sum IV
- 再谈C#委托与事件
- IIS8 未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- 百度第二页关键词如何快速排名至百度首页
- 人工智能让机器人拥有无限可能
- Gaussian high-pass filter
- POJ 1458