#include<algorithm>
#include<iostream>
#include<vector>
#include<utility>
using namespace std
typedef pair<int, pair<备歼int, int>> item
int absub(int 仿猜冲a, int b)
{
return a < b ? b - a : a - b
}
bool cmp(item a, item b)
{
return a > b
}
int main()
{
int n, t
cin >> n >> t
vector<item> mine
mine.resize(n * n)
int gold
for (int x = 0 x 兆岩< n x++)
{
for (int y = 0 y < n y++)
{
cin >> gold
mine[x*n+y] = make_pair(gold, make_pair(x, y))
}
}
sort(mine.begin(), mine.end(), cmp)
int x = 0, y = 0, xcur, ycur, gcur, sum
for (auto it = mine.begin() it != mine.end() it++)
{
gcur = (*it).first
xcur = (*it).second.first
ycur = (*it).second.second
t -= gcur + absub(x, xcur) + absub(y, ycur)
if (t < 0)
{
break
}
sum += gcur
x = xcur
y = ycur
}
cout << sum
return 0
}
俄罗斯方快http://topic.csdn.net/t/20051201/01/4429905.html扫雷
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
struct list
{
int x
int y
int num
int bomb
int wa
}
struct list di[10][10]
int currentx=210
int currenty=130
void initxy(void)
{
int i,j
for(i=0i<=9i++)
for(j=0j<=9j++)
{
di[j].x=i*20+200
di[j].y=j*20+120
di[j].wa=0
di[j].bomb=0
}
}
void initmu(void)
{
int i,j
setcolor(2)
rectangle(200,120,400,320)
rectangle(190,110,410,330)
setfillstyle(8,14)
floodfill(191,111,2)
for(i=0i<=9i++)
for(j=0j<=9j++)
rectangle(di[j].x,di[j].y,di[j].x+19,di[j].y+19)
outtextxy(450,200,"press 'enter' to kick"芹做启嫌如)
outtextxy(450,250,"press '\' to mark")
}
void randbomb(void)
{
int k
int i,j
randomize()
for(i=0i<=9i++)
for(j=0j<=9j++)
{
k=random(5)
if(k==2)
di[j].bomb=1
}
}
void jisuan(void)
{
int k=0
int i,j
for(i=0i<=9i++)
for(j=0j<=9j++)
{
if(i&&j&&di[i-1][j-1].bomb)
k=k+1
if(i&&di[i-1][j].bomb)
k=k+1
if(j&&di[j-1].bomb)
k=k+1
if(i<=8&&di[i+1][j].bomb)
k=k+1
if(j<=8&&di[j+1].bomb)
k=k+1
if(i<胡亏=8&&j<=8&&di[i+1][j+1].bomb)
k=k+1
if(i&&j<=8&&di[i-1][j+1].bomb)
k=k+1
if(i<=8&&j&&di[i+1][j-1].bomb)
k=k+1
di[j].num=k
k=0
}
}
void xianbomb(void)
{
int i,j
char biaoji[2]
char znum[2]
biaoji[0]=1
biaoji[1]=NULL
for(i=0i<=9i++)
for(j=0j<=9j++)
{
if(di[j].bomb==1)
outtextxy(di[j].x+2,di[j].y+2,biaoji)
else
{
itoa(di[j].num,znum,10)
setfillstyle(1,0)
bar(i*20+202,j*20+122,i*20+218,j*20+138)
outtextxy(i*20+202,j*20+122,znum)
}
}
}
void move(void)
{
int key
key=bioskey(1)
if(key)
key=bioskey(0)
if(key==0x4800)
{
if(currenty>130)
{
setcolor(0)
circle(currentx,currenty,5)
currenty-=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currenty=310
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x4b00)
{
if(currentx>210)
{
setcolor(0)
circle(currentx,currenty,5)
currentx-=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currentx=390
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x4d00)
{
if(currentx<390)
{
setcolor(0)
circle(currentx,currenty,5)
currentx+=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currentx=210
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x5000)
{
if(currenty<310)
{
setcolor(0)
circle(currentx,currenty,5)
currenty+=20
setcolor(4)
circle(currentx,currenty,5)
}
else
{
setcolor(0)
circle(currentx,currenty,5)
currenty=130
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x1c0d)
{
int i,j
char snum[2]
snum[0]=NULL
snum[1]=NULL
i=(currentx-210)/20
j=(currenty-130)/20
if(di[j].bomb==1)
{
outtextxy(100,100,"game over")
xianbomb()
sleep(2)
exit(0)
}
if(di[j].bomb==0)
{
di[j].wa=1
setfillstyle(1,0)
bar(currentx-8,currenty-8,currentx+8,currenty+8)
setcolor(15)
itoa(di[j].num,snum,10)
outtextxy(currentx-8,currenty-8,snum)
setcolor(4)
circle(currentx,currenty,5)
}
}
if(key==0x2b5c)
{
char biaoji[2]
biaoji[0]=1
biaoji[1]=NULL
setcolor(0)
bar(currentx-8,currenty-8,currentx+8,currenty+8)
setcolor(4)
outtextxy(currentx-8,currenty-8,biaoji)
circle(currentx,currenty,5)
}
}
void success(void)
{
int k=1
int i,j
for(i=0i<=9i++)
for(j=0j<=9j++)
if(di[j].bomb==0&&di[j].wa==0)
k=0
if(k==1)
{
outtextxy(100,100,"success good")
xianbomb()
sleep(2)
exit(0)
}
}
void main(void)
{
int gd=DETECT,gm
initgraph(&gd,&gm,"")
initxy()
initmu()
randbomb()
jisuan()
setcolor(4)
circle(210,130,5)
while(1)
{
move()
success()
}
}
/*太大了估计你不想要,给你一个扫雷哪渗程序,turboC下才能编译成功
空格:打标记
回车:扫雷
方向键:改变方向
*/
#include<stdio.h>
#include<conio.h>逗缓巧
#include<time.h>
void
adjust(int*,int*)
int
a[23][23],c[22][22],mm,nn
int
roundmine(int,int)
void
spread()
main()
{
int
i,j,b[22][22],minenum,mine
int
x,y,yy,s
char
g,h,z
int*x1
int*y1
time_t
t
again:srand((unsigned)
time(&t))
textcolor(LIGHTGREEN)
for(i=2i<=21i++)
for(j=2j<=21j++)
{
gotoxy(i,j)
putch(219)
b[i][j]=1
c[i][j]=1
}
minenum=0
for(i=1i<=22i++)
for(j=1j<=22j++)
{
a[i][j]=0
if(i>1&&i<22&j>1&&j<22)
{if((s=rand()%10)>0)
a[i][j]=0
else
if(s==0)
a[i][j]=1
}
if(a[i][j])
minenum++
}
gotoxy(50,2)
puts("dirction")
gotoxy(50,3)
puts("SPACE:mark")
gotoxy(50,4)
puts("ENTER:dig")
gotoxy(50,8)
printf("mine
num:%4d",minenum)
gotoxy(50,5)
printf("ESC:exit")
gotoxy(30,15)
puts("
")
gotoxy(30,20)
puts("
")
mine=minenum
gotoxy(2,2)
x=2y=2
while(mine)
{
h=getch()
if(h=='H')
gotoxy(x,--y)
else
if(h=='P')
gotoxy(x,++y)
else
if(h=='K')
gotoxy(--x,y)
else
if(h=='M')
gotoxy(++x,y)
x1=&xy1=&y
adjust(x1,y1)
if(h=='
')
{
if(c[wherex()][wherey()])
if(b[wherex()][wherey()])
{
textcolor(LIGHTRED)
putch(16)
mine--
gotoxy(59,8)
printf("%4d",mine)
gotoxy(x,y)
b[wherex()][wherey()]=0
}
else
{
textcolor(LIGHTGREEN)
putch(219)
mine++
gotoxy(59,8)
printf("%4d",mine)
gotoxy(x,y)
b[wherex()][wherey()]=1
}
}
if(h=='\015')
{
mm=wherex()nn=wherey()
c[wherex()][wherey()]=0
if(a[wherex()][wherey()])
{
for(i=2i<=21i++)
for(j=2j<=21j++)
{gotoxy(i,j)
if(a[i][j])
{textcolor(LIGHTRED)
putch(017)
}
}
break
}
else
{spread()gotoxy(mm,nn)}
}
if(h=='\033')
exit(0)
}
yy=1
for(i=2i<=21i++)
for(j=2j<=21j++)
if
(a[i][j]==1&&b[i][j]==1)
{gotoxy(30,15)
cprintf("You
lose!!")
yy=0
}
if(yy)
{gotoxy(30,15)
cprintf("You
win!!")
}
gotoxy(30,20)
cprintf("Once
again(y/n)?"山键)
z=getch()
if(z=='y')
goto
again
}
void
adjust(int*
x,int*
y)
{
if(*x<2)
gotoxy(*x+=20,*y)
else
if(*x>21)
gotoxy(*x-=20,*y)
else
if(*y<2)
gotoxy(*x,*y+=20)
else
if(*y>21)
gotoxy(*x,*y-=20)
}
int
roundmine(int
x,int
y)
{
int
i,j,r=0
for(i=x-1i<=x+1i++)
for(j=y-1j<=y+1j++)
if(a[i][j])
r++
return
r
}
void
spread()
{
int
r,i,j,x,y
x=wherex()
y=wherey()
r=roundmine(x,y)
if(r)
{printf("%d",r)c[x][y]=0}
else
if(r==0&&x>1&&x<22&&y>1&&y<22)
{
putchar('
')c[x][y]=0
for(i=x-1i<=x+1i++)
for(j=y-1j<=y+1j++)
if(x>1&&x<22&&y>1&&y<22&&c[i][j])
{gotoxy(i,j)
spread()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)