ACM 计算器 类似24点 UVALive 6163 Myth Busters
2014-08-02 22:08
337 查看
ACM 计算器 类似24点 UVALive 6163 Myth Busters
C - Myth Busters
Time Limit:15000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
UVALive
6163
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 (1
N
1000),
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
Sample Output
C - Myth Busters
Time Limit:15000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
UVALive
6163
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 (1
N
1000),
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
2 6666 5555 2 1234 1611 1602 0
Sample Output
BUSTED TRUE
Memory: 0 KB | Time: 73 MS | |
Language: 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<<endl const 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; }
相关文章推荐
- 【UVALive】6163 Myth Busters 类24点
- UVALive 6163 - Myth Busters
- acm 乘法逆元 或线段树 UVALive 5798
- UVALive 6661 - Equal Sum Sets (类似硬币的DP问题)
- UVALive Problem 7079 How Many Maos Does the Guanxi Worth(暴力枚举+最短路)——2014ACM/ICPC亚洲区广州站
- UVALive Problem 7073 Song Jiang's rank list(排序)——2014ACM/ICPC亚洲区广州站
- UVALive - 7715 The 2016 ACM-ICPC Asia Jakarta Regional Contest E - Guessing Game 繁琐的等差数列求和
- UVALive7261(2015ACM/ICPC北京赛区现场赛A)
- The 2014 ACM-ICPC Asia Shanghai Regional Contest - I - Defeat the Enemy (贪心+multiset)UVALive - 7146
- ACM->uvalive->Sentry Robots(二分图匹配的最小点覆盖)
- 【Uvalive 2531】 The K-League (最大流-类似公平分配问题)
- UVALive 6163(暴力枚举)
- UVALive 7146 (贪心+少许数据结构基础)2014acm/icpc区域赛上海站
- ACM 数论 UVALive 6170 Esspe-Peasee 解二元一次方程 扩张欧几里得算法
- ACM学习历程—UVALive 7147 World Cup(分类讨论 && 贪心)
- UVALive 7061 Dire Wolf (dp)(The 2014 ACM-ICPC Asia Beijing Regional Contest D)
- UVALive-7350-ACM Contest Scoring(模拟)
- UVALive 6163
- UVALive - 7711 The 2016 ACM-ICPC Asia Jakarta Regional Contest A - Confusing Date Format
- UVALive 6270 (ACM-ICPC Live Archive: 6270) Edge Case(大数斐波那契)