首页 > vijos > vijos_1095

vijos_1095

2009年11月5日 moradin 发表评论 阅读评论

约瑟夫问题10E100版-60min-数论,高精度

Hint

1、23点后应该睡觉
2、2*n+1写成2*n-1
3、伪高精度不够熟练
4、n=1时输出1
4、约瑟夫问题的二进制解法,将第一位移到最后一位(9=1001,输出0011=3)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
type arr=array[0..100] of integer;
var f,ok,p,t,k,i,j:longint;
    s:string;
    a:array[0..332] of arr;
    b,b1:arr;
    c:array[1..100] of integer;
begin
  fillchar(a,sizeof(a),0);
  a[0,0]:=1;
  a[0,1]:=1;
  for i:=1 to 332 do begin
    p:=0;
    a[i,0]:=a[i-1,0];
    for j:=1 to a[i-1,0] do begin
      t:=a[i-1,j]*2;
      inc(a[i,j],t mod 10);
      inc(a[i,j],p);
      p:=t div 10;
    end;
    if p<>0 then begin
      inc(a[i,0]);
      a[i,a[i,0]]:=p;
    end;
    c[a[i,0]]:=i;
  end;
  readln(s);
  b[0]:=length(s);
  for i:=1 to b[0] do val(s[i],b[b[0]-i+1],ok);
  for i:=c[b[0]] downto 1 do begin
    f:=0;
    for j:=b[0] downto 1 do
      if b[j]>a[i,j]
        then begin
               f:=1;
               break;
             end
        else
          if b[j]=a[i,j]
            then continue
            else begin
                   f:=2;
                   break;
                 end;
    case f of
      1   :begin
             for k:=1 to j do begin
               if b[k]<0
                 then begin
                        dec(b[k+1]);
                        inc(b[k],10);
                      end;
               b1[k]:=b[k]-a[i,k];
               if b1[k]<0
                 then begin
                        inc(b1[k],10);
                        dec(b[k+1]);
                      end;
             end;
             b1[0]:=j;
             if b1[j]=0 then dec(b1[0]);
             str(i,s);
             fillchar(b,sizeof(b),0);
             b[0]:=length(s);
             t:=0;
             for j:=b[0] downto 1 do begin
               val(s[j],b[b[0]-j+1],ok);
               inc(b1[j],b[j]);
               if b1[j]>10
                 then begin
                        inc(b1[j+1]);
                        dec(b1[j],10);
                      end
             end;
             if b1[b1[0]+1]<>0 then inc(b1[0]);
             for j:=b1[0] downto 1 do write(b1[j]);
             writeln;
             halt;
           end;
      0   :begin
             writeln(s);
             halt;
           end;
      end;
  end;
end.

编译通过…
├ 测试数据 01:答案正确… 0ms
├ 测试数据 02:答案正确… 0ms
├ 测试数据 03:答案正确… 0ms
├ 测试数据 04:答案正确… 0ms
├ 测试数据 05:答案正确… 0ms
├ 测试数据 06:答案正确… 0ms
├ 测试数据 07:答案正确… 0ms
├ 测试数据 08:答案正确… 0ms
├ 测试数据 09:答案正确… 0ms
├ 测试数据 10:答案正确… 0ms
————————-
Accepted 有效得分:100 有效耗时:0ms

分类: vijos 标签: , , ,
  1. 2009年11月5日22:10 | #1

    约瑟夫问题的二进制解法,将第一位移到最后一位(9=1001,输出0011=3)

    Orz……………………………………………………………………

  2. 2009年11月5日22:11 | #2

    @Wandsea
    想想好有道理啊….=.=

  3. moradin
    2009年11月5日22:41 | #3

    @Wandsea 好像就是利用奇数和2次幂的关系?

  1. 本文目前尚无任何 trackbacks 和 pingbacks.
评论头像:请点击注册,可用于所有wordpress的评论
注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。