【UVALive】6163 Myth Busters 类24点

2024-09-05 15:18
文章标签 24 uvalive busters myth 6163

本文主要是介绍【UVALive】6163 Myth Busters 类24点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传送门:【UVALive】6163 Myth Busters


题目分析:

可以使用括号,还有加减乘除,问能否用四个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" ) ;elseprintf ( "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 ;
}


这篇关于【UVALive】6163 Myth Busters 类24点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1139326

相关文章

Science|癌症中三级淋巴结构的免疫调节作用与治疗潜力|顶刊精析·24-09-08

小罗碎碎念 Science文献精析 今天精析的这一篇综述,于2022-01-07发表于Science,主要讨论了癌症中的三级淋巴结构(Tertiary Lymphoid Structures, TLS)及其在肿瘤免疫反应中的作用。 作者类型作者姓名单位名称(中文)通讯作者介绍第一作者Ton N. Schumacher荷兰癌症研究所通讯作者之一通讯作者Daniela S. Thomm

SIGMOD-24概览Part7: Industry Session (Graph Data Management)

👇BG3: A Cost Effective and I/O Efficient Graph Database in ByteDance 🏛机构:字节 ➡️领域: Information systems → Data management systemsStorage management 📚摘要:介绍了字节新提出的ByteGraph 3.0(BG3)模型,用来处理大规模图结构数据 背景

【A题成品论文已出】24数学建模国赛A题成品论文(附参考代码)免费分享

A 题  “板凳龙”  闹元宵 摘要 “板凳龙”是一种传统的民俗文化活动,通常由许多板凳连接成龙的形状进行表演。本文基于螺旋线和板凳龙的运动特性,建立数学模型来分析舞龙队在不同情况下的运动轨迹、调头路径和速度优化等问题。问题主要涉及板凳龙的行进路径、碰撞避免、调头空间的设计,以及如何优化龙头的速度,以确保龙身与龙尾的行进安全。 针对问题一,舞龙队由223节板凳组成,龙头前把手的速度为1

【Git 学习笔记_24】Git 使用冷门操作技巧(四)——更多实用 git 别名设置、交互式新增提交

文章目录 11.8 更多别名设置别名1:只查看当前分支(git b)别名2:以图表形式显示自定义格式的 git 日志(git graph)别名3:查看由于合并分支导致的冲突后仍有冲突的、待合并的文件列表(git unmerged)别名4:查看 git 状态(git st)别名5:查看 git 简要状态(git s)别名6:查看最新版本的统计信息(git l1)别名7:查看最近 5 个版本的提

Leetcode面试经典题-24.两两交换链表中的节点

解法都在代码里,不懂就留言或者私信 这里先写一个递归的解,如果后面有时间,我再写个迭代的 /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val =

图形API学习工程(24):D3D11读取非DDS格式的CubeMap

工程GIT地址:https://gitee.com/yaksue/yaksue-graphics 目标 在《图形API学习工程(21):使用CubeMap纹理》中,由于DirectX读取CubeMap的教程范例都是DDS格式的纹理,因此我也首先实现了DDS的版本,期望之后做处理。 上一篇使D3D12可以用非DDS格式的CubeMap了,本篇目标将是D3D11。 分析当前的流程 当前使用D

数字人直播防封技巧升级!头部源码厂商如何实现7*24小时无间断直播?

当前,许多用户在使用数字人直播的过程中都遇到了直播间违规和账号被封两大问题,并因此蒙受了一定的损失。在此背景下,不少有计划引入数字人直播的企业和搭建数字人直播系统的创业者也开始有了犹豫。为了让大家能够更放心地入局,本期,我们将通过分析这两大问题出现的原因,来整理数字人直播防封教程,希望能对大家有所帮助。 一、数字人直播是否会导致直播间违规和封号问题? 需要明确的一点是,当前,虽然许多人在进

【24数模国赛赛题思路已出】国赛B题第二套整体思路丨附参考代码丨免费分享

B 题 生产过程中的决策问题 一、问题1解析 问题1的任务是为企业设计一个合理的抽样检测方案,基于少量样本推断整批零配件的次品率,帮助企业决定是否接收供应商提供的这批零配件。具体来说,企业需要依据两个不同置信度(95% 和 90%)来判断次品率是否超过或不超过标称值(10%)。 供应商声称的次品率为不超过10%,但企业需要通过抽样检测来验证实际次品率是否符合此要求。通过设计合理的抽样方案,企

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from class path resource [bean1.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineN

24. Redis缓存问题

1. 前言 在小型项目中(例如大部分 toB 业务),Redis 被作为缓存,我们无需过多关注缓存的性能,但是对于高并发的场景(例如 toC 的在线电商业务),在商品秒杀或者库存抢购的时候,Redis 也可能存在诸多潜在的问题,例如缓存穿透、缓存雪崩。 2. 缓存问题 2.1 缓存穿透 面试官提问: Redis 的缓存穿透是什么意思?有什么解决方案? 题目解析: 首先给出缓