`
473687880
  • 浏览: 535120 次
文章分类
社区版块
存档分类
最新评论

23 out of 5 UVA 10344

 
阅读更多

Problem I

23 Out of 5

Input:standard input

Output:standard output

Time Limit:1 second

Memory Limit:32 MB

Your task is to write a program that can decide whether you can find an arithmetic expression consisting of five given numbers(1<=i<=5) that will yield the value 23.
For this problem we will only consider arithmetic expressions of the following from:


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-Tupels of positive Integers, each between 1 and 50.
Input is terminated by a line containing five zero's. This line should not be processed.

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

Thomas Strohmann

搞了半天,看错题目了,以为数字的顺序不能变。。。顺序是可以变化的。

#include<iostream>
#include<cstring>

using namespace std;

int arry[10],vis[10];
int tag,s,s1;

void dfs(int pos,int s)
{
    if(pos==5&&s==23)
    {
        tag=1;
        return;
    }
    for(int i=0;i<5;i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            dfs(pos+1,s+arry[i]);
            dfs(pos+1,s-arry[i]);
            dfs(pos+1,s*arry[i]);
            vis[i]=0;
        }
    }
}

int main()
{
    while(cin>>arry[0]>>arry[1]>>arry[2]>>arry[3]>>arry[4])
    {
        if(arry[0]==0&&arry[1]==0&&arry[2]==0&&arry[3]==0&&arry[4]==0) break;
        tag=0;
        int i,j,k;
        for(i=0;i<5;i++)
        {
            memset(vis,0,sizeof(vis));
            vis[i]=1;
            dfs(1,arry[i]);
        }
        if(tag) cout<<"Possible"<<endl;
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


分享到:
评论

相关推荐

    UVa1516/LA5906 Smoking gun

    标题“UVa1516/LA5906 Smoking gun”所指的是一场编程竞赛中的一个问题,可能来源于ICPC(国际大学生程序设计竞赛)的在线评测系统UVa(University of Virginia Online Judge)。该问题编号UVa1516与LA5906可能分别...

    Art_of_Programming_Contest_SE_for_uva

    《Art_of_Programming_Contest_SE_for_uva》是一本专为ACM国际大学生程序设计竞赛(ACM International Collegiate Programming Contest, ICPC)爱好者准备的专业参考资料。本书由孟加拉国工程与技术大学(Ahmed ...

    UVa1313/LA2693 Ghost Busters

    【标题】"UVa1313/LA2693 Ghost Busters"是一个编程竞赛题目,来源于UVA(University of Virginia)在线判题系统,同时也出现在了NEERC(North Eurasia East Regional Contest)2002的比赛中。这类题目通常是为训练...

    UVA12563 Jin Ge Jin Qu hao数据

    标题“UVA12563 Jin Ge Jin Qu hao数据”显然指的是一个在线编程竞赛中的问题,可能来自University of Virginia(UVA)的在线判题系统。UVA的在线判题平台是许多程序员和学生熟悉的地方,他们可以在这里解决各种算法...

    UVa1348/LA3310 Tomato Automata

    在编程竞赛的世界中,UVa(University of Virginia)在线判题系统是广大学者和爱好者的重要学习平台,其中的题目UVa1348/LA3310 "Tomato Automata" 是一道具有挑战性的算法问题。该题目源于2005年的SEERC(South ...

    UVa101:紫外线101

    这个平台,也称为“紫外101”,是University of Virginia(UVA)的在线算法竞赛系统,它为程序员提供了丰富的算法问题来锻炼和提升编程技能。特别地,我们将会集中讨论如何使用Java语言来解决UVa101中的挑战。 一、...

    UVa1446/LA4640 Origami Through-Hole测试数据

    标题 "UVa1446/LA4640 Origami Through-Hole测试数据" 提供的信息表明,这是一个与编程竞赛相关的题目,源自UVa(University of Virginia Online Judge)和LA4640,可能是一个特定年份或地区的比赛题目,如标签所示...

    uva.onlinejudge.org:时间通过 UVA 挑战

    5. **输入输出流**:学会使用System.in读取标准输入,System.out.println输出结果,以及更高级的FileInputStream和FileOutputStream进行文件操作。 6. **排序和搜索算法**:如冒泡排序、选择排序、插入排序、快速...

    UVaSolutions:这个 Repository 包含我个人如何解决 UVa 上的问题集的解决方案,这些解决方案可能不是最优的,但它们都被在线评判系统接受

    UVaSolutions 是一个公开的代码仓库,作者分享了他在解决 UVa(University of Virginia's Online Judge)问题集时所采用的策略和代码。UVa 在线评判系统是一个著名的编程竞赛平台,它提供了大量算法和逻辑挑战问题,...

Global site tag (gtag.js) - Google Analytics