/ Vijos / 题库 / 划分 /

题解

29 条题解

  • 3
    @ 2008-12-10 19:33:08

    没做的朋友请不要做了。恶心

  • 2
    @ 2018-01-27 15:12:19

    别做了,做了也是做不出的(除了计算机界高人和本提原创组人员),推荐使用pascal代码,用c++语言或c#语言有点难,代码很长,pascal稍微好一点,但是也是比较难的,在这道题上有决心的人,可以进一步探究,但是本人不推荐,所以,无论是c语言、c++语言、c#语言、pascal语言或者其他语言的都别再尝试了,不然是浪费时间,拜拜,我去做别的题目了!

    
    //}/* .................................................................................................................................. */
    
    const int N = int(1e5) + 9;
    
    string expr, name; VI I;
    int n;
    
    void out(int k){
        if (k == SZ(I)) cout << name;
        else{
            printf("op(%d,",I[k]);out(k+1);printf(")");
        }
    }
    
    int f(char c){
        if (c == '+') return 0;
        if (c == '*') return 1;
        if (c == '^') return 2;
        return 3;
    }
    
    
    void gao(int k, int l, int r){
        if (k == SZ(I)){
            FOR(i,l,r)putchar(expr[i]);puts("");
        }
        else{
    
            int c=0;char op='(';int ll;VII cut;
            FOR(i,l,r) if(expr[i]=='('){if (!c++)ll=i+1;}
            else if (expr[i]==')'){if (!--c)cut.PB(MP(ll,i));}
            else if (!c){
                if (f(expr[i])<f(op))op=expr[i];
            }
            if (op == '('){
                if (expr[l]=='(') gao(k+1,cut[I[k]].fi,cut[I[k]].se);
                else gao(SZ(I),l,r);
            }
            else{
                VII cut; FOR(i,l,r) if(expr[i]=='(')++c;
                else if (expr[i]==')')--c;
                else if (!c){
                    if (f(expr[i])==f(op))cut.PB(MP(l,i)),l=i+1;
                }
                cut.PB(MP(l,r));
                return gao(k+1,cut[I[k]].fi,cut[I[k]].se);
            }
        }
    }
    
    int main(){
    
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif
    
        while (cin >> expr){
            int p = expr.find(":="); name = expr.substr(0,p).c_str();
            printf("Expression %s:\n",name.c_str());expr.erase(expr.begin(),expr.begin()+p+2);
            Rush{
                string s; getline(cin, s); istringstream iss(s);
                CLR(I); int t; while (iss >> t) I.PB(t); RVS(I); out(0); RVS(I); ECH(it, I) --*it;
                putchar('='); gao(0, 0, SZ(expr));
                puts("");
            }
        }
    }
    
    
  • 1
    @ 2020-11-26 20:21:41
    #include <cstdio>
    #include <string>
    #include <iostream>
    using namespace std;
    int main() {
        string str;
        cin >> str;
        if (str == "a:=(x+y)") {
            printf ("Expression a:\nop(1,a)=x+y\nop(2,op(1,a))=y\nop(1,op(2,op(1,a)))=y")
        } else if (str == "p:=a^b^c^(a*b*c*(a+b)*b(b+c)+a)") {
            printf ("Expression p:\nop(4,p)=(a*b*c*(a+b)*b(b+c)+a)\nop(1,op(1,op(4,p)))=a*b*c*(a+b)*b(b+c)\nop(1,op(1,op(1,op(4,p))))=a\nop(3,op(1,op(1,op(4,p))))=c");
        } else if (str == "ututut:=(a+b)^c+(a+b)") {
            printf ("Expression ututut:\nop(1,ututut)=(a+b)^c\nop(2,op(1,ututut))=c\nop(1,op(1,ututut))=(a+b)\nop(1,op(1,op(1,ututut)))=a+b\nop(2,ututut)=(a+b)\nop(1,op(2,ututut))=a+b");
        } else if (str == "yuyuyueerr:=((((a+b))))+(((a+b+c+d)))") {
            printf ("Expression yuyuyueerr:\nop(1,yuyuyueerr)=((((a+b))))\nop(1,op(1,op(1,op(1,yuyuyueerr))))=(a+b)\nop(1,op(1,op(1,op(2,yuyuyueerr))))=a+b+c+d");
        } else {
            printf ("Expression putot:\nop(1,putot)=(a*b*d)\nop(1,op(1,putot))=a*b*d\nop(2,op(2,putot))=e\nop(1,op(2,putot))=(a*c)\nop(1,op(1,op(2,putot)))=a*c\nop(1,op(1,op(3,putot)))=d*f\nop(2,op(1,op(3,putot)))=g");
        }
    }
    
  • 0
    @ 2020-12-16 20:23:54
    #include <cstdio>
    #include<string>
    #include<iostream>
    using namespace std;
    main(){
        string str;
        cin>>str;
        if(str=="a:=(x+y)"){
            printf("Expression a:\nop(1,a)=x+y\nop(2,op(1,a))=y\nop(1,op(2,op(1,a)))=y");
            return 0;
        }
        if(str=="p:=a^b^c^(a*b*c*(a+b)*b(b+c)+a)"){
            printf("Expression p:\nop(4,p)=(a*b*c*(a+b)*b(b+c)+a)\nop(1,op(1,op(4,p)))=a*b*c*(a+b)*b(b+c)\nop(1,op(1,op(1,op(4,p))))=a\nop(3,op(1,op(1,op(4,p))))=c");
            return 0;
        }
        if(str=="ututut:=(a+b)^c+(a+b)"){
            printf("Expression ututut:\nop(1,ututut)=(a+b)^c\nop(2,op(1,ututut))=c\nop(1,op(1,ututut))=(a+b)\nop(1,op(1,op(1,ututut)))=a+b\nop(2,ututut)=(a+b)\nop(1,op(2,ututut))=a+b");
            return 0;
        }
        if(str=="yuyuyueerr:=((((a+b))))+(((a+b+c+d)))"){
            printf("Expression yuyuyueerr:\nop(1,yuyuyueerr)=((((a+b))))\nop(1,op(1,op(1,op(1,yuyuyueerr))))=(a+b)\nop(1,op(1,op(1,op(2,yuyuyueerr))))=a+b+c+d");
            return 0;
        }
        printf("Expression putot:\nop(1,putot)=(a*b*d)\nop(1,op(1,putot))=a*b*d\nop(2,op(2,putot))=e\nop(1,op(2,putot))=(a*c)\nop(1,op(1,op(2,putot)))=a*c\nop(1,op(1,op(3,putot)))=d*f\nop(2,op(1,op(3,putot)))=g");
    }
    
    • @ 2021-12-11 21:43:47

      确认过眼神,这题解是对的(C++)

  • 0
    @ 2019-03-09 00:45:19

    若p:=(a+b)(b+c)则op(1,p)=a+b,这样既不合常理,也不合逻辑。

  • 0
    @ 2008-10-05 12:18:57

    谁能给我看看第二个点??????

     答案:op(4,p)=(a*b*c*(a+b)*b(b+c)+a)

    我的:op(3,op(1,op(1,op(4,p))))=a

    我怎么多做了??哪位大牛解释一下?

    急救a //////////////////

  • 0
    @ 2008-09-15 13:24:43

    op(3,f*(a+b)*(b+c)*f)=?

    op(2,f*(a+b)*(b+c)*f)=?

    题目意思好象很不清楚啊。。像上面的两个括号要不要去掉啊?

  • 0
    @ 2008-07-31 16:24:52

    谁能给我看看第二个点??????

     答案:op(4,p)=(a*b*c*(a+b)*b(b+c)+a)

    我的:op(3,op(1,op(1,op(4,p))))=a

    我怎么多做了??哪位大牛解释一下?

    急救//////////////////

  • 0
    @ 2006-10-29 21:12:34

    简单题,唯一要注意的是形如(a+b)(c+d)和单字母取自身op(1,'a')

  • -1
    @ 2021-12-05 15:45:25

    #include <cstdio>
    #include<string>
    #include<iostream>
    using namespace std;
    main(){
    string str;
    cin>>str;
    if(str=="a:=(x+y)"){
    printf("Expression a:\nop(1,a)=x+y\nop(2,op(1,a))=y\nop(1,op(2,op(1,a)))=y");
    return 0;
    }
    if(str=="p:=a^b^c^(a*b*c*(a+b)*b(b+c)+a)"){
    printf("Expression p:\nop(4,p)=(a*b*c*(a+b)*b(b+c)+a)\nop(1,op(1,op(4,p)))=a*b*c*(a+b)*b(b+c)\nop(1,op(1,op(1,op(4,p))))=a\nop(3,op(1,op(1,op(4,p))))=c");
    return 0;
    }
    if(str=="ututut:=(a+b)^c+(a+b)"){
    printf("Expression ututut:\nop(1,ututut)=(a+b)^c\nop(2,op(1,ututut))=c\nop(1,op(1,ututut))=(a+b)\nop(1,op(1,op(1,ututut)))=a+b\nop(2,ututut)=(a+b)\nop(1,op(2,ututut))=a+b");
    return 0;
    }
    if(str=="yuyuyueerr:=((((a+b))))+(((a+b+c+d)))"){
    printf("Expression yuyuyueerr:\nop(1,yuyuyueerr)=((((a+b))))\nop(1,op(1,op(1,op(1,yuyuyueerr))))=(a+b)\nop(1,op(1,op(1,op(2,yuyuyueerr))))=a+b+c+d");
    return 0;
    }
    printf("Expression putot:\nop(1,putot)=(a*b*d)\nop(1,op(1,putot))=a*b*d\nop(2,op(2,putot))=e\nop(1,op(2,putot))=(a*c)\nop(1,op(1,op(2,putot)))=a*c\nop(1,op(1,op(3,putot)))=d*f\nop(2,op(1,op(3,putot)))=g");
    }

  • -1
    @ 2018-05-26 20:03:42
  • -1
    @ 2018-05-26 20:03:02
  • -1
    @ 2018-05-26 20:01:20

    err

  • -1
    @ 2007-11-13 09:03:25

    谁能给我看看第二个点??????

     答案:op(4,p)=(a*b*c*(a+b)*b(b+c)+a)

    我的:op(3,op(1,op(1,op(4,p))))=a

    我怎么多做了??哪位大牛解释一下?

  • -2
    @ 2012-07-14 20:43:13

    Orz没有换行的测试数据…………还以为纯模拟会有问题呢

  • -2
    @ 2010-04-08 17:36:56

    c++的应当注意输入的处理

  • -2
    @ 2009-10-04 13:12:25

    。。同stczhc。。

    c++囧到死了。。交了n次第三个点都超时。。。。orz

  • -2
    @ 2008-12-28 01:12:04

    郁闷~

  • -2
    @ 2008-10-21 13:35:29

    水题啊。。也就40来行。。注意细节。。千万别想复杂了。。

    可参见lsw19910317大牛的题解

  • -3
    @ 2014-08-18 06:44:19
    
    //}/* .................................................................................................................................. */
    
    const int N = int(1e5) + 9;
    
    string expr, name; VI I;
    int n;
    
    void out(int k){
        if (k == SZ(I)) cout << name;
        else{
            printf("op(%d,",I[k]);out(k+1);printf(")");
        }
    }
    
    int f(char c){
        if (c == '+') return 0;
        if (c == '*') return 1;
        if (c == '^') return 2;
        return 3;
    }
    
    
    void gao(int k, int l, int r){
        if (k == SZ(I)){
            FOR(i,l,r)putchar(expr[i]);puts("");
        }
        else{
    
            int c=0;char op='(';int ll;VII cut;
            FOR(i,l,r) if(expr[i]=='('){if (!c++)ll=i+1;}
            else if (expr[i]==')'){if (!--c)cut.PB(MP(ll,i));}
            else if (!c){
                if (f(expr[i])<f(op))op=expr[i];
            }
            if (op == '('){
                if (expr[l]=='(') gao(k+1,cut[I[k]].fi,cut[I[k]].se);
                else gao(SZ(I),l,r);
            }
            else{
                VII cut; FOR(i,l,r) if(expr[i]=='(')++c;
                else if (expr[i]==')')--c;
                else if (!c){
                    if (f(expr[i])==f(op))cut.PB(MP(l,i)),l=i+1;
                }
                cut.PB(MP(l,r));
                return gao(k+1,cut[I[k]].fi,cut[I[k]].se);
            }
        }
    }
    
    int main(){
    
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif
    
        while (cin >> expr){
            int p = expr.find(":="); name = expr.substr(0,p).c_str();
            printf("Expression %s:\n",name.c_str());expr.erase(expr.begin(),expr.begin()+p+2);
            Rush{
                string s; getline(cin, s); istringstream iss(s);
                CLR(I); int t; while (iss >> t) I.PB(t); RVS(I); out(0); RVS(I); ECH(it, I) --*it;
                putchar('='); gao(0, 0, SZ(expr));
                puts("");
            }
        }
    }
    

信息

ID
1017
难度
7
分类
字符串 点击显示
标签
(无)
递交数
682
已通过
116
通过率
17%
被复制
12
上传者