/ Vijos / 题库 / 划分 /

题解

30 条题解

  • -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("");
            }
        }
    }
    
  • -3
    @ 2013-02-16 10:12:29
    • @ 2019-08-13 17:08:57

      妈的还有权限,这就是让人强行加好友,差评!

  • -3
    @ 2009-09-04 15:26:10

    cheat 万岁

  • -3
    @ 2009-08-11 10:52:48

    一次AC

    没想像中的那么麻烦

  • -3
    @ 2009-08-06 21:50:40

    没有(a+b)(c+d)的情况......

    幸好我抱着试试的态度交了,不然又要再写半天

  • -3
    @ 2009-08-03 12:02:43

    第三个测试数据,

    输入文件末尾居然没有换行符...

  • -3
    @ 2009-05-02 23:25:06

    话说看到此题时刚好100人通过……没心情做第101个了……留名纪念……此楼勿删,谢谢

    Flag   Accepted

    题号   P1017

    类型(?)   其它

    通过   101人

    提交   458次

    通过率   22%

    难度   2

    想好不做第101个的,结果还是把这题做了……结果就是101个了……诶……水题啊……

  • -3
    @ 2009-04-09 21:20:17

    在网上找到一个AC程序..

    运行

    P:=(A+B)(C+D)

    1

    1

    输出B)(C

    ....验证发现..注:在本题中认为(a+b)(b+c)为合法表达式,若p:=(a+b)(b+c)则op(1,p)=a+b;而p:=(a+b)+(b+c)则op(1,p)=(a+b)

    标准费话...

  • -3
    @ 2009-02-25 19:26:15

    一点小hints:

    1.op(1,'(a+b)(c+d)')=a+b

    而op(1,'(a+b)*(c+d)')=(a+b)

    2.存在 sdfasdf:=之类的 也就是不一定是一个字符'p'

  • -3
    @ 2006-12-01 23:22:25

    同意楼上,果然是简单题,建议大家花点耐心看题就知道了,还有就是细节很重要,除了楼上说的还有括号的处理(去括号算一次处理啊!!!).

    具体算法可以参考小学的运算口则:"先乘除,后加减,同级运算先算前,有括号要先算……"那么这题就只要给每个运算符加上优先级就好,'+'是1,'*'是2,'^'是3,'('')'之间的包括自己都加4 其他的就是递归处理了.

    这题通过人数比较少,我就把通过的一瞬间给大家分享把.

    From Tsuzuki

    划分

    编译通过...

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

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

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

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

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

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

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

信息

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