小H和迷宫

链接:https://ac.nowcoder.com/acm/problem/15156
来源:牛客网
 

题目描述

    小H陷入了一个迷宫中,迷宫里有一个可怕的怪兽,血量有N点,小H有三瓶魔法药水,分别可以使怪兽损失a%、b%、c%的血量(之后怪兽的血量会向下取整),小H想合理地运用这三瓶药水,使怪兽失去尽可能多的血量

    注意:每瓶药水只能用一次

输入描述:

一行,四个整数 N,a,b,c

输出描述:

一行,一个整数w,表示最多能使得怪兽扣减多少血量

示例1

输入

100 20 15 0

输出

32

备注:

5≤N≤109,0≤a,b,c≤100

这里我用的全排列枚举

不然的话比如说这组数据

    105 20 25 0

105-(105*0.8+(84为105*0.8后向下取整)84*0.75) = 42
 

105-(105*0.75(78为105*0.75后向下取整)*0.8)=43

答案是不是不一样?

#include <stdio.h>
#include <string>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(long long a,long long b){
	return a>b;
}
int main(){
	long long n,a,b,c;
	long long num[10010];
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);

	num[0]=a;
	num[1]=b;
	num[2]=c;
	
	sort(num,num+3,cmp);
	long long m=-1;
	do{
		long long sum=0;
		sum=n*(100-num[0])/100;//剩余血量
		sum=sum*(100-num[1])/100;
		sum=sum*(100-num[2])/100;
		sum=n-sum;
		m=max(m,sum);
	}while(next_permutation(num,num+3));
	printf("%lld",m);
	return 0;
} 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是代码 #include #include #include #include #define Height 25 //迷宫的高度,必须为奇数 #define Width 25 //迷宫的宽度,必须为奇数 #define Wall 1 #define Road 0 #define Start 2 #define End 3 #define Esc 5 #define Up 1 #define Down 2 #define Left 3 #define Right 4 int map[Height+2][Width+2]; void gotoxy(int x,int y) //移动坐标 { COORD coord; coord.X=x; coord.Y=y; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); } void hidden()//隐藏光标 { HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci;); cci.bVisible=0;//赋1为显示,赋0为隐藏 SetConsoleCursorInfo(hOut,&cci;); } void create(int x,int y) //随机生成迷宫 { int c[4][2]={0,1,1,0,0,-1,-1,0}; //四个方向 int i,j,t; //将方向打乱 for(i=0;i<4;i++) { j=rand()%4; t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; } map[x][y]=Road; for(i=0;i<4;i++) if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) { map[x+c[i][0]][y+c[i][1]]=Road; create(x+2*c[i][0],y+2*c[i][1]); } } int get_key() //接收按键 { char c; while(c=getch()) { if(c==27) return Esc; //Esc if(c!=-32)continue; c=getch(); if(c==72) return Up; //上 if(c==80) return Down; //下 if(c==75) return Left; //左 if(c==77) return Right; //右 } return 0; } void paint(int x,int y) //画迷宫 { gotoxy(2*y-2,x-1); switch(map[x][y]) { case Start: printf("入");break; //画入口 case End: printf("出");break; //画出口 case Wall: printf("▇");break; //画墙 case Road: printf(" ");break; //画路 } } void game() { int x=2,y=1; //玩家当前位置,刚开始在入口处 int c; //用来接收按键 while(1) { gotoxy(2*y-2,x-1); printf("●"); //画出玩家当前位置 if(map[x][y]==End) //判断是否到达出口 { gotoxy(30,24); printf("到达终点,按任意键结束"); getch(); break; } c=get_key(); if(c==Esc) { gotoxy(0,24); break; } switch(c) { case Up: //向上走 if(map[x-1][y]!=Wall) { paint(x,y); x--; } break; case Down: //向下走 if(map[x+1][y]!=Wall) { paint(x,y); x++; } break; case Left: //向左走 if(map[x][y-1]!=Wall) { paint(x,y); y--; } break; case Right: //向右走 if(map[x][y+1]!=Wall) { paint(x,y); y++; } break; } } } int main() { system("title yourname"); int i,j; srand((unsigned)time(NULL)); //初始化随即种子 hidden(); //隐藏光标 for(i=0;i<=Height+1;i++) for(j=0;j<=Width+1;j++) if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫 map[i][j]=Road; else map[i][j]=Wall; create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //从随机一个点开始生成迷宫,该点行列都为偶数 for(i=0;i<=Height+1;i++) //边界处理 { map[i][0]=Wall; map[i][Width+1]=Wall; } for(j=0;j<=Width+1;j++) //边界处理 { map[0][j]=Wall; map[Height+1][j]=Wall; } map[2][1]=Start; //给定入口 map[Height-1][Width]=End; //给定出口 for(i=1;i<=Height;i++) for(j=1;j<=Width;j++) //画出迷宫 paint(i,j); game(); //开始游戏 getch(); return 0; }
基于C++和EasyX开发的走迷宫益智小游戏源码+项目说明.zip 【项目介绍】 该资源内项目代码都是经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶, 或者实际项目借鉴参考! 当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。如果基础还行,也可在此代码基础上进行修改,以实现其他功能。 版本:V1.0 时间:2020-7-22 环境:开始使用 VS2010,后来用 VS2017 修改 简介:一个普通的迷宫小游戏 感谢:感谢 QQ 群 C语言革命7 全体成员为该项目的开发做了巨大的贡献,没有你们,该作品也不能有现在的情况! 版权:作者原创,无抄袭,不涉及版权问题,仅用作学习、娱乐,欢迎各位fork! ### 玩法: ~~~cpp 游戏开始选择系列关卡 有三种系列: 森林(简单,基于 Prim 算法) 地牢(中等,基于图论 DFS 算法) 地狱(困难,基于暴力 DFS 算法) 选择系列后,进入游戏 WSAD 上下左右,游戏中有计时器 ~~~ ### 文件: ~~~cpp Maze.h : 初始化头文件 Maze.cpp : 程序开端文件 Game.h : 游戏类头文件 Adventrue.cpp : 冒险模式类文件 Forest.cpp : 冒险模式-森林系列类实现文件 Dungeon.cpp : 冒险模式-地牢系列类实现文件 Infernal.cpp : 冒险模式-地狱系列类实现文件 Help.cpp : 帮助信息类实现文件 Other.cpp : 刷新界面、放置按钮、输出对话框类实现文件 ~~~
好的,我可以为您提供一个简单的迷宫小游戏的C语言代码示例,您可以根据需要进行修改和扩展。 ```c #include <stdio.h> #include <stdlib.h> #include <time.h> #define ROWS 10 #define COLS 10 void createMaze(int maze[][COLS], int rows, int cols); void printMaze(int maze[][COLS], int rows, int cols); int solveMaze(int maze[][COLS], int rows, int cols, int row, int col); int main() { int maze[ROWS][COLS]; srand(time(NULL)); createMaze(maze, ROWS, COLS); printMaze(maze, ROWS, COLS); if (solveMaze(maze, ROWS, COLS, 0, 0)) printf("Congratulations! You have solved the maze.\n"); else printf("Sorry, you failed to solve the maze.\n"); return 0; } // 创建迷宫 void createMaze(int maze[][COLS], int rows, int cols) { int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { maze[i][j] = rand() % 2; } } maze[0][0] = 0; // 入口 maze[rows - 1][cols - 1] = 0; // 出口 } // 打印迷宫 void printMaze(int maze[][COLS], int rows, int cols) { int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (maze[i][j] == 0) printf(" "); else printf("# "); } printf("\n"); } } // 解迷宫 int solveMaze(int maze[][COLS], int rows, int cols, int row, int col) { if (row < 0 || row >= rows || col < 0 || col >= cols) // 越界 return 0; if (maze[row][col] == 1) // 障碍 return 0; if (row == rows - 1 && col == cols - 1) // 到达出口 return 1; maze[row][col] = 1; // 标记已经访问过 if (solveMaze(maze, rows, cols, row - 1, col)) // 向上走 return 1; if (solveMaze(maze, rows, cols, row + 1, col)) // 向下走 return 1; if (solveMaze(maze, rows, cols, row, col - 1)) // 向左走 return 1; if (solveMaze(maze, rows, cols, row, col + 1)) // 向右走 return 1; maze[row][col] = 0; // 回溯 return 0; } ``` 该迷宫小游戏使用了递归算法来解决迷宫问题。在迷宫创建时,随机生成了一些障碍物,并标记了入口和出口。在解迷宫时,从入口开始,每次尝试向上、下、左、右四个方向走,如果可以走通,则递归进入下一层,直到到达出口或走不通为止。如果走不通,则回溯到上一层,尝试其他方向。最终,如果找到了一条通路,则返回1,否则返回0。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值