SGU 172 — eXam

Posted on 五月 27th, 2008.

这道题WindyWinter牛给出的算法是并查集,实际上可以DFS解决(感谢alft…).
每个人选的两个课程之间连无向边,然后DFS时进行黑白染色,DFS树上每个结点和他的父亲节点不同色.然后考虑横向边和返祖边,如果有一条边两边的结点颜色相同则说明无解,否则将白色的考试放在一天,黑色的放在另一天就可以了…并查集当然也没错…
注意会是一个森林,需要多次DFS…
{ SGU 172; eXam - sqybi’s code - DFS}//for my winstyprogram sgu172_sqybi;  const    nn = 200;    mm = 30000;
  var    n, m, tot, i, x, y, t: longint;    flag: boolean;    head, p: array[1..nn]of longint;    adj, next: array[-mm..mm]of longint;
  procedure addEdge(x, y: longint);    begin      inc(tot);      adj[tot] := y;      next[tot] := head[x];      head[x] := tot;      […]

Read Full Post | Make a Comment ( None so far )

SGU 181 — X-Sequence

Posted on 五月 25th, 2008.

其实真的不难…自己找一下规律吧.因为有mod m嘛…然后就几个一循环而已…
{ SGU 181; X-Sequence - sqybi’s code}//for my winstyprogram sgu181_sqybi;  const    mm = 1000;
  var    n, i: longint;    x, a, b, c, m, stop, r: int64;    f, t: array[0..mm]of longint;
  begin    readln(x, a, b, c, m, n);    if n = 0 then begin      writeln(x);      halt;    end;    fillchar(f, sizeof(f), 0);    stop := 0;    […]

Read Full Post | Make a Comment ( 5 so far )

SGU 169 — Numbers

Posted on 五月 25th, 2008.

bt的数学题.题解看这里:http://www.mydrs.org/dvp/dispbbs.php?boardid=13&id=436842楼说的还算比较详细…我刚开始把题目里P的定义的乘法看成了加法所以一直不懂2楼说的,后来看题之后才发现自己看错了…
{ SGU 169; Numbers - sqybi’s code - Maths}//for my winstyprogram sgu169_sqybi;  var    n, t: longint;
  begin    readln(n);    if n = 1 then      writeln(8)    else begin      t := 1;      if (n - 1) mod 3 = 0 then t := t + 2;      if (n - 1) mod 6 = 0 then t := […]

Read Full Post | Make a Comment ( None so far )

SGU 175 — Encoding

Posted on 五月 25th, 2008.

稍微推导一下就可以得到一个递推式(这里直接借用WindyWinter的式子):pos[1,1]=1pos[n,q]=n-k+pos[k,k-q+1] (q<=k)             =pos[n-k,n-q+1] (q>k)
求pos[n, q]即可.
{ SGU 175; Encoding - sqybi’s code}//for my winstyprogram sgu175_sqybi;  var    n, t, q, k: longint;
  begin    readln(n, q);    t := 0;    while n <> 1 do begin      k := n div 2;      if q <= k then begin        t := t + n - k;        n := k;        q […]

Read Full Post | Make a Comment ( 1 so far )

SGU 144 — Meeting

Posted on 五月 25th, 2008.

只说一句:图像法解决概率问题真好用.公式见程序.
{ SGU 144; Meeting - sqybi’s code - Maths}//for my winstyprogram sgu144_sqybi;  var    x, y, z: double;
  begin    readln(x, y, z);    writeln((1-sqr((y-x)*60-z)/sqr((y-x)*60)):0:7);  end.
阅读(122 次)

Read Full Post | Make a Comment ( None so far )

« Previous Entries Next Entries »

Liked it here?
Why not try sites on the blogroll...