ACM 计算器 类似24点 UVALive 6163 Myth Busters
来源:互联网 发布:温州广电网络 编辑:程序博客网 时间:2024/05/04 03:01
ACM 计算器 类似24点 UVALive 6163 Myth Busters
Description
Every train carriage operated by CityRail of Sydney has a unique ID number of four digits. A not so uncommon myth amongst local school pupils is that every ID number can be manipulated by permuting the digits, using brackets and using arithmetic operations from the set '*' , '/', '+' , '-' to calculate the number 10.
Your task is to check the validity of this myth for the carriages operated by CityRail of Sydney and for train carriages from other cities whose ID numbers were collected.
Reminder: The operation `/' refers to integer division. Most of you already know it, but here are two examples: result of 5/2 is 2 and of2/5 is 0.
Input
The input consists of many test cases. The description of each test case consists of:
- an integer N (1N1000), on a line by itself, which indicates the number of IDs collected from one city, and
- N lines that contain a four-digit number each.
A zero on a line by itself indicates the end of input and should not be processed.
Output
For each test case print the conclusion of your investigation as `TRUE' or `BUSTED' as shown in ``Sample Output" below. Print `TRUE' if this myth is correct for all carriage ID numbers for that city. Otherwise, `BUSTED' is to be printed.
Sample Input
26666555521234161116020
Sample Output
BUSTEDTRUE
Memory: 0 KB Time: 73 MSLanguage: C++ 4.5.3 Result: Accepted
/* * Author: NICK WONG * Created Time: 8/2/2014 13:11:54 * File Name: */#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;#define out(x) cout<<#x<<": "<<x<<endlconst double eps(1e-8);const int maxn=11000;const long long maxint=-1u>>1;const long long maxlong=maxint*maxint;typedef long long lint;int n;int a[maxn][5],p,b[10],ans[maxn];bool vis[10],flag,wjj;void init(){ char c; for (int i=1; i<=n; i++) { for (int j=1; j<=4; j++) { cin>>c; a[i][j]=c-'0'; } } }void dfs(int l, int r,int ans[])//计算排列的值,数组ans存储可能的结果情况,目测最多302种左右{ int x[maxn],y[maxn]; if (l==r) { ans[0]=1; ans[1]=b[l]; return; } ans[0]=0; for (int i=l; i<r; i++) { dfs(l,i,x); dfs(i+1,r,y); for (int j=1; j<=x[0]; j++) for (int k=1; k<=y[0]; k++) { ans[++ans[0]]=x[j]*y[k]; ans[++ans[0]]=x[j]+y[k]; ans[++ans[0]]=x[j]-y[k]; if (y[k]!=0) ans[++ans[0]]=x[j]/y[k]; } }}void dg(int x)//生成排列{ if (wjj) return; if (x==5) { ans[0]=0; dfs(1,4,ans); for (int i=1; i<=ans[0]; i++) if (ans[i]==10) { wjj=true; break; } //out(ans[0]); return; } for (int i=1; i<=4; i++) if (!vis[i]) { vis[i]=true; b[x]=a[p][i]; dg(x+1); vis[i]=false; }}void work(){ flag=true; memset(vis,false,sizeof(vis)); for (p=1; p<=n; p++) { wjj=false; dg(1); if (!wjj) flag=false; } if (flag) cout<<"TRUE"<<endl; else cout<<"BUSTED"<<endl;}int main(){ while(cin>>n && n!=0) { init(); work(); } return 0;}
- ACM 计算器 类似24点 UVALive 6163 Myth Busters
- 【UVALive】6163 Myth Busters 类24点
- UVALive 6163 - Myth Busters
- 6163 - Myth Busters
- BNU 29022 Myth Busters (dfs)
- 24点计算器Ruby脚本
- 24点计算器Python脚本
- 24点纸牌游戏计算器
- ACM->uvalive->Sentry Robots(二分图匹配的最小点覆盖)
- 【割点 && dfs】UVALive
- ACM简单的计算器
- [ACM]时间计算器
- 绩点计算器
- 数据结构-计算器点实现
- 类似点赞、评论
- Stress Busters
- uva_109_SCUD Busters
- Number Busters
- 【IIS】windows2003 iis6.0站点打不开,找不到服务器或 DNS 错误
- Pager-taglib分页使用
- POJ 3114 Countries in War 强连通tarjan缩点后 跑最短路spfa
- 数据结构学习笔记4
- 时间复杂度和空间复杂度
- ACM 计算器 类似24点 UVALive 6163 Myth Busters
- 杭电题目分类
- 项目中期总结
- 哎, 安全,一声叹息
- cf五道题
- POJ 1182 食物链
- Codeforces 155 C.Double Profiles
- Android文件上传 PHP端接收
- 解决ViewPager+Fragment时状态保存的问题