德必信生活网

您现在的位置是:首页 > 生活资讯 > 正文

生活资讯

pascal游戏(pascalswager游戏)

阿信2023-04-02生活资讯66

今天给各位分享pascal游戏的知识,其中也会对pascalswager游戏进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

pascal超超超难题——石头剪子布游戏

int today=d.get(Calendar.DAY_OF_MONTH);

int month=d.get(Calendar.MONTH);

do {

int day=d.get(Calendar.DAY_OF_MONTH);

System.out.printf("%3d",day);

if(day==today){

System.out.print("*");

}else {

System.out.print(" ");

}

d.add(Calendar.DAY_OF_MONTH, 1);

weekday=d.get(Calendar.DAY_OF_WEEK);

if(weekday==firstDayOfWeek){

System.out.println("");

}

} while (d.get(Calendar.MONTH)==month);

pascal题目:游戏

这题也许是贪心算法的一个简单应用 。

一开始我是这么想的:

但是马上就推翻了这种简单的算法:

如果给第一个人7颗糖,第二个人3颗,那么生气指数是:

尽管上述看似对于解题没太大帮助,但是了解一个思考过程我觉得也是有必要的。

事实上,它启发了我找到下面这个应该正确的算法。

——————————————————————————————————————

36,比一开始的55小了很多。

事实上,经过验证,36是这一个例子中最小的结果。

(用以上算法验证一下样例,得到的也是正确答案)

贪心的算法一旦确定,代码应该就好写了。

目前摆在面前的一道坎,是数据范围。那么大的数,一个个减去一定会超时,因此用了一点技巧。

写了很久的代码,看一下:

var a:array[1..100000]of record

                                         x,y:longint;          //记录类型,x表示理想糖数,y表示实际收到糖数;

                                       end;

    s,ans:int64;

    m,n,i,j,t:longint;

procedure sort(l,r:longint);            //快速排序,从小到大;

var i,j,k,t:longint;

begin

 i:=l; j:=r; k:=a[(l+r) div 2].x;

 repeat

  while a[i].xk do inc(i);

  while a[j].xk do dec(j);

  if i=j then

  begin

   t:=a[i].x; a[i].x:=a[j].x; a[j].x:=t;

   inc(i); dec(j);

  end;

 until ij;

 if ir then sort(i,r);

 if lj then sort(l,j);

end;

begin

 readln(m,n);

 for i:=1 to n do

 begin

  readln(a[i].x);

  a[i].y:=a[i].x;

  inc(s,a[i].x);

 end;

 sort(1,n);

 for i:=1 to n do a[i].y:=a[i].x;

 i:=0;

 while true do

 begin

  inc(i);

  t:=a[i].y;

  while (s-t*(n-i+1)m) and (t0) do

   dec(t);

  dec(s,t*(n-i+1));

  if t0 then for j:=i to n do dec(a[j].y,t)

           else break;

 end;                                                          //代码核心;

 while sm do

 begin

  dec(a[i].y);

  inc(i);

  dec(s);

 end;

 for i:=1 to n do

  inc(ans,trunc(sqr(a[i].x-a[i].y)));

 writeln(ans);                                            //最终结果;

 readln;

end.

或者直接从附件中下载。

用pascal怎么做游戏啊

先送你一个猜数游戏:

program c_k;

var a,b,c:integer;

begin

randomize;

a:=random(100);

c:=0;

repeat

c:=c+1;

write('please input b:');

readln(b);

if ba then writeln('Too big')

else if ba then writeln('Too small')

else if b=a tehn writeln('you are right');

until (c=10) or (a=b);

if c=10 then writeln('you false,the number is:',a);

readln;readln;

end.

再送你一个坦克大战程序:

program tanke;

uses crt,graph;

type

type1=record

h,l,f:integer;

end;

time=record

ms,s,m:integer;

end;

const fx:array[1..4,1..2] of -1..1=((-1,0),(0,-1),(1,0),(0,1));

var t:time;

tank:type1;

bomb:array[1..20]of type1;

diren:array[1..8]of type1;

fire:array[1..20]of type1;

u,d,l,r,gu,gd,gl,gr:char;

lf:boolean;

procedure initg;

var gd,gm:integer;

begin

gd:=detect;

initgraph(gd,gm,'');

end;

procedure pushtype1(l,h,f:integer;var a:array of type1);

var i:integer;

begin

for i:=1 to high(a) do

if a[i].f=0 then

begin

a[i].h:=h;a[i].l:=l;a[i].f:=f;

exit;

end;

end;

procedure print;

var i,j:integer;

begin

setfillstyle(white,1);

bar(0,0,600,400);

for i:=1 to high(fire) do

with fire[i] do

if f0 then

begin

setcolor(red);

line(l*40-20,h*40-20,l*40-1,h*40-1);

line(l*40-20,h*40-20,l*40-1,h*40-10);

line(l*40-20,h*40-20,l*40-1,h*40-20);

line(l*40-20,h*40-20,l*40-1,h*40-30);

line(l*40-20,h*40-20,l*40-1,h*40-40);

line(l*40-20,h*40-20,l*40-40,h*40-1);

line(l*40-20,h*40-20,l*40-40,h*40-10);

line(l*40-20,h*40-20,l*40-40,h*40-20);

line(l*40-20,h*40-20,l*40-40,h*40-30);

line(l*40-20,h*40-20,l*40-40,h*40-40);

line(l*40-20,h*40-20,l*40-20,h*40-1);

line(l*40-20,h*40-20,l*40-30,h*40-1);

line(l*40-20,h*40-20,l*40-10,h*40-40);

line(l*40-20,h*40-20,l*40-10,h*40-1);

line(l*40-20,h*40-20,l*40-20,h*40-40);

line(l*40-20,h*40-20,l*40-30,h*40-40);

end;

for i:=1 to high(bomb) do

with bomb[i] do

if f0 then

begin

setcolor(blue);

circle((l-1)*40+20,(h-1)*40+20,5);

end;

for i:=1 to high(diren) do

with diren[i] do

if f0 then

begin

setcolor(11);

line((l-1)*40+5,(h-1)*40+1,(l-1)*40+15,(h-1)*40+10);

line((l-1)*40+15,(h-1)*40+10,(l-1)*40+10,(h-1)*40+15);

line((l-1)*40+10,(h-1)*40+15,(l-1)*40+1,(h-1)*40+5);

line((l-1)*40+1,(h-1)*40+5,(l-1)*40+5,(h-1)*40+1);

line((l-1)*40+35,(h-1)*40+1,(l-1)*40+25,(h-1)*40+10);

line((l-1)*40+25,(h-1)*40+10,(l-1)*40+30,(h-1)*40+15);

line((l-1)*40+30,(h-1)*40+15,(l-1)*40+40,(h-1)*40+5);

line((l-1)*40+40,(h-1)*40+5,(l-1)*40+35,(h-1)*40+1);

line((l-1)*40+5,(h-1)*40+40,(l-1)*40+15,(h-1)*40+30);

line((l-1)*40+15,(h-1)*40+30,(l-1)*40+10,(h-1)*40+25);

line((l-1)*40+10,(h-1)*40+25,(l-1)*40+1,(h-1)*40+35);

line((l-1)*40+1,(h-1)*40+35,(l-1)*40+5,(h-1)*40+40);

line((l-1)*40+35,(h-1)*40+40,(l-1)*40+25,(h-1)*40+30);

line((l-1)*40+25,(h-1)*40+30,(l-1)*40+30,(h-1)*40+25);

line((l-1)*40+30,(h-1)*40+25,(l-1)*40+40,(h-1)*40+35);

line((l-1)*40+40,(h-1)*40+35,(l-1)*40+35,(h-1)*40+40);

line((l-1)*40+15,(h-1)*40+10,(l-1)*40+25,(h-1)*40+10);

line((l-1)*40+30,(h-1)*40+15,(l-1)*40+30,(h-1)*40+25);

line((l-1)*40+10,(h-1)*40+15,(l-1)*40+15,(h-1)*40+25);

line((l-1)*40+15,(h-1)*40+30,(l-1)*40+25,(h-1)*40+30);

setcolor(red);

circle((l-1)*40+20,(h-1)*40+20,6);

end;

with tank do

begin

if f0 then setcolor(green)

else setcolor(red);

case f of

0,1:begin

setcolor(green);

line((l-1)*40+1,(h-1)*40+10,(l-1)*40+1,(h-1)*40+40);

line((l-1)*40+10,(h-1)*40+10,(l-1)*40+10,(h-1)*40+40);

line((l-1)*40+1,(h-1)*40+10,(l-1)*40+10,(h-1)*40+10);

line((l-1)*40+1,(h-1)*40+40,(l-1)*40+10,(h-1)*40+40);

line((l-1)*40+30,(h-1)*40+10,(l-1)*40+30,(h-1)*40+40);

line((l-1)*40+40,(h-1)*40+10,(l-1)*40+40,(h-1)*40+40);

line((l-1)*40+30,(h-1)*40+10,(l-1)*40+40,(h-1)*40+10);

line((l-1)*40+30,(h-1)*40+40,(l-1)*40+40,(h-1)*40+40);

line((l-1)*40+10,(h-1)*40+15,(l-1)*40+30,(h-1)*40+15);

line((l-1)*40+10,(h-1)*40+35,(l-1)*40+30,(h-1)*40+35);

line((l-1)*40+1,(h-1)*40+20,(l-1)*40+10,(h-1)*40+20);

line((l-1)*40+1,(h-1)*40+30,(l-1)*40+10,(h-1)*40+30);

line((l-1)*40+30,(h-1)*40+20,(l-1)*40+40,(h-1)*40+20);

line((l-1)*40+30,(h-1)*40+30,(l-1)*40+40,(h-1)*40+30);

line((l-1)*40+15,(h-1)*40+1,(l-1)*40+25,(h-1)*40+1);

line((l-1)*40+15,(h-1)*40+1,(l-1)*40+15,(h-1)*40+15);

line((l-1)*40+25,(h-1)*40+1,(l-1)*40+25,(h-1)*40+15);

circle((l-1)*40+20,(h-1)*40+25,5);

end;

2:begin

line((l-1)*40+10,(h-1)*40+1,(l-1)*40+40,(h-1)*40+1);

line((l-1)*40+10,(h-1)*40+10,(l-1)*40+40,(h-1)*40+10);

line((l-1)*40+10,(h-1)*40+1,(l-1)*40+10,(h-1)*40+10);

line((l-1)*40+40,(h-1)*40+1,(l-1)*40+40,(h-1)*40+10);

line((l-1)*40+10,(h-1)*40+30,(l-1)*40+40,(h-1)*40+30);

line((l-1)*40+10,(h-1)*40+40,(l-1)*40+40,(h-1)*40+40);

line((l-1)*40+10,(h-1)*40+30,(l-1)*40+10,(h-1)*40+40);

line((l-1)*40+40,(h-1)*40+30,(l-1)*40+40,(h-1)*40+40);

line((l-1)*40+15,(h-1)*40+10,(l-1)*40+15,(h-1)*40+30);

line((l-1)*40+35,(h-1)*40+10,(l-1)*40+35,(h-1)*40+30);

line((l-1)*40+20,(h-1)*40+1,(l-1)*40+20,(h-1)*40+10);

line((l-1)*40+30,(h-1)*40+1,(l-1)*40+30,(h-1)*40+10);

line((l-1)*40+20,(h-1)*40+30,(l-1)*40+20,(h-1)*40+40);

line((l-1)*40+30,(h-1)*40+30,(l-1)*40+30,(h-1)*40+40);

line((l-1)*40+1,(h-1)*40+15,(l-1)*40+1,(h-1)*40+25);

line((l-1)*40+1,(h-1)*40+15,(l-1)*40+15,(h-1)*40+15);

line((l-1)*40+1,(h-1)*40+25,(l-1)*40+15,(h-1)*40+25);

circle((l-1)*40+25,(h-1)*40+20,5);

end;

3:begin

setcolor(green);

line((l-1)*40+40,(h-1)*40+30,(l-1)*40+40,(h-1)*40+1);

line((l-1)*40+30,(h-1)*40+30,(l-1)*40+30,(h-1)*40+1);

line((l-1)*40+40,(h-1)*40+30,(l-1)*40+30,(h-1)*40+30);

line((l-1)*40+40,(h-1)*40+1,(l-1)*40+30,(h-1)*40+1);

line((l-1)*40+40,(h-1)*40+1,(l-1)*40+30,(h-1)*40+1);

line((l-1)*40+10,(h-1)*40+30,(l-1)*40+10,(h-1)*40+1);

line((l-1)*40+1,(h-1)*40+30,(l-1)*40+1,(h-1)*40+1);

line((l-1)*40+10,(h-1)*40+30,(l-1)*40+1,(h-1)*40+30);

line((l-1)*40+10,(h-1)*40+1,(l-1)*40+1,(h-1)*40+1);

line((l-1)*40+30,(h-1)*40+25,(l-1)*40+10,(h-1)*40+25);

line((l-1)*40+30,(h-1)*40+25,(l-1)*40+10,(h-1)*40+25);

line((l-1)*40+30,(h-1)*40+5,(l-1)*40+10,(h-1)*40+5);

line((l-1)*40+40,(h-1)*40+20,(l-1)*40+30,(h-1)*40+20);

line((l-1)*40+40,(h-1)*40+10,(l-1)*40+30,(h-1)*40+10);

line((l-1)*40+10,(h-1)*40+20,(l-1)*40+1,(h-1)*40+20);

line((l-1)*40+10,(h-1)*40+10,(l-1)*40+1,(h-1)*40+10);

line((l-1)*40+25,(h-1)*40+40,(l-1)*40+15,(h-1)*40+40);

line((l-1)*40+25,(h-1)*40+40,(l-1)*40+25,(h-1)*40+25);

line((l-1)*40+15,(h-1)*40+40,(l-1)*40+15,(h-1)*40+25);

circle((l-1)*40+20,(h-1)*40+15,5);

end;

4:begin

setcolor(green);

line((l-1)*40+30,(h-1)*40+40,(l-1)*40+1,(h-1)*40+40);

line((l-1)*40+30,(h-1)*40+30,(l-1)*40+1,(h-1)*40+30);

line((l-1)*40+30,(h-1)*40+40,(l-1)*40+30,(h-1)*40+30);

line((l-1)*40+1,(h-1)*40+40,(l-1)*40+1,(h-1)*40+30);

line((l-1)*40+30,(h-1)*40+10,(l-1)*40+1,(h-1)*40+10);

line((l-1)*40+30,(h-1)*40+1,(l-1)*40+1,(h-1)*40+1);

line((l-1)*40+30,(h-1)*40+10,(l-1)*40+30,(h-1)*40+1);

line((l-1)*40+1,(h-1)*40+10,(l-1)*40+1,(h-1)*40+1);

line((l-1)*40+25,(h-1)*40+30,(l-1)*40+25,(h-1)*40+10);

line((l-1)*40+5,(h-1)*40+30,(l-1)*40+5,(h-1)*40+10);

line((l-1)*40+20,(h-1)*40+40,(l-1)*40+20,(h-1)*40+30);

line((l-1)*40+10,(h-1)*40+40,(l-1)*40+10,(h-1)*40+30);

line((l-1)*40+20,(h-1)*40+10,(l-1)*40+20,(h-1)*40+1);

line((l-1)*40+10,(h-1)*40+10,(l-1)*40+10,(h-1)*40+1);

line((l-1)*40+40,(h-1)*40+25,(l-1)*40+40,(h-1)*40+15);

line((l-1)*40+40,(h-1)*40+25,(l-1)*40+25,(h-1)*40+25);

line((l-1)*40+40,(h-1)*40+15,(l-1)*40+25,(h-1)*40+15);

circle((l-1)*40+15,(h-1)*40+20,5);

end;

end;{case}

end;{with}

end;

procedure runtank(ch:char);

begin

case ch of

'i':if tank.h1 then dec(tank.h);

'k':if tank.h10 then inc(tank.h);

'j':if tank.l1 then dec(tank.l);

'l':if tank.l15 then inc(tank.l);

'8':tank.f:=1;

'4':tank.f:=2;

'5':tank.f:=3;

'6':tank.f:=4;

'0':pushtype1(tank.l,tank.h,tank.f,bomb);

'q':halt;

end;

end;

function win:boolean;

var i:integer;

begin

for i:=1 to high(diren) do

if diren[i].f0 then begin win:=false;exit;end;

win:=true;

end;

function lost:boolean;

var i:integer;

begin

for i:=1 to high(diren) do

if (diren[i].h=tank.h) and (diren[i].l=tank.l) and (diren[i].f0) then

begin lost:=true;exit;end;

lost:=false;

end;

procedure runbomb;

var i,hh,hl:integer;

begin

for i:=1 to high(bomb) do

with bomb[i] do

if f0 then

begin

hh:=hh+fx[f,1];

hl:=l+fx[f,2];

if(hl in [1..15])and

(hh in [1..10]) then

begin

h:=hh;

l:=hl;

end

else begin f:=0;pushtype1(l,h,5,fire);end;

end;

end;

procedure runfire;

var i:integer;

begin

for i:=1 to high(fire) do

begin

if fire[i].f0 then dec(fire[i].f);

end;

end;

procedure rundiren;

var s:set of 1..4;

i,j,k,hh1,hh2,hl1,hl2:integer;

begin

for i:=1 to high(diren) do

with diren[i] do

if f0 then

begin

if htank.h then dec(h)

else if htank.h then inc(h);

if ltank.l then inc(l)

else if ltank.l then dec(l);

end;

end;

procedure check;

var i,j:integer;

begin

for i:=1 to high(diren) do

with diren[i] do

if f0 then

begin

for j:=1 to high(bomb) do

if (bomb[j].h=h) and (bomb[j].l=l) and (bomb[j].f0)

and ((bomb[j].htank.h) or (bomb[j].ltank.l)) then

begin

bomb[j].f:=0;f:=0;break;

end;

end;

end;

procedure inittank;

var y:integer;

ch:char;

begin

settextstyle(7,horizdir,6);

setcolor(white);

outtextxy(10,10,'Tank2:Crazy tank');

settextstyle(1,horizdir,1);

y:=100;

outtextxy(50,y,'Mase by WangYu');

inc(y,textheight('H')+1);

outtextxy(50,y,'Ctrl key:');

inc(y,textheight('H')+1);

outtextxy(50,y,'Up:i Left:j Right:l Down:k Exit:q');

inc(y,textheight('H')+1);

outtextxy(50,y,'GunUp:8 GunLeft:4 GunRight:6 Fire:0');

inc(y,textheight('H')+100);

outtextxy(50,y,'Pressed Enter to continue');

repeat ch:=readkey;until ch=#13;

end;

procedure init(ds:integer);

var i:integer;

st:string;

begin

fillchar(t,sizeof(t),0);

fillchar(diren,sizeof(diren),0);

fillchar(fire,sizeof(fire),0);

fillchar(bomb,sizeof(bomb),0);

tank.h:=5;tank.l:=8;tank.f:=1;

with diren[1] do begin h:=1;l:=7;f:=0;end;

with diren[2] do begin h:=10;l:=7;f:=0;end;

with diren[3] do begin h:=1;l:=1;f:=0;end;

with diren[4] do begin h:=10;l:=15;f:=0;end;

with diren[5] do begin h:=1;l:=15;f:=0;end;

with diren[6] do begin h:=10;l:=1;f:=0;end;

with diren[7] do begin h:=6;l:=1;f:=0;end;

with diren[8] do begin h:=6;l:=15;f:=0;end;

for i:=1 to ds do diren[i].f:=1;

str(ds,st);

print;

setcolor(black);

outtextxy(200,200,'Level'+st);

readkey;

end;

procedure main;

var ch:char;

begin

while not lost and not win do

begin

delay(50);

with t do

begin

inc(ms,50);

if ms=1000 then

begin

ms:=0;

inc(s);

if s=60 then

s:=0;

inc(m);

end;

end;

if keypressed then

begin

ch:=readkey;

runtank(ch);

end;

if t.ms mod 200=0 then rundiren;

if t.ms mod 100=0 then check;

if t.ms mod 100=0 then begin runbomb;lf:=true;end;

if t.ms mod 100=0 then runfire;

print;

end;

setcolor(black);

if win then outtextxy(200,200,'You win!!!')

else outtextxy(200,200,'You lost!!!');

repeat

ch:=readkey;

until ch=#13;

end;

var level:integer;

begin

initg;

inittank;

for level:=1 to 8 do

begin

init(level);

main;

if lost then dec(level);

end;

end.

关于pascal游戏和pascalswager游戏的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。