[院赛]A number game

Description

You've designed a computer and implemented all the common arithmetic operators: addition, subtraction, multiplication and integer division. However, your budget was very limited, so you could only afford to place a single register in the computer. The register can store any non-negative integer value. Since there is only one register, there is no need to identify the store location or the operands of each operation or its result. The programming language has four instructions: '+', '-', '*' and '/'. Each instruction performs the corresponding operation using the value in the register as both its parameters. It then stores the result in the same register, overwriting the previous content.
A program for your computer is a sequential list of zero or more instructions. You want to show that, even with its limitations, your newly constructed computer is powerful. You will be given two ints s and t. Return the shortest program that finishes with a value of t in the register if it contained s before executing. If there is more than one possible answer, return the one that comes earliest lexicographically. If there is no program that can do the job, return ":-(" (quotes for clarity) instead.

Input

There are at most 100 cases,each case one line contain 2 space seperated integers S and T. (1 <= S,T <= 10^9)

Output

Output the shortest program that finishes with a value of t in the register if it contained s before executing. If there is more than one possible answer, return the one that comes earliest lexicographically. If there is no program that can do the job, return ":-(" (quotes for clarity) instead.

Sample Input

7 392
7 256
4 256
7 9

 

Sample Output

+*+
/+***
**
:-(

 

 

//--------------------------------------------------------------------------------------

简单广搜题,却被我做的很悲剧,无限WA。今天可耻地去看了测试数据才发现错在哪里。

//----------------------------------------

起初思路是:

1如果目标数可以拆成起始数与2的积就用*、+向上广搜

2如果不能但目标数因数只有2,先除成1后再向上广搜

3以上不符合或者搜不到就输出:-(

错误:以为能直接向上搜到的话,直接向上搜肯定比除成1后再向上搜要快,其实不是。

比如,起始数为2^n,目标数为2^(2n-1),起始数要不断的加才能上去,但除成1后可以用乘,当n比较大时,后者会较快到达目标。

  //----------------------------------------

于是改了下,不去分情况,直接广搜。

因为除法只可能在第一次用,所以把起始数插进队列后,把1和除号也插进队列(脑子果断进水),依然WA。

错误:假设两种方法以同样的步数到目标,一个/开头,一个*开头,按字典序应该输出后者,但由于/是先插进去的,反而会输出前者。

  //----------------------------------------

最后还是回到最老老实实的广搜,把起始数插入队列,先插乘再插加最后除没插过就插下除,唉~~~

  //----------------------------------------

每次陷进一个错误出来后都会很混乱,而且没有从头理下头绪的习惯,只是在原来的基础上改下去。这种错误跟着代码走一遍就能发现的,下次要冷静点了,唉~~~

Certainly! Here's an example of MATLAB code that uses the scores of the 16 teams to simulate the number of times each team wins the championship in a tournament: ```matlab % Step 1: Prepare the data % Let's assume you have a 100x16 matrix called 'scores', where each row represents a game and each column represents a team's score. % You can calculate the total score for each team by summing up the scores across all games. totalScores = sum(scores, 1); % Total scores for each team (1x16 vector) % Step 2: Simulate the tournament % We will randomly generate the outcome of each game based on the teams' scores. % The team with the higher score has a higher probability of winning. numSimulations = 10000; % Number of simulations to run numTeams = 16; % Number of teams championCounts = zeros(1, numTeams); % Initialize the count of championships for each team for simulation = 1:numSimulations % Shuffle the order of teams for each simulation shuffledTeams = randperm(numTeams); % Simulate the tournament for round = 1:(numTeams-1) numGames = numel(shuffledTeams) / 2; winners = zeros(1, numGames); % Match up teams in pairs and determine the winners for game = 1:numGames teamA = shuffledTeams(game*2-1); teamB = shuffledTeams(game*2); % Determine the winner based on their total scores if totalScores(teamA) > totalScores(teamB) winners(game) = teamA; else winners(game) = teamB; end end % Keep the winners for the next round shuffledTeams = winners; end championCounts(shuffledTeams) = championCounts(shuffledTeams) + 1; % Increment the count for the champion team end % Step 3: Display the championship counts for each team % You can display the number of times each team wins the championship. teamNames = {'Team 1', 'Team 2', 'Team 3', ...}; % Replace with actual team names for i = 1:numTeams disp(['Championship count for ', teamNames{i}, ': ', num2str(championCounts(i))]); end ``` Make sure to replace `'Team 1', 'Team 2', 'Team 3', ...` with the actual names of the 16 teams. Also, ensure that your data is properly formatted and includes the scores for each team. This code simulates the tournament by randomly shuffling the teams for each simulation and determining the winners based on their total scores. The number of times each team wins the championship is counted and displayed at the end. Feel free to adjust the number of simulations (`numSimulations`) to get more accurate results.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值