UVA 23 out of 5
题目例如以下:
Problem I
23 Out of 5
Input: standard input
Output: standardoutput
Time Limit: 1 second
Memory Limit: 32 MB
Your task is to writea program that can decide whether you can find an arithmetic expression consistingof five given numbers
(1<=i<=5) that will yieldthe value 23.
For this problem we will only consider arithmetic expressions of the followingfrom:
where: {1,2,3,4,5} -> {1,2,3,4,5} is a bijective function
and{+,-,*} (1<=i<=4)
Input
The Input consists of 5-Tupelsof positive Integers, each between 1 and 50.
Input is terminated by a line containing five zero's. This line should not beprocessed.
Output
For each 5-Tupel print"Possible" (without quotes) if their exists an arithmetic expression(as described above) that yields 23. Otherwise print "Impossible".
Sample Input
1 1 1 1 1
1 2 3 4 5
2 3 5 7 11
0 0 0 0 0
Sample Output
Impossible
Possible
Possible
也是直接回溯就能够了,只是要注意π是个双射函数(bijective function)。所以要一一相应。不能反复使用,採用一个vis数组标记就可以。
AC的代码例如以下:
UVA 23 out of 5的更多相关文章
- uva 10344 23 out of 5 凑运算结果 全排列+dfs
五个数三个运算符号,排列之后凑成结果为23,不考虑优先级. 很水,数据量也不大,先生成五个数的全排列,用dfs找出结果能否为23即可. 代码: #include <cstdio> #inc ...
- uva10344 23 out of 5
Your task is to write a program that can decide whether you can nd an arithmetic expression consisti ...
- UVA 11427 (概率DP+期望)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 题目大意:每晚打游戏.每晚中,赢一局概率p,最多玩n局, ...
- UVa 103 - Stacking Boxes(dp求解)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVA 437 十九 The Tower of Babylon
The Tower of Babylon Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- UVa 1593代码对齐
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 10905 Children's Game 孩子的游戏 贪心
题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
- Uva 11549 - Calculator Conundrum 找规律加map
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- thinkphp信息修改和分页
关联两个数据表,在Model里建立StuModel.class.php: <?php //Belongs_to 关联表示当前模型从属于另外一个父对象 namespace Admin\Model; ...
- 使用morphia实现对mongodb的聚合查询
morphia是谷歌的一个针对mongodb的数据化持久框架: 关于mongodb的介绍不在这里展示,直接进入主题:采用morphia实现对mongodb的聚合查询 这里获取所有学生的分数总和 spr ...
- C# datagrideview插件的使用
private void btnLogin_Click(object sender, EventArgs e) { string txtUserName = this.txtUserName.Text ...
- Tcl之Math
expr is for Tcl to do math operations. It takes all of its arguments ("2 + 2" for example) ...
- Assembly之instruction之Status register
The status register (SR/R2), used as a source or destination register, can be used in the register m ...
- java web 学习笔记 - Java Bean
1. Java Bean 是一个简单的 java 类,一般放在WEB-INF下的 classes目录下(如果没有则需要手工新建) 一个简单的Bean包括属性,getter ,setter方法,如果没有 ...
- Application crashes -程序崩溃原因
Typical errors that result in application crashes include: attempting to read or write memory that i ...
- 【转】上传并解析excel
[转载自]http://blog.csdn.net/u011563331/article/details/51322523 通过解析excel,将数据存储到数据库中.现在将方法保存下来. 使用的是ap ...
- Luogu P1991 无线通讯网
P1991 无线通讯网 题目描述 国防部计划用无线网络连接若干个边防哨所.2 种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫 ...
- Moving Tables POJ - 1083 (思维)
题目大意 在一层楼上推桌子,每个空间一次只能推1种桌子,且消耗十分钟.可以同时推多个桌子,但是他们所占的空间不能是相交的如图 解法 真的很考验思维能力,首先考虑到这个走廊是有两排的,我瞬间想到了宿舍楼 ...