回 帖 发 新 帖 刷新版面

主题:难题(2)

题目:
    不等式的解
    给出一些不等式,求其公共解集.
    注意:表达方式:x<3表示为(-,3)(“-”号表示无穷小,且不要表示为 (3,-),其左边只能用'(',下同)x<=3表示为(-,3].x>3表示为(3,+),x>=3表示为[3,+)("+"表示无穷大,其右边只能用")')1<=x<=3表示为[1,3].对于每一组数据,肯定有解.
    "或"的表示:1<=x<3或x>5表示为:[1,3) (5,+)
    输入数据第一行为n,表示有n个不等式(组)
    以下n行为不等式(组)
    输出数据为公共解集,重复的只输出一个,且最后的解集后面不要有多余空格,每个解集之间只要有一个空格.
    样例:
    Input:
    3
    [1,10) [3,11] (5,+)
    (-10,11]
    (0,7) (-1,8]
    Output:
    [1,7) [1,8] [3,7) [3,8] (5,7) (5,8]

回复列表 (共21个回复)

11 楼


Program ss;
  const maxn=100;
  type
     node=record
         data1,data2:integer;
         s1,s2:string;
         l1,l2:0..1;
     end;
     arr=array[1..maxn,1..maxn]of node;
     arr2=array[1..maxn]of node;
  var
     a:arr;
     p:array[1..maxn]of integer;
     n:integer;
  procedure init;
    var
       i,j,l,k,x,ff:integer;
       st,st1,st2:string;
       ch:char;
    begin
       readln(n);
       for i:=1 to n do
         begin
           readln(st);
           j:=1;l:=0;
           while j<=length(st) do
             begin
               st1:='';
               while (st[j]<>' ')and(j<=length(st))do
                 begin
                   st1:=st1+st[j];
                   inc(j);
                 end;
               inc(l);inc(j);
               ch:=st1[1];
               case ch of
                 '(':a[i,l].l1:=0;
                 '[':a[i,l].l1:=1;
               end;
               delete(st1,1,1);
               k:=1; st2:='';
               while st1[k]<>',' do
                 begin
                   st2:=st2+st1[k];
                   inc(k);
                 end;
               if st2='-' then a[i,l].s1:='-'
                   else begin
                     val(st2,x,ff);
                     a[i,l].data1:=x;
                     end;
               inc(k);st2:='';
               while (st1[k]<>')')and(st1[k]<>']') do
                 begin
                   st2:=st2+st1[k];
                   inc(k);
                 end;
               if st2='+' then a[i,l].s2:='+'
                 else begin
                   val(st2,x,ff);
                   a[i,l].data2:=x;
                 end;
               inc(k);
               case st1[k] of
                 ')':a[i,l].l2:=0;
                 ']':a[i,l].l2:=1;
               end;
             end;
           p[i]:=l;
         end;
    end;

12 楼

{继续}
  procedure di(s:arr2);
    var
       i:integer;
       bb:node;
    begin
       bb.s1:='-';
       bb.s2:='+';
       bb.l1:=0;bb.l2:=0;
       for i:=1 to n do
         begin
           if (bb.s1='-')and(s[i].s1='')then begin
                  bb.s1:='';bb.data1:=s[i].data1;
                  bb.l1:=s[i].l1;end
               else if bb.s1<>'-' then begin
                 if s[i].data1>bb.data1 then begin
                      bb.data1:=s[i].data1;
                      bb.l1:=s[i].l1;
                       end;
                 if s[i].data1=bb.data1 then
                       if (bb.l1=1)and(s[i].l1=0)then bb.l1:=0;
                 end;
           if (bb.s2='+')and(s[i].s2='')then begin
                  bb.s2:='';bb.data2:=s[i].data2;
                  bb.l2:=s[i].l2;end
               else if bb.s2<>'+' then begin
                 if s[i].data2<bb.data2 then begin
                       bb.data2:=s[i].data2;
                       bb.l2:=s[i].l2;
                        end;
                 if s[i].data2=bb.data2 then
                       if (bb.l2=1)and(s[i].l2=0)then bb.l1:=0;
                 end;
           if i<>1 then write(' ');
         end;
       case bb.l1 of
         1:write('[');
         0:write('(');
       end;
       if bb.s1='-' then write(bb.s1,',')
          else
            write(bb.data1,',');
       if bb.s2='+' then write(bb.s2)
              else write(bb.data2);
       case bb.l2 of
         0:write(')');
         1:write(']');
       end;

    end;
  procedure work;
    var
       t:array[1..maxn]of integer;
       s:arr2;
       i,j:integer;
    begin
       for i:=1 to n do
         t[i]:=1;
       while true do
         begin
           for i:=1 to n do
               s[i]:=a[i,t[i]];
           di(s);
           i:=n;
           while (i>=1)and(t[i]=p[i])do
             dec(i);
           if i=0 then exit;
           t[i]:=t[i]+1;
           for j:=i+1 to n do t[j]:=1;
         end;
    end;

  begin
     init;
     work;
end.

13 楼


给分拉!!

14 楼

try一下........

15 楼

不错.但是要判断一下:有(x,x)这种情况吗?!
输出时要注意....!!!

16 楼

[em8][em8]不好意思,那就修改一下,在输出时判断一下:

if s[i],data1<>s[i].data2 then {打印}

17 楼

good

18 楼


晕掉!

你是考我还是问我啊?

19 楼

xxxxxx

20 楼


begin
  while true do
    writeln('xxxxxx');
end.

我来回复

您尚未登录,请登录后再回复。点此登录或注册