算各种点数
来源:互联网 发布:补水保湿精华 知乎 编辑:程序博客网 时间:2024/04/30 08:06
#include<iostream>#include<string>#include<cstdlib>#include<cmath>#include<cstdio>using namespace std;const double Threshold=1E-6;const int CardsNumber=4;const int ResultValue=24;int number[6];string result[CardsNumber];bool PointsGame(int n){ if(n==1) { if(fabs(number[0]-ResultValue)<Threshold) { cout<<result[0]<<endl; return true; } else { return false; } } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { int a,b; string expa,expb; a=number[i]; b=number[j]; number[j]=number[n-1]; expa=result[i]; expb=result[j]; result[j]=result[n-1]; result[i]='('+expa+'+'+expb+')'; number[i]=a+b; if(PointsGame(n-1)) return true; result[i]='('+expa+'-'+expb+')'; number[i]=a-b; if(PointsGame(n-1)) return true;result[i]='('+expb+'-'+expa+')'; number[i]=b-a; if(PointsGame(n-1)) return true; result[i]='('+expa+'*'+expb+')'; number[i]=a*b; if(PointsGame(n-1)) return true; if(b!=0) { result[i]='('+expa+'/'+expb+')'; number[i]=a/b; if(PointsGame(n-1)) return true; } if(a!=0) { result[i]='('+expb+'/'+expa+')'; number[i]=b/a; if(PointsGame(n-1)) return true; } number[i]=a; number[j]=b; result[i]=expa; result[j]=expb; }}return false;}int main(){ int x; char ss[5]; int nn; int a,b,c,d; while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF){ //if(nn==0) break; int flag=1; //while(nn--){ //scanf("%s",ss); number[0]=a; number[1]=b; number[2]=c; number[3]=d; for(int i=0;i<CardsNumber;i++) { char buffer[20]; //cout<<"the "<<i<<"th number:"; //number[i]=ss[i]-'0'; x=number[i]; itoa(x,buffer,10); result[i]=buffer; } if(PointsGame(CardsNumber)) { if(flag==1) flag=1;else flag=0; } else { flag=0; }if(flag==1) cout<<"Yes"<<endl;else if(flag==0) cout<<"No"<<endl;} return 0;}
0 0
- 算各种点数
- 点数
- 编写一个掷骰子100次的程序,打出各种点数的出现次数
- nyoj487点数
- 随机数例子 筛子点数
- 24点数学游戏
- 自动跃点数
- 骰子点数的概率
- 输出骰子点数
- 骰子点数问题
- 采样率 窗口点数
- metric跃点数含义
- 求圆上和谐点数
- Jzoj3927 可见点数
- 学点数学吧
- 寻找平面内共线点数最多的直线和点数
- 部门ID 员工ID 点数
- 今天点数首次破10
- python 处理excel
- cocos2d-x AnchorPoint锚点
- strcpy,strncpy, strlen, strcmp strcat函数实现
- matlab中uitable 的一些使用说明
- 互联网推送服务原理:长连接+心跳机制(MQTT协议)
- 算各种点数
- 门面模式
- 你的计算机配置似乎是正确的,但该设备或资源(DNS)没检测到有响应
- ios:UITableView告别手动上拉更新,自动刷新数据
- Dom编程(购物车 全选及金额总计、仿css手册实例效果)
- NSSet类型 以及与NSArray区别
- cron表达式(详解)
- SQL92标准
- 笔画宽度变化(C++和matlab算法)