2008年12月6日星期六

A nice course on Tilings and Patterns

Recently, I found a course fund by University of Turku in Finland, which the porfessor offers a course concerntrates on tilings and patterns, which is very interesting, there are all homeworks available on the hompage of that course, but I can not found any other handout or other useful sources about it. but i still recommend this course.



http://users.utu.fi/jkari/tilings/

2008年11月16日星期日

CrackMe! A nice challenge

Crack Me is a fun cracker game! I'd try to invent a uncrackable CM.

2008年10月12日星期日

第一次用Functional Language Ruby-Smalltalk 变种 完成了SPOJ的第一题

第一次用Functional Language Ruby-Smalltalk 变种 完成了SPOJ的第一题
真费劲,又转了一个语言
val=gets
i=1
while val.chomp.to_i != 42
if i==1
puts "#{val}"
i+=1
end
val= gets
if val.chomp.to_i != 42
puts "#{val}"
end
end

2008年9月28日星期日

Using Mathematica(New kind of science) to crack EulerProject.org

Using Mathematica(New kind of science) to crack EulerProject.org

2008年9月27日星期六

First TopCoder Program (SRM 291 DIV II)

I am still confused about string and vector and how to calculate the score( I got 95 out of 250, but why?).....I won't give up.
PS: it's really painful to change Pascal to C++. It's ulgy to dispaly my code in Blogger...

#include

class FarFromPrimes{
public:

int count(int A, int B);
{
int s[100000];
int flag;
int ans=0;
for (int i=0;i<=100000;i++)
s[i]=0;
for (int i=2;i<=317;i++)
{
if (s[i]==0)
{
for (int j=2;j<=100000/i;j++)
s[i*j]=1;
}
}
for (int i=A;i<=B;i++)
{
flag=0;
for (int j=i-10;j<=i+10;j++)
if (s[j]==0)
{
flag=1;
break;
}
if (flag==0)
ans++;
}
return ans;
}
}

2008年9月12日星期五

Life Check List

1. Make a Nuclear Fusion Reactor 2. Code a Operating System or Programming Language 3. U TRIZ 4. U Dynamic Programming 5. U Ludwig Wittgenstein at his logical level 6. Abolish English + U English 7. Develop Anti-Symbolic Meta-Mathematics 8. U ENIAC(speclize of Electric Engineering), Make a Chipset 9. Develop Biomimic 2.1. U AVL inside Linux 写一段相声 Pure Online Judge about Dynamic Programming

2008年8月17日星期日

First Time Splay Tree for PKU 2761

First Time Splay Tree for PKU 2761


var
tmp,data,father,size,ans,num:array[0..100000] of longint;
t:array[0..50000,1..3] of longint;
i,j,m,n,root,node:longint;
son:array[0..1,0..100000] of longint;
procedure Qsort(s,l:longint);
var i,j,mid,tmp:longint;
begin
i:=s; j:=l; mid:=t[(i+j) div 2,1];
repeat
while (t[i,1]<mid) do i:=i+1;
while (t[j,1]>mid) do j:=j-1;
if i<=j then
begin
tmp:=t[i,1];
t[i,1]:=t[j,1];
t[j,1]:=tmp;
tmp:=t[i,2];
t[i,2]:=t[j,2];
t[j,2]:=tmp;
tmp:=t[i,3];
t[i,3]:=t[j,3];
t[j,3]:=tmp;
tmp:=num[i];
num[i]:=num[j];
num[j]:=tmp;
inc(i);
dec(j);
end;
until i>j;
if s<j then Qsort(s,j);
if i<l then Qsort(i,l);
end;
Procedure update(x:longint);
begin
size[x]:=size[son[0,x]]+size[son[1,x]]+1;
end;
Procedure Lrot(x:longint);
var y:longint;
begin
y:=father[x];
son[1,y]:=son[0,x];
if son[0,x]<>0 then
begin
father[son[0,x]]:=y;
end;
father[x]:=father[y];
if father[y]<>0 then
begin
if son[0,father[y]]=y then
begin
son[0,father[y]]:=x;
end
else
begin
son[1,father[y]]:=x;
end;
end;
son[0,x]:=y;
father[y]:=x;
update(y);
update(x);
end;
Procedure Rrot(x:longint);
var y:longint;
begin
y:=father[x];
son[0,y]:=son[1,x];
if son[1,x]<>0 then
begin
father[son[1,x]]:=y;
end;
father[x]:=father[y];
if father[y]<>0 then
begin
if son[0,father[y]]=y then
begin
son[0,father[y]]:=x;
end
else
begin
son[1,father[y]]:=x;
end;
end;
son[1,x]:=y;
father[y]:=x;
update(y);
update(x);
end;
Procedure splay(x,y:longint);
begin
while father[x]<>y do
begin
if father[father[x]]=y then
begin
if x=son[0,father[x]] then
begin
Rrot(x);
end
else
begin
Lrot(x);
end;
end
else
if father[x]=son[0,father[father[x]]] then
begin
if x=son[0,father[x]] then
begin
Rrot(father[x]);
Rrot(x);
end
else
begin
Lrot(x);
Rrot(x);
end;
end
else
begin
if x=son[1,father[x]] then
begin
Lrot(father[x]);
Lrot(x);
end
else
begin
Rrot(x);
LRot(x);
end;
end;
if y=0 then
root:=x;
end;
end;
Procedure addnode(x,y,z:longint);
begin
data[x]:=z;
father[x]:=y;
son[0,x]:=0;
son[1,x]:=0;
size[x]:=1;
end;
Procedure init;
begin
root:=0;
node:=0;
end;
Procedure ins(k:longint);
var y:longint;
begin
if root=0 then
begin
root:=1;
node:=1;
addnode(1,0,k);
exit;
end;
y:=root;
repeat
inc(size[y]);
if k<data[y] then
begin
if son[0,y]<>0 then
y:=son[0,y]
else
begin
inc(node);
addnode(node,y,k);
son[0,y]:=node;
y:=node;
break;
end;
end
else
begin
if son[1,y]<>0 then
y:=son[1,y]
else
begin
inc(node);
addnode(node,y,k);
son[1,y]:=node;
y:=node;
break;
end;
end;
until false;
splay(y,0);
end;
function rank(x:longint):longint;
var y:longint;
begin
y:=root;
while true do begin
if x<=size[son[0,y]] then
y:=son[0,y]
else
if x=size[son[0,y]]+1 then break
else begin
x:=x-size[son[0,y]]-1;
y:=son[1,y];
end;

end;
rank:=data[y];
splay(y,0);
end;
function find(x:longint):longint;
var
y: longint;
begin
y := root;
repeat
if data[y] = x then break;
if x < data[y] then begin
if son[0, y] = 0 then
break
else
y := son[0, y];
end
else begin
if son[1, y] = 0 then
break
else
y := son[1, y];
end;
until false;
find:= y;
splay(y, 0);
end;
Procedure del(x:longint);
var y,z:longint;
begin
y:= find(x);
splay(y, 0);
if son[0, y] = 0 then begin
if son[1, y] = 0 then
init
else begin
root := son[1, y];
father[son[1, y]] := 0;
end;
end
else begin
z := son[0, y];
while son[1, z] <> 0 do z := son[1, z];
splay(z, y);
son[1, z] := son[1, y];
if son[1, y] <> 0 then father[son[1, y]] := z;
father[z] := 0;
root := z;
update(z);
end;
end;
begin
readln(n,m);
init;
for i:=1 to n do
begin
read(tmp[i]);
end;
for j:=1 to m do
begin
readln(t[j,1],t[j,2],t[j,3]);
num[j]:=j;
end;
Qsort(1,m);
for i:=t[1,1] to t[1,2] do
begin
ins(tmp[i]);
end;
ans[num[1]]:=rank(t[1,3]);
for j:=2 to m do
begin
if t[j-1,2]<t[j,1] then
for i:=t[j-1,1] to t[j-1,2] do
begin
del(tmp[i]);
end
else
for i:=t[j-1,1] to t[j,1]-1 do
del(tmp[i]);
if t[j-1,2]<t[j,1] then begin
for i:=t[j,1] to t[j,2] do
begin
ins(tmp[i]);
end;
end
else
begin
for i:=t[j-1,2]+1 to t[j,2] do
begin
ins(tmp[i]);
end;

end;
ans[num[j]]:=rank(t[j,3]);
end;
for i:=1 to m do
begin
write(ans[i]);
end;
end.