天天看點

2010年10月21日 總結

額,今天一整天都好困的說...

于是隻有6道...還有不少水題、徹底的純粹的水題...

好的上題!

152 奶牛式乘法 142 拜年 370 區域網路 137 找試場 144 伯虎點秋香 224 手機 (為友善查閱,前面的序号是題号)   奶牛式乘法:純水之一,簡單的字元串處理 program rq152;

var

s,a,b:string;

i,j:longint;

ans:qword;

begin

readln(s);

a:=copy(s,1,pos(' ',s)-1);

b:=copy(s,pos(' ',s)+1,255);

for i:=1 to length(a) do

for j:=1 to length(b) do

inc(ans,(ord(a[i])-48)*(ord(b[j])-48));

writeln(ans);

end.

拜年:水題又一道,其實就是求最小生成樹,prim輕松AC program rq142;

var

map:array[1..100,1..100]of longint;

v:array[1..100]of boolean;

mincost:array[1..500]of longint;

s,i,j,k,n,m,tot,l,x,y,wm,min,p:longint;

begin

readln(n);

for i:=1 to n do

begin

for j:=1 to n do

read(map[i,j]);

readln;

end;

for i:=2 to n do mincost[i]:=maxlongint;

for i:=1 to n do

begin

min:=maxlongint;

for j:=1 to n do

if (mincost[j]<min)and not v[j]then

begin

min:=mincost[j];

p:=j;

end;

inc(tot,mincost[p]);

v[p]:=true;

for j:=1 to n do

if mincost[j]>map[p,j] then mincost[j]:=map[p,j];

end;

writeln(tot);

end.

區域網路:一句話題解,拆掉的網線數=總網線數-最小生成樹 program rq370;

var

i,j,k,n,fw,tw,len,min,total,sum:longint;

a:array[1..100,1..100]of longint;

mincost:array[1..100]of longint;

v:array[1..100]of boolean;

begin

readln(n,k);

sum:=0;

fillchar(a,sizeof(a),$3f);

for i:=1 to k do

begin

readln(fw,tw,len); inc(sum,len);

if len<>0 then

begin

a[fw,tw]:=len;

a[tw,fw]:=len;

end;

end;

v[1]:=true;

total:=0;

for i:=2 to n do

mincost[i]:=a[1,i];

for i:=2 to n do

begin

min:=maxlongint;

for j:=2 to n do

if (not(v[j]))and(mincost[j]<min) then

begin

min:=mincost[j];

k:=j;

end;

v[k]:=true; inc(total,min);

for j:=2 to n do

if (not(v[j]))and(mincost[j]>a[k,j]) then

mincost[j]:=a[k,j];

end;

writeln(sum-total);

end.

找試場:好吧雖然水,但是我是在夢境中做出來的(呀!夢遊了!),是以很羅嗦。記得最後如果沒動還要輸出(0,0)。 program rq137;

var

dir,z,n,i,code:longint;

s:string;

x,y:longint;

walked:boolean;

begin

readln(n);

walked:=false;

dir:=1;

for i:=1 to n do

begin

readln(s);

val(s,z,code);

if code=0 then

begin

walked:=true;

case dir of

{ up}1:inc(y,z);

{ left}2:dec(x,z);

{ down}3:dec(y,z);

{right}4:inc(x,z);

end;

writeln('(',x,',',y,')');

end

else

begin

if s='left'then inc(dir);

if s='right'then dec(dir);

if dir=0 then dir:=4;

if dir=5 then dir:=1;

end;

end;

if not walked then writeln('(0,0)');

end.

伯虎點秋香:好像今天做的全都是水題?冒泡+直接輸出...   program rq144;

var

n,i,j,k:longint;

t:string;

a:array[1..1000]of string;

begin

readln(n,k);

for i:=1 to n do

readln(a[i]);

for i:=1 to n do

for j:=i+1 to n do

if a[i]>a[j] then

begin

t:=a[i];

a[i]:=a[j];

a[j]:=t;

end;

writeln(a[k]);

end.

手機:作為今天的壓軸題...最短小精悍的程式華麗麗地登場了!   program rq224;

var

total,i:longint;

s:string;

begin

readln(s);

total:=0;

for i:=1 to length(s) do

case s[i] of

' ','a','d','g','j','m','p','t','w':inc(total);

'b','e','h','k','n','q','u','x':inc(total,2);

'c','f','i','l','o','r','v','y':inc(total,3);

's','z':inc(total,4);

end;

writeln(total);

end.

 結束了,昨天的那個歸并排序還沒弄,隻好等到明天了XD 2010年10月21日23:29:46

繼續閱讀