VIJOS-P1134 24点游戏
来源:互联网 发布:培训管理数据流程图 编辑:程序博客网 时间:2024/06/06 07:05
Description
几十年前全世界就流行一种数字扑克游戏,至今仍有人乐此不疲.在中国我们把这种游戏称为“算24点”。您作为游戏者将得到4个1-13(在扑克牌里用A代替1,J代替11,Q代替12,K代替13)之间的自然数作为操作数,而您的任务是对这4个操作数进行适当的算术运算,判断运算结果是否等于24。能输出1,不能输出0。
Input
四个牌面值。牌面值与牌面值之间用一个空格隔开。
Output
输出0或1。
Sample Input
3 8 10 Q
Sample Output
1
HINT
Q×(10/(8-3))=24
Source
zhouyc
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char s[5];double sum[5],ans;void dfs(int dep,double t[5]){double sum2[5];if(t[1]>24-0.000001&&t[1]<24+0.000001&&dep==1){printf("1");exit(0);}for(int i=1;i<=dep;i++){for(int j=1;j<=dep;j++){if(i!=j){double x=t[i],y=t[j];int cnt=1;for(int k=1;k<=dep;k++)if(k!=i&&k!=j)sum2[cnt++]=t[k];ans=x*y;sum2[cnt]=ans;dfs(dep-1,sum2);ans=x+y;sum2[cnt]=ans;dfs(dep-1,sum2);ans=x-y;sum2[cnt]=ans;dfs(dep-1,sum2);ans=y-x;sum2[cnt]=ans;dfs(dep-1,sum2);if(y!=0.0){ans=x/y;sum2[cnt]=ans;dfs(dep-1,sum2);}if(x!=0.0){ans=y/x;sum2[cnt]=ans;dfs(dep-1,sum2);}}}}}int main(){for(int i=1;i<=4;i++){scanf("%s",s);if(s[0]=='1'&&s[1]=='0') sum[i]=10;else if(s[0]=='A') sum[i]=1;else if(s[0]=='J') sum[i]=11;else if(s[0]=='Q') sum[i]=12;else if(s[0]=='K') sum[i]=13;elsesum[i]=s[0]-'0';}dfs(4,sum);printf("0");}
dfs暴搜。
阅读全文
0 0
- VIJOS-P1134 24点游戏
- VIJOS-P1134 24点游戏 dfs
- vijos P1134 算24点 题解
- vijos P1134 矩形覆盖 题解
- 积木游戏 vijos
- VIJOS 1779 国王游戏
- vijos P1779 国王游戏
- vijos P1485 传球游戏
- vijos-伊甸园日历游戏
- 【VIJOS】1208 欧几里德游戏
- Vijos P1941猜谜游戏
- Vijos 1464积木游戏
- Vijos P1301 智力游戏
- 24点游戏代码
- 24点游戏
- 24点扑克牌游戏
- 24点游戏
- 24点游戏
- 详细分析Vuex 的应用场景
- easy example of tensorflow in python on creating dataset and training
- Spark编程、RDD 功能介绍、RDD 元素变换、RDD 元素操作
- 微信小程序实现文件,图片上传
- c++之智能指针(二)之直接管理内存
- VIJOS-P1134 24点游戏
- KeyShot Pro(3D渲染动画制作工具)官方中文注册版V7.2.109下载 | keyshot7破解版
- USB驱动程序之概念介绍学习笔记
- 东方财富网股票数据爬虫
- Appium--键盘操作 KEYCODE
- android 正确监听并拦截软键盘的退格键
- 报错解决:No Hibernate Session bound to thread, and configuration does not allow creation of non-transact
- vue自定义指令-vue-reclick
- linux下mysql 5.1 和 5.7的安装