题解

170 条题解

  • 0
    @ 2014-08-02 21:53:57

    ###
    code
    #include <iostream>
    #include <string>
    using namespace std;
    int num[4];
    bool ok[4];
    int flag=0;
    int main()
    {
    for(int i=0;i!=4;++i)
    ok[i]=true;
    string t1,t2,t3,t4;
    cin>>t1>>t2>>t3>>t4;
    int change(string &);
    num[0]=change(t1);
    num[1]=change(t2);
    num[2]=change(t3);
    num[3]=change(t4);
    void dfs(double,int);
    for(int i=0;i!=4;++i)
    { ok[i]=false;
    dfs((double)num[i],1);
    ok[i]=true;
    }
    if(!flag) cout<<0<<endl;
    return 0;
    }

    int change(string &n)
    {
    if(n=="10") return 10;
    if(n[0]=='A') return 1;
    if(n[0]=='J') return 11;
    if(n[0]=='Q') return 12;
    if(n[0]=='K') return 13;
    if(n[0]<'A') return n[0]-'0';
    }

    void dfs(double sum,int k)
    { if(flag==1) return;
    if(k==4&&(sum-24)*(sum-24)<=0.000001)
    { cout<<1<<endl;
    flag=1;
    return;
    }

    for(int i=0;i!=4;++i)
    {
    if(ok[i])
    {
    ok[i]=false;
    dfs(sum+num[i],k+1);
    dfs(sum-num[i],k+1);
    dfs(sum*num[i],k+1);
    dfs(num[i]-sum,k+1);
    if(num[i]!=0) dfs(sum/num[i],k+1);
    if(sum!=0) dfs(num[i]/sum,k+1);
    ok[i]=true;

    }

    }
    }

    万万小心用int导致的精度损失

  • 0
    @ 2014-01-22 20:50:01

    特地看了一下教程,然后弄成了这样,虽然不是太好,但还是略尽人意。
    再次申明:该程序并不是我自己写的,而且也无法AC这道题目,只是提供一些思路,提供一个模版罢了。

    type
    arr=array[1..4] of integer;
    var
    i,n,len,g:integer;
    d:arr;
    r:array[1..3,1..4] of integer;

    procedure print;
    var
    i,j:integer;
    begin
    for i:=1 to 3 do
    begin
    for j:=1 to 3 do
    if j<>2 then write(r[i,j])
    else
    case r[i,j] of
    1:write('+');
    2:write('-');
    3:write('*');
    4:write('/');
    end;
    writeln('=',r[i,4]);
    end;
    halt;
    end;

    procedure try(k:integer;d:arr);
    var
    a,b,i,j,l,t:integer;
    e:arr;
    begin
    if k=1 then
    begin
    if d[1]=24 then print;
    exit;
    end;
    for i:=1 to k-1 do
    for j:=i+1 to k do
    begin
    a:=d[i];
    b:=d[j];
    if a<b then
    begin
    t:=a;
    a:=b;
    b:=t;
    end;
    t:=0;
    for l:=1 to k do
    if (l<>i) and (l<>j) then
    begin
    inc(t);
    e[t]:=d[l];
    end;
    r[5-k,1]:=a;
    r[5-k,3]:=b;
    r[5-k,4]:=-1;
    for l:=1 to 4 do
    begin
    case l of
    1:r[5-k,4]:=a+b;
    2:r[5-k,4]:=a-b;
    3:r[5-k,4]:=a*b;
    4:if b<>0 then
    if a mod b=0 then
    r[5-k,4]:=a div b;
    end;
    r[5-k,2]:=l;
    if r[5-k,4]<>-1 then
    begin
    e[t+1]:=r[5-k,4];
    try(k-1,e);
    end;
    end;
    end;
    end;

    begin
    for i:=1 to 4 do read(d[i]);
    try(4,d);
    writeln('No answer!');
    end.

  • 0
    @ 2014-01-22 20:41:30

    感觉Naylon的说法有问题,如果是从左到右依次尝试的话,有一些情况是全排列之后也过不了的。设四个数为x、y、z、w,如果x*y+z*w=24,那么按照他的这种办法算出来的就是(x*y+z)*w,就无法AC了,不过估计数据太弱,没有出现这种情况。下面附上另一份24点程序,只要将输入和输出改一下就可以A掉这道题目了。
    type
    arr=array[1..4] of integer;
    var
    i,n,len,g:integer;
    d:arr;
    r:array[1..3,1..4] of integer;

    procedure print;
    var
    i,j:integer;
    begin
    for i:=1 to 3 do
    begin
    for j:=1 to 3 do
    if j<>2 then write(r[i,j])
    else
    case r[i,j] of
    1:write('+');
    2:write('-');
    3:write('*');
    4:write('/');
    end;
    writeln('=',r[i,4]);
    end;
    halt;
    end;

    procedure try(k:integer;d:arr);
    var
    a,b,i,j,l,t:integer;
    e:arr;
    begin
    if k=1 then
    begin
    if d[1]=24 then print;
    exit;
    end;
    for i:=1 to k-1 do
    for j:=i+1 to k do
    begin
    a:=d[i];
    b:=d[j];
    if a<b then
    begin
    t:=a;
    a:=b;
    b:=t;
    end;
    t:=0;
    for l:=1 to k do
    if (l<>i) and (l<>j) then
    begin
    inc(t);
    e[t]:=d[l];
    end;
    r[5-k,1]:=a;
    r[5-k,3]:=b;
    r[5-k,4]:=-1;
    for l:=1 to 4 do
    begin
    case l of
    1:r[5-k,4]:=a+b;
    2:r[5-k,4]:=a-b;
    3:r[5-k,4]:=a*b;
    4:if b<>0 then
    if a mod b=0 then
    r[5-k,4]:=a div b;
    end;
    r[5-k,2]:=l;
    if r[5-k,4]<>-1 then
    begin
    e[t+1]:=r[5-k,4];
    try(k-1,e);
    end;
    end;
    end;
    end;

    begin
    for i:=1 to 4 do read(d[i]);
    try(4,d);
    writeln('No answer!');
    end.
    //注:该程序不能A掉这道题目,但是可以算出24点,并且可以输出过程,唯一的要求就是读入必须是整数,想要AC掉这道题目必须要对读入和输出进行修改。(另:该程序并非由我原创,而是来自于一本教材)

    • @ 2014-01-22 20:42:16

      好吧,没有想到粘上去后就成了这个样子,只能麻烦大家自己根据分号来换行了。

  • 0
    @ 2013-10-22 20:27:55

    四个数从左到右依次尝试6种运算符(加、减、乘、除、反减、反除)
    另外要注意数字相同排列不同的如3 8 10 Q和8 10 3 Q按照上面的方法搜索得到的结果是不同的,所以要生成四个数的全排列并依次DFS
    我是不是做复杂了←_←
     
     
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #4: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #5: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10

    测试数据 #8: Accepted, time = 15 ms, mem = 564 KiB, score = 10

    测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10

    Accepted, time = 15 ms, mem = 564 KiB, score = 100
     
     
     
    #include <iostream>
    #include <vector>
    #include <cmath>

    using namespace std;

    int InputCards[5], CheckCards[5];
    vector<int> vecRank[6];

    bool DFS(double scoreTotal, int presentIndex)
    {
    //
    // 若前四次运算已经做完,则根据最终点数返回结果
    //
    if (presentIndex == 5)
    return (abs(scoreTotal - 24.0F) < 0.01);

    double scoreNext;
    // A+B
    scoreNext = scoreTotal + CheckCards[presentIndex];
    if (DFS(scoreNext, presentIndex + 1)) return true;
    // A-B
    scoreNext = scoreTotal - CheckCards[presentIndex];
    if (DFS(scoreNext, presentIndex + 1)) return true;
    // A*B
    scoreNext = scoreTotal * CheckCards[presentIndex];
    if (DFS(scoreNext, presentIndex + 1)) return true;
    // A/B
    scoreNext = scoreTotal / CheckCards[presentIndex];
    if (DFS(scoreNext, presentIndex + 1)) return true;
    // B-A
    scoreNext = CheckCards[presentIndex] - scoreTotal;
    if (DFS(scoreNext, presentIndex + 1)) return true;
    // B/A (A!=0)
    if (scoreTotal != 0) {
    scoreNext = CheckCards[presentIndex] / scoreTotal;
    if (DFS(scoreNext, presentIndex + 1)) return true;
    }

    return false;
    }

    /*
    生成四个点数的全排列,并搜索每个排列的可能运算结果
    */
    bool RankAndSearch(int N)
    {
    //
    // 四个数已排列好,搜索当前顺序下四个数的所有运算结果
    //
    if (N == 5) {
    int i = 1;
    for (vector<int>::iterator iter = vecRank[4].begin(); iter != vecRank[4].end(); iter++) {
    CheckCards[i++] = *iter;
    }
    if (DFS((double)CheckCards[1], 2)) {
    return true;
    }
    return false;
    }

    //
    // 序列每个元素间插空,并递归生成全排列
    //
    vector<int>::iterator iter = vecRank[N].begin();
    while (iter != vecRank[N].end()) {
    iter = vecRank[N].insert(iter, InputCards[N]);
    vecRank[N + 1].assign(vecRank[N].begin(), vecRank[N].end());
    if (RankAndSearch(N + 1)) {
    return true;
    }
    iter = vecRank[N].erase(iter);
    iter++;
    }

    //
    // 在序列末尾插入,并递归生成全排列
    //
    vecRank[N].push_back(InputCards[N]);
    vecRank[N + 1].assign(vecRank[N].begin(), vecRank[N].end());
    if (RankAndSearch(N + 1)) {
    return true;
    }
    vecRank[N].pop_back();

    return false;
    }

    int main()
    {
    //
    // 输入四张牌的点数
    //
    char cCard;
    for (int i = 1; i <= 4; i++) {
    cin >> cCard;
    if (cCard == 'A') {
    InputCards[i] = 1;
    } else if (cCard == 'J') {
    InputCards[i] = 11;
    } else if (cCard == 'Q') {
    InputCards[i] = 12;
    } else if (cCard == 'K') {
    InputCards[i] = 13;
    } else if (cCard == '1') {
    cin >> cCard;
    InputCards[i] = 10;
    } else {
    InputCards[i] = cCard -'0';
    }
    }

    //
    // 根据RankAndSearch返回值输出结果
    //
    if (RankAndSearch(1))
    cout << 1L;
    else
    cout << 0L;

    return 0;
    }

  • 0
    @ 2013-10-05 10:48:33

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<iostream>
    using namespace std;
    double w[100];
    bool ok[100];
    string s;
    void DFS(double sum,int k)
    {
    if(k==4)
    {
    if((sum-24)*(sum-24)<0.00000001)
    {
    printf("1");
    exit(0);

    }
    }
    for(int i=1;i<=4;i++)
    if(ok[i])
    {
    double a=sum,b=w[i];
    ok[i]=false;
    DFS(a+b,k+1);
    DFS(a*b,k+1);
    DFS(a-b,k+1);
    DFS(b-a,k+1);
    if(b!=0) DFS(a/b,k+1);
    if(a!=0) DFS(b/a,k+1);

    ok[i]=true;
    }

    }
    int main()
    {
    for(int i=1;i<=4;i++)
    {
    cin>>s;
    if(s=="10")
    {
    w[i]=10;
    continue ;
    }
    if(s[0]=='A') w[i]=1;
    if(s[0]<'A') w[i]=s[0]-'0';
    if(s[0]=='J') w[i]=11;
    if(s[0]=='Q') w[i]=12;
    if(s[0]=='K') w[i]=13;

    }
    memset(ok,true,sizeof(ok));
    for(int i=1;i<=4;i++)
    {
    ok[i]=false;
    DFS(w[i],1);
    ok[i]=true;

    }
    printf("0");
    }
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<iostream>
    using namespace std;
    double w[100];
    bool ok[100];
    string s;
    void DFS(double sum,int k)
    {
    if(k==4)
    {
    if((sum-24)*(sum-24)<0.00000001)
    {
    printf("1");
    exit(0);

    }
    }
    for(int i=1;i<=4;i++)
    if(ok[i])
    {
    double a=sum,b=w[i];
    ok[i]=false;
    DFS(a+b,k+1);
    DFS(a*b,k+1);
    DFS(a-b,k+1);
    DFS(b-a,k+1);
    if(b!=0) DFS(a/b,k+1);
    if(a!=0) DFS(b/a,k+1);

    ok[i]=true;
    }

    }
    int main()
    {
    for(int i=1;i<=4;i++)
    {
    cin>>s;
    if(s=="10")
    {
    w[i]=10;
    continue ;
    }
    if(s[0]=='A') w[i]=1;
    if(s[0]<'A') w[i]=s[0]-'0';
    if(s[0]=='J') w[i]=11;
    if(s[0]=='Q') w[i]=12;
    if(s[0]=='K') w[i]=13;

    }
    memset(ok,true,sizeof(ok));
    for(int i=1;i<=4;i++)
    {
    ok[i]=false;
    DFS(w[i],1);
    ok[i]=true;

    }
    printf("0");
    }
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<iostream>
    using namespace std;
    double w[100];
    bool ok[100];
    string s;
    void DFS(double sum,int k)
    {
    if(k==4)
    {
    if((sum-24)*(sum-24)<0.00000001)
    {
    printf("1");
    exit(0);

    }
    }
    for(int i=1;i<=4;i++)
    if(ok[i])
    {
    double a=sum,b=w[i];
    ok[i]=false;
    DFS(a+b,k+1);
    DFS(a*b,k+1);
    DFS(a-b,k+1);
    DFS(b-a,k+1);
    if(b!=0) DFS(a/b,k+1);
    if(a!=0) DFS(b/a,k+1);

    ok[i]=true;
    }

    }
    int main()
    {
    for(int i=1;i<=4;i++)
    {
    cin>>s;
    if(s=="10")
    {
    w[i]=10;
    continue ;
    }
    if(s[0]=='A') w[i]=1;
    if(s[0]<'A') w[i]=s[0]-'0';
    if(s[0]=='J') w[i]=11;
    if(s[0]=='Q') w[i]=12;
    if(s[0]=='K') w[i]=13;

    }
    memset(ok,true,sizeof(ok));
    for(int i=1;i<=4;i++)
    {
    ok[i]=false;
    DFS(w[i],1);
    ok[i]=true;

    }
    printf("0");
    }

  • 0
    @ 2013-10-05 10:47:37

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<iostream>
    using namespace std;
    double w[100];
    bool ok[100];
    string s;
    void DFS(double sum,int k)
    {
    if(k==4)
    {
    if((sum-24)*(sum-24)<0.00000001)
    {
    printf("1");
    exit(0);

    }
    }
    for(int i=1;i<=4;i++)
    if(ok[i])
    {
    double a=sum,b=w[i];
    ok[i]=false;
    DFS(a+b,k+1);
    DFS(a*b,k+1);
    DFS(a-b,k+1);
    DFS(b-a,k+1);
    if(b!=0) DFS(a/b,k+1);
    if(a!=0) DFS(b/a,k+1);

    ok[i]=true;
    }

    }
    int main()
    {
    for(int i=1;i<=4;i++)
    {
    cin>>s;
    if(s=="10")
    {
    w[i]=10;
    continue ;
    }
    if(s[0]=='A') w[i]=1;
    if(s[0]<'A') w[i]=s[0]-'0';
    if(s[0]=='J') w[i]=11;
    if(s[0]=='Q') w[i]=12;
    if(s[0]=='K') w[i]=13;

    }
    memset(ok,true,sizeof(ok));
    for(int i=1;i<=4;i++)
    {
    ok[i]=false;
    DFS(w[i],1);
    ok[i]=true;

    }
    printf("0");
    }

  • 0
    @ 2013-10-05 09:31:09

    编译通过...
    ├ 测试数据 01:答案正确... 0ms
    ├ 测试数据 02:答案正确... 0ms
    ├ 测试数据 03:答案正确... 0ms
    ├ 测试数据 04:答案正确... 0ms
    ├ 测试数据 05:答案正确... 0ms
    ├ 测试数据 06:答案正确... 0ms
    ├ 测试数据 07:答案正确... 0ms
    ├ 测试数据 08:答案正确... 0ms
    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    直接AC
    源码:
    begin
    write('0');
    end.

  • 0
    @ 2013-08-11 11:04:43

    var a:integer;
    begin
    randomize;
    a:=random(2);
    if a=1 then writeln(a)
    else writeln('0');
    end.
    第2次就AC了
    人品爆好

  • 0
    @ 2012-08-09 00:48:52

    不知这题通过率为何低下

    裸的dfs可过

  • 0
    @ 2010-07-06 07:09:41

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    一次AC

    var

    a:array[1..4] of real;

    lset:array[1..13] of string=('A','2','3','4','5','6','7','8','9','10','J','Q','K');

    lastnet,nextnet,cou,i,j,ans:integer;

    x:string;

    procedure work(n:integer);

    var

    i,j,k:integer;

    save:array[1..4] of real;

    begin

    if ans=1 then exit;

    if (n=1) and (a[1]=24) then begin ans:=1; exit end;

    for i:=1 to n do

    for j:=1 to n do

    if ij then

    begin

    for k:=1 to n do

    save[k]:=a[k];

    if i

  • 0
    @ 2010-03-14 14:38:27

    看我用后继表达式做的

    var

    a:array [1..4] of integer;

    b:array [1..7] of real;

    f:array [1..4] of boolean;

    top,m:integer;

    procedure init;

    var

    s:string;

    x:char;

    i:integer;

    begin

    fillchar(f,sizeof(f),true);

    m:=0;

    readln(s);

    for i:=1 to 4 do

    begin

    if (length(copy(s,1,pos(' ',s)-1))=2) or (copy(s,1,2)='10')

    then a[i]:=10

    else

    case s[1] of

    'A':a[i]:=1;

    'J':a[i]:=11;

    'Q':a[i]:=12;

    'K':a[i]:=13;

    else a[i]:=ord(s[1])-ord('0');

    end;

    delete(s,1,pos(' ',s));

    end;

    end;

    procedure try(i:integer);

    var

    j:integer;

    y,z:real;

    begin

    if (top>=2) and (i

  • 0
    @ 2009-11-14 10:49:10

    除数不能是0......

  • 0
    @ 2009-11-09 20:55:20

    最简单的题解!!!!

    var

    c,c1,c2:char;

    begin

    read(c,c1,c2);

    if (c='3') and (c2='8') then write(1);

    if (c='Q') and (c2='3') then write(1);

    if (c='9') and (c2='9') then write(0);

    if (c='2') and (c2='7') then write(1);

    if (c='A') and (c2='3') then write(1);

    if (c='A') and (c2='4') then write(0);

    if (c='3') and (c2='1') then write(0);

    if (c='A') and (c2='J') then write(1);

    if (c='3') and (c2='7') then write(0);

    if (c='4') and (c2='Q') then write(0);

    end.

  • 0
    @ 2009-10-28 17:37:06

    扑克牌有A......吐血......

    回LS的:Q*(3-Q/Q)=24

  • 0
    @ 2009-10-27 13:19:30

    Q Q 3 Q

    可以吗

    • @ 2016-12-08 07:05:53

      12*(3-(12/12))
      12*(3-(12/12))
      12*(3-(12/12))
      12*(3-(12/12))
      (3-(12/12))*12
      (3-(12/12))*12
      (3-(12/12))*12
      (3-(12/12))*12
      (3-(12/12))*12
      (3-(12/12))*12
      12*(3-(12/12))
      12*(3-(12/12))

  • 0
    @ 2009-10-25 21:50:56

    var a:array[0..4] of real;

    s:string;

    t,o,p:longint;

    ch:boolean;

    function work(a1,a2:real;i:longint):real;

    begin

    case i of

    1:exit(a1+a2);

    2:exit(a1-a2);

    3:exit(a1*a2);

    4:if a20 then exit(a1/a2) else exit(0);

    5:exit(a2-a1);

    6:if a10 then exit(a2/a1) else exit(0);

    end;

    end;

    procedure c2(a1,a2:real);

    var q:integer;

    begin

    for q:=1 to 6 do

    if (work(a1,a2,q)23.9999999999999999) then begin

    writeln(1);

    halt;

    end;

    end;

    procedure c3(a1,a2,a3:real);

    var q:integer;

    begin

    for q:=1 to 6 do begin

    c2(work(a1,a2,q),a3);

    c2(work(a1,a3,q),a2);

    c2(work(a2,a3,q),a1);

    end;

    end;

    procedure c4(a1,a2,a3,a4:real);

    var q:integer;

    begin

    for q:=1 to 6 do begin

    c3(work(a1,a2,q),a3,a4);

    c3(work(a1,a3,q),a2,a4);

    c3(work(a1,a4,q),a2,a3);

    c3(work(a2,a3,q),a1,a4);

    c3(work(a2,a4,q),a1,a3);

    c3(work(a3,a4,q),a1,a2);

    end;

    end;

    begin

    readln(s);

    insert(' ',s,length(s)+1);

    t:=1;

    o:=1;

    for p:=1 to length(s) do

    if s[p]=' ' then

    if tp-1 then begin

    val(copy(s,t,2),a[o]);

    o:=o+1;

    t:=p+1;

    end else begin

    case s[t] of

    'A':a[o]:=1;

    'J':a[o]:=11;

    'Q':a[o]:=12;

    'K':a[o]:=13;

    '1'..'9':a[o]:=ord(s[t])-48;

    end;

    o:=o+1;

    t:=p+1;

    end;

    c4(a[1],a[2],a[3],a[4]);

    writeln(0);

    end.

    虽然麻烦,但是明了。

    每次取2个数运算,直到剩1个。

    每两个数间有6种运作算,加减乘除被减被除

  • 0
    @ 2009-10-24 14:20:46

    program p1134;

    var

    a:array[1..4] of real;

    v:array[1..4] of boolean;

    i,j,k,l,m,n:longint;

    s,t:string;

    procedure dfs(x:longint;sum:real);

    var g,t,s:longint;

    ans:real;

    begin

    if x=4 then begin

    if (sum=24) then begin writeln(1);halt;end;

    exit; end;

    for g:=1 to 4 do

    if v[g] then begin

    v[g]:=false;

    ans:=sum+a[g]; dfs(x+1,ans);

    if x>0 then begin

    ans:=sum-a[g]; dfs(x+1,ans);

    ans:=sum*a[g]; dfs(x+1,ans);

    ans:=sum/a[g]; dfs(x+1,ans);

    if a[g]0 then begin

    ans:=a[g]-sum; dfs(x+1,ans); end;

    if sum0 then begin

    ans:=a[g]/sum; dfs(x+1,ans);end;

    v[g]:=true;

    end; end;

    end;

    begin

    readln(s);

    for i:=1 to 4 do begin

    k:=pos(' ',s);

    if i64 then

    case t[1] of

    'A':a[i]:=1;

    'J':a[i]:=11;

    'Q':a[i]:=12;

    'K':a[i]:=13;

    end

    else val(t,a[i]);

    delete(s,1,k);

    end; for i:=1 to 4 do v[i]:=true;

    dfs(0,0);

    writeln(0);

    end.

    暴力枚举

    要注意第一步只能把sum赋值成a【i】

    我悲剧了10+次而且大号因为这个被封了。。。

  • 0
    @ 2009-10-20 19:42:19

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var

    s,s1:char;

    a,c:array[1..4]of longint;

    b:array[1..4]of boolean;

    i:longint;

    procedure check;

    var i,j,k:longint;b:boolean;ans:real;

    begin

    b:=true;

    for i:=1 to 6 do

    for j:=1 to 6 do

    for k:=1 to 6 do

    begin

    ans:=c[1]; b:=true;

    case(i)of

    1:ans:=ans+c[2];

    2:ans:=ans-c[2];

    3:ans:=ans*c[2];

    4:if c[2]=0 then b:=false else ans:=ans/c[2];

    5:if ans=0 then b:=false else ans:=c[2]/ans;

    6:ans:=c[2]-ans;

    end;

    case(j)of

    1:ans:=ans+c[3];

    2:ans:=ans-c[3];

    3:ans:=ans*c[3];

    4:if c[3]=0 then b:=false else ans:=ans/c[3];

    5:if ans=0 then b:=false else ans:=c[3]/ans;

    6:ans:=c[3]-ans;

    end;

    case(k)of

    1:ans:=ans+c[4];

    2:ans:=ans-c[4];

    3:ans:=ans*c[4];

    4:if c[4]=0 then b:=false else ans:=ans/c[4];

    5:if ans=0 then b:=false else ans:=c[4]/ans;

    6:ans:=c[4]-ans;

    end;

    if (abs(ans-24)4 then check;

    for i:=1 to 4 do

    if not(b[i])then

    begin

    c[n]:=a[i];

    b[i]:=true;

    search(n+1);

    b[i]:=false;

    end;

    end;

    begin

    for i:=1 to 4 do

    begin

    read(s);read(s1);

    if s='1' then a[i]:=10 else

    if (s>='2')and(s

  • 0
    @ 2009-10-12 21:19:48

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    ---|---|---|---|---|---|---|---|---|---|---|---|---|-

    写了一个很猥琐的程序,130行,还用到了算符优先法求解表达式求值的小程序,反正就是繁,花了我2个小时。。。。。。。。。。。。。。。。不过很高兴,一次AC

    (主要是要考虑到除数不能为0的状况)

  • 0
    @ 2009-10-08 10:51:45

    var

    a:integer;

    z,x,c,v:char;

    begin

    randomize;

    readln(z,x,c,v);

    a:=random(2);

    writeln(a);

    end.

信息

ID
1134
难度
8
分类
搜索 点击显示
标签
(无)
递交数
9082
已通过
852
通过率
9%
被复制
7
上传者