题解

180 条题解

  • 0
    @ 2009-10-21 20:47:16

    题目的测试数据好像和当年复赛时的数据不同,

    被改弱了,导致我一次AC

    括号不匹配的情况好像被删掉了。。。

  • 0
    @ 2009-10-20 20:30:16

    var

    i,j,k,n,m,number,ta,tb:longint;

    a,a1:array[0..26] of string;

    bool:array[0..26] of boolean;

    sa:array[0..100]of extended;

    sb:array[0..100]of char;

    pre:extended;

    function Get(ch:char):longint;

    var t:longint;

    begin

    case ch of

    '(':t:=0;

    ')':t:=1;

    '+','-':t:=2;

    '*':t:=3;

    '^':t:=4;

    end;

    exit(t);

    end;

    procedure PushA(t:extended);

    begin

    inc(ta); sa[ta]:=t;

    end;

    procedure PushB(ch:char);

    begin

    inc(tb); sb[tb]:=ch;

    end;

    function PopA:extended;

    begin

    PopA:=sa[ta]; dec(ta);

    end;

    function PopB:char;

    begin

    PopB:=sb[tb]; dec(tb);

    end;

    function Pow(x1,x2:extended):extended;

    var i:longint; t:extended;

    begin

    t:=1;

    for i:=1 to trunc(x2) do

    t:=t*x1;

    exit(t);

    end;

    function Calc(s:string; number:longint):extended;

    var i,j,k,now,many:longint;

    ch:char;

    x1,x2,x3:extended;

    begin

    ta:=0; tb:=0;

    s:='('+s+')';

    i:=1;

    many:=0;

    while i

  • 0
    @ 2009-10-19 22:13:32

    program mm;

    var

    s,s1:string;

    ch:char;

    sa:array[0..1000] of longint;

    sb:array[0..1000] of char;

    ta,tb,x1,x2,i,j,k,l,m,n,x,y,z,plus:longint;

    function jisuan(pp:char):longint;

    begin

    case pp of

    '+':jisuan:=2;

    '-':jisuan:=2;

    '*':jisuan:=3;

    '^':jisuan:=4;

    '(':jisuan:=0;

    ')':jisuan:=1;

    end;

    end;

    begin

    readln(s);

    s:='('+s+')';

    i:=1;

    ta:=0;

    tb:=0;

    while i=jisuan(s[i]) do begin

    x1:=sa[ta];

    dec(ta);

    x2:=sa[ta];

    dec(ta);

    plus:=0;

    case ch of

    '+':plus:=x1+x2;

    '-':plus:=x2-x1;

    '*':plus:=x1*x2;

    '^':begin

    plus:=1;

    for i:=1 to x1 do

    plus:=plus*x2;

    end;

    end;

    inc(ta);

    sa[ta]:=plus;

    ch:=sb[tb];

    dec(tb);

    end;

    if (s[i]')') or (ch'(') then begin

    zxc inc(tb);

    sb[tb]:=ch;

    end;

    if s[i]')' then begin

    inc(tb);

    sb[tb]:=s[i];

    end;

    inc(i);

    end;

    writeln(sa[1]);

    end.

    不错的题

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-10-11 13:48:01

     这个题目手算很麻烦,因为明明对计算机编程很感兴趣,所以他想是不是可以用计算机来解决这个问题。...

  • 0
    @ 2009-10-11 13:13:21

    WA了5次总算AC了

    用堆栈对每个表达式进行处理

    每个运算符都有优先度 优先度大则进栈 小则进行运算

    还有一些细节要恨仔细

    真不愧是第4题啊

    ---|---|---|---|---|---|---|---|---|--晒程序---|---|---|---|---|---|---|---|---|---|-

    program p1003;

    var

    b:boolean;

    c:char;

    a:array[0..26]of string;

    start:string;

    i,j,n:longint;

    function getout(x:char):integer;

    begin

    case x of

    '!':exit(-1);

    '+','-':exit(1);

    '*','/':exit(3);

    '^':exit(5);

    '(':exit(8);

    ')':exit(0);

    end;

    end;

    function getin(x:char):integer;

    begin

    case x of

    '!':exit(-1);

    '+','-':exit(2);

    '*','/':exit(4);

    '^':exit(6);

    '(':exit(0);

    ')':exit(8);

    end;

    end;

    function calculate(x1,x2:int64;x:char):int64;

    var

    i,j:int64;

    begin

    case x of

    '+':exit((x1+x2));

    '-':exit((x1-x2));

    '*':exit((x1*x2));

    '^':begin

    j:=1;

    i:=1;

    while i

  • 0
    @ 2009-10-11 11:07:29

    vijos怎么偷数据????????????????????????????????????????????????????????????????????

  • 0
    @ 2009-10-07 19:03:41

    额...怎么少这么多括号

    不知当然NOIP人们这题考的怎么样……

  • 0
    @ 2009-10-23 19:05:50

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    Flag   Accepted

    题号   P1003

    类型(?)   字符串处理

    通过   1437人

    提交   5860次

    通过率   25%

    难度   2

    program deng_jia_biao_da_shi;

    const

    maxn=250;

    maxk=30;

    tempa:array[1..4]of longint=(-1,0,1,2);

    fin='e:\bp\djbds.in';

    var

    ope:array[0..maxn]of char;

    num:array[1..maxn]of longint;{two stack}

    answer:array[1..4]of longint;

    itis:array[1..maxk]of boolean;

    i,j,k,t,temp :longint;

    top1,top2,x1,x2 :longint;

    ss :string;

    l :longint;

    c :char;

    ns,no :longint;

    procedure init;

    var i,g:longint;

    ts:string;

    begin

    readln(ss);

    l:=length(ss);ts:='';

    for i:=1 to l do

    if ss[i]' ' then

    ts:=ts+ss[i];

    ss:=ts;{kill the spaces}

    repeat

    g:=0;l:=length(ss);

    for i:=1 to l do

    begin

    if ss[i]='(' then inc(g)

    else if ss[i]=')' then

    begin

    dec(g);

    if g=2 do

    begin

    x2:=num[top2];

    dec(top2);

    x1:=num[top2];

    num[top2]:=calc(x1,x2,ope[top1]);

    dec(top1);

    end;

    answer[temp]:=num[top2];

    end;

    for no:=1 to ns do

    begin

    init;

    for temp:=1 to 4 do

    begin

    for i:=1 to maxn do

    begin

    num[i]:=0;

    ope[i]:=' ';

    end;

    ope[0]:='@';

    top1:=0;

    top2:=0;

    ss:=ss+'@';

    i:=1;

    j:=1;

    c:=ss[i];

    while c'@' do

    begin

    if c = 'a' then

    begin

    inc(top2);

    num[top2]:=tempa[temp];

    end

    else if c in ['0'..'9'] then

    begin

    inc(top2);

    num[top2]:=ord(c)-ord('0');

    while ss in ['0'..'9'] do

    begin

    inc(i);

    num[top2]:=num[top2]*10+ord(ss[i])-ord('0');

    end;

    end

    else if c in ['+','-','*','^']then

    begin

    while prio(c)=2 then

    begin

    x2:=num[top2];

    dec(top2);

    x1:=num[top2];

    num[top2]:=calc(x1,x2,ope[top1]);

    dec(top1);

    end;

    end;

    inc(top1);

    ope[top1]:=c;

    end

    else if c='(' then

    begin

    inc(top1);

    ope[top1]:=c;

    end

    else if c=')' then

    begin

    while ope[top1]'('do

    begin

    if top2>=2 then

    begin

    x2:=num[top2];

    dec(top2);

    x1:=num[top2];

    num[top2]:=calc(x1,x2,ope[top1]);

    dec(top1);

    end;

    end;

    ope[top1]:=' ';

    dec(top1);

    end;

    inc(i);

    c:=ss[i];

    end;

    while top2>=2 do

    begin

    x2:=num[top2];

    dec(top2);

    x1:=num[top2];

    num[top2]:=calc(x1,x2,ope[top1]);

    dec(top1);

    end;

    if num[top2]=answer[temp]then itis[no]:=true

    else

    begin

    itis[no]:=false;

    break;

    end;

    end;

    end;

    for no:=1 to ns do

    if itis[no] then write(chr(no+ord('A')-1));

    close(input);

    end.

    {看注释}

  • 0
    @ 2009-10-03 23:20:19

    我蛋疼,我光荣

  • 0
    @ 2009-07-28 11:10:40

    这道题令人吐血,还是递归做比较方便,也很简捷

    括号这种事情……

  • 0
    @ 2009-07-26 11:20:35

    HOHOHO~~~~~复制不需删空格哦

    #include

    using namespace std;

    int s,s0,s1;

    void input(char c[],int f[],int p[],int k)

    {

    char c0[201],c1[201];

    int i,l;

    s=0;s0=-1;s1=-1;

    for (i=0;i=1)

    {

    la--;

    lb++;

    bp[lb]=a[la+1];

    b[lb]=1;

    }

    la++;

    a[la]=p[i];

    }

    if (p[i]==-2)

    {

    while (a[la]!=-1&&la>=1)

    {

    la--;

    lb++;

    bp[lb]=a[la+1];

    b[lb]=1;

    }

    if (a[la]==-1) la--;

    }

    }

    }

    while (la>=1)

    {

    la--;

    lb++;

    bp[lb]=a[la+1];

    b[lb]=1;

    }

    int x,y,e;

    la=0;

    for (i=1;i

  • 0
    @ 2009-07-23 23:58:11

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    好奇怪...我没考虑左右括号不匹配啊 咋还过了?还居然秒杀?...

    话说自己测了半天不对...

    无语中...后来才发现是括号不匹配...

    对vijos ORZ

  • 0
    @ 2009-07-19 14:03:06

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    Flag    Accepted

    题号   P1003

    类型(?)   字符串处理

    通过   1200人

    提交   4900次

    通过率   24%

    难度   2

    提交 讨论 题解

    呀呀 纪念一下 O(∩_∩)O哈哈~( ⊙o⊙ )哇

  • 0
    @ 2009-07-16 20:29:50

    70分……忍无可忍,无需再忍,Just Cheat it!

  • 0
    @ 2009-08-26 16:15:55

    我无语了!

  • 0
    @ 2009-07-12 15:21:18

    猥琐死了

  • 0
    @ 2009-05-30 17:31:09

    用(1,2,3,4,5)测一下就行了

  • 0
    @ 2009-05-03 18:35:52

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

    郁闷…… 太恶心了 没注意效率 最后发现最后一组数据如果不是以1、2、-1、-2测试的话就会超时…… 如果以小数测试的话直接挂……

    括号不匹配太恶心了 恶心死了……恶心死了……恶心死了……

    • @ 2014-01-05 14:15:27

      请问括号不匹配是什么意思?

  • 0
    @ 2009-04-24 22:38:52

    第一次..

    记录号 Flag 得分 记录信息 环境 评测机 程序提交时间

    R1219415 Unaccepted 70 From zhengfangyi-

      P1003 FPC Vag 6K 2009-4-24 22:32:31

    From chp516

    等价表达式 全国青少年信息学奥林匹克分区联赛 (NOIp) 竞赛原题

    被过滤广告

    编译通过...

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

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

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

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

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

    ├ 测试数据 06:答案错误...程序输出比正确答案长

    ├ 测试数据 07:答案错误...程序输出比正确答案长

    ├ 测试数据 08:答案错误...程序输出比正确答案长

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

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

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

    Unaccepted 有效得分:70 有效耗时:0ms

    第二次

    记录号 Flag 得分 记录信息 环境 评测机 程序提交时间

    R1219415 Unaccepted 90 From zhengfangyi-

      P1003 FPC Vag 6K 2009-4-24 22:32:31

    From chp516

    等价表达式 全国青少年信息学奥林匹克分区联赛 (NOIp) 竞赛原题

    被过滤广告

    编译通过...

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

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

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

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

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

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

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

    ├ 测试数据 08:答案错误...程序输出比正确答案长

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

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

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

    Unaccepted 有效得分:90 有效耗时:0ms

    完全一样的程序..

    But .....

    在flag后面,出现了如下字样:

    Flag   Accepted

    题号   P1003

    类型(?)   字符串处理

    通过   1118人

    提交   4479次

    通过率   25%

    难度   2

    无语...

    竟然这样也能过

    下附我的猥琐程序

    type

    ayy=array[0..50] of integer;

    var

    n,i,k,j:longint;

    s:array[0..26] of string;

    x,ans,t,p:extended;

    z:array[0..26] of boolean;

    y:array[0..26] of ayy;

    l:array[0..26] of integer;

    procedure jin(k:integer);

    var

    i,base,jj:integer;

    begin

    base:=0;

    jj:=10;

    fillchar(y[k],sizeof(y[k]),127);

    for i:=1 to l[k] do

    begin

    case s[k][i] of

    '(':inc(base,15);

    ')':dec(base,15);

    '+','-':y[k][i]:=base+1;

    '*':y[k][i]:=base+2;

    '^':begin

    y[k][i]:=base+3+jj;

    dec(jj);

    end;

    end;

    end;

    end;

    function find(k,l,r:integer):integer;

    var

    i,min:integer;

    begin

    find:=0;

    min:=32638;

    for i:=r downto l do

    if y[k][i]

  • 0
    @ 2009-03-30 22:01:30

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    终于AC了!

    注意!!!

    1.先删去全部的空格

    2.右括号不匹配的情况,应删去无用括号,否则会出错,以下是删括号的过程

    procedure kuohao(var ss:string);

    var

    g,l:int64;

    i:longint;

    begin

    repeat

    g:=0;l:=length(ss);

    for i:=1 to l do begin

    if ss[i]='(' then inc(g)

    else

    if ss[i]=')' then begin

    dec(g);

    if g

信息

ID
1003
难度
7
分类
字符串 点击显示
标签
递交数
7413
已通过
1550
通过率
21%
被复制
50
上传者