【UVALive】6163 Myth Busters 类24点
2014-08-08 16:53
495 查看
传送门:【UVALive】6163 Myth Busters
题目分析:
可以使用括号,还有加减乘除,问能否用四个0~9的数凑出10。。。我了个去。。渣渣不会写拿来当模拟写了,写的人都要吐了。。。。
先处理出所有两个数和起来的情况,然后用两个数和起来的情况再加上一个数处理出所有三个数和起来的情况,最后用两个两个数或者一个三个数加一个数的继续推出四个数的,最后按照不降序保存。
这个能一边AC真是奇葩了。。。。
代码如下:
题目分析:
可以使用括号,还有加减乘除,问能否用四个0~9的数凑出10。。。我了个去。。渣渣不会写拿来当模拟写了,写的人都要吐了。。。。
先处理出所有两个数和起来的情况,然后用两个数和起来的情况再加上一个数处理出所有三个数和起来的情况,最后用两个两个数或者一个三个数加一个数的继续推出四个数的,最后按照不降序保存。
这个能一边AC真是奇葩了。。。。
代码如下:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std ; #define REP( i , a , b ) for ( int i = a ; i < b ; ++ i ) #define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REV( i , a , b ) for ( int i = a ; i >= b ; -- i ) #define CLR( a , x ) memset ( a , x , sizeof a ) const int MAXN = 1005 ; int two[10][10][10] ; int three[10][10][10][2000] ; int four[10][10][10][10] ; int n ; int num[4] ; void solve () { int cnt = 0 ; REP ( i , 0 , n ) { REP ( j , 0 , 4 ) scanf ( "%1d" , &num[j] ) ; sort ( num , num + 4 ) ; if ( four[num[0]][num[1]][num[2]][num[3]] ) ++ cnt ; } if ( cnt == n ) printf ( "TRUE\n" ) ; else printf ( "BUSTED\n" ) ; } int unique ( int a[] , int n ) { int cnt = 1 ; sort ( a + 1 , a + n + 1 ) ; FOR ( i , 2 , n ) if ( a[i] != a[cnt] ) a[++ cnt] = a[i] ; return cnt ; } void fun () { CLR ( two , 0 ) ; CLR ( three , 0 ) ; REP ( i , 0 , 10 ) REP ( j , 0 , 10 ) { int& cnt = two[i][j][0] ; two[i][j][++ cnt] = i + j ; two[i][j][++ cnt] = i * j ; two[i][j][++ cnt] = i - j ; two[i][j][++ cnt] = j - i ; if ( i ) two[i][j][++ cnt] = j / i ; if( j ) two[i][j][++ cnt] = i / j ; } REP ( i , 0 , 10 ) REP ( j , 0 , 10 ) two[i][j][0] = unique ( two[i][j] , two[i][j][0] ) ; int ans = 0 ; REP ( i , 0 , 10 ) REP ( j , 0 , 10 ) FOR ( k , 1 , two[i][j][0] ) REP ( l , 0 , 10 ) { int& cnt = three[i][j][l][0] ; three[i][j][l][++ cnt] = two[i][j][k] + l ; three[i][j][l][++ cnt] = two[i][j][k] * l ; three[i][j][l][++ cnt] = two[i][j][k] - l ; three[i][j][l][++ cnt] = l - two[i][j][k] ; if ( l ) three[i][j][l][++ cnt] = two[i][j][k] / l ; if ( two[i][j][k] ) three[i][j][l][++ cnt] = l / two[i][j][k] ; ans = max ( ans , cnt ) ; //printf ( "%d\n" , ans ) ; } REP ( i , 0 , 10 ) REP ( j , 0 , 10 ) REP ( k , 0 , 10 ) three[i][j][k][0] = unique ( three[i][j][k] , three[i][j][k][0] ) ; REP ( i , 0 , 10 ) REP ( j , i , 10 ) REP ( k , j , 10 ) { int cnt = three[i][j][k][0] ; int num = 0 ; FOR ( l , 1 , three[i][k][j][0] ) three[i][j][k][++ cnt] = three[i][k][j][l] ; FOR ( l , 1 , three[j][i][k][0] ) three[i][j][k][++ cnt] = three[j][i][k][l] ; FOR ( l , 1 , three[j][k][i][0] ) three[i][j][k][++ cnt] = three[j][k][i][l] ; FOR ( l , 1 , three[k][i][j][0] ) three[i][j][k][++ cnt] = three[k][i][j][l] ; FOR ( l , 1 , three[k][j][i][0] ) three[i][j][k][++ cnt] = three[k][j][i][l] ; three[i][j][k][0] = cnt ; } REP ( i , 0 , 10 ) REP ( j , i , 10 ) REP ( k , j , 10 ) three[i][j][k][0] = unique ( three[i][j][k] , three[i][j][k][0] ) ; } void go () { CLR ( four , 0 ) ; REP ( i , 0 , 10 ) REP ( j , i , 10 ) REP ( k , j , 10 ) FOR ( x , 1 , three[i][j][k][0] ) REP ( l , 0 , 10 ) { int a = three[i][j][k][x] , b = l ; int tmp[4] = { i , j , k , l } ; sort ( tmp , tmp + 4 ) ; if ( a + b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( a - b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( a * b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( b - a == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( a && b / a == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( b && a / b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; } REP ( i , 0 , 10 ) REP ( j , i , 10 ) REP ( k , 0 , 10 ) REP ( l , k , 10 ) FOR ( x , 1 , two[i][j][0] ) FOR ( y , 1 , two[k][l][0] ) { int a = two[i][j][x] , b = two[k][l][y] ; int tmp[4] = { i , j , k , l } ; sort ( tmp , tmp + 4 ) ; if ( a + b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( a - b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( a * b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( b - a == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( a && b / a == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; else if ( b && a / b == 10 ) four[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = 1 ; } } int main () { fun () ; go () ; while ( ~scanf ( "%d" , &n ) && n ) solve () ; return 0 ; }
相关文章推荐
- ACM 计算器 类似24点 UVALive 6163 Myth Busters
- UVALive 6163 - Myth Busters
- UVALive 6163(暴力枚举)
- UVALive 6163
- uvalive 3213 Ancient Cipher
- UESTC 893&&uvalive 6627 First Date
- UVALive 6858 Frame (模拟)
- UVALive 4952
- UVALive 6258 Non-boring sequences 分治
- UVALive 7414 Sibling Rivalry
- [UVALive 6696] A Generalized N-Queens Problem
- POJ1011 HDU1455 UVA307 UVALive5522 Sticks题解
- UVALive 6187 Never Wait for Weights(并查集)
- UVAlive 3092 无根树->有根树 dfs
- UVALive 7279 Sheldon Numbers(位运算、暴力)
- UVALive -- 2664 One-way traffic(双连通求割边)
- UVALive 3211 Now or later(2-sat)
- UVAlive 1808 Best Position(FFT)
- UVALive - 3902 Network
- UVALive 7004-10.1训练赛