SRM 146 DIV1 600
Problem Statement |
|||||||||||||
|
Masterbrain is a two player board game in which one player decides on a secret combination of digits, while the other must figure it out in 10 guesses or less. The game differs from Mastermind in that the player making the secret combination is allowed to lie once. The game consists of one player making a sequence of guesses about what the secret combination is, and the other player giving him or her certain information about the quality of the guess. The following is how each guess is analyzed: if a digit is in the correct position then a black peg is given. If a digit is in the guess but in the wrong position then a white peg is given. For all other cases no pegs are given. For example, if guess = "1234", secret = "2335". Analyzing the guess digit by digit; the '1' is not in secret - no pegs given. The '2' is in secret but not in the right place - white peg given. The '3' is in secret and in the right place - black peg given. The '4' is not in secret - no pegs given. Result should be "1b 1w", meaning one black peg and one white peg. Now, if guess is "2334" and secret is "3224", we have the following: '2' is in secret, but not in the right place - white peg given. The first '3' is in secret, but not in the right place - white peg given. Since the '3' in secret has been used, the second '3' in guess should return no pegs. The '4' is in secret and in the right place - black peg given. Result should be "1b 2w". Given a String[] of guesses and a String[] of results for those guesses, return the total number of possible secret combinations, assuming that exactly one of the results is incorrect. Each element of results will be formatted as "<x>b <y>w", where <x> and <y> are the number of black and white pegs respectively. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Notes |
|||||||||||||
| - | The second player must lie exactly once. | ||||||||||||
| - | Black pegs always take precedence over white pegs. Thus, when analyzing a guess, black pegs are assigned first, and then white pegs are assigned. | ||||||||||||
| - | No digit in either a guess or a secret combination may be involved in giving more than one peg. | ||||||||||||
Constraints |
|||||||||||||
| - | guesses and results will have the same number of elements. | ||||||||||||
| - | guesses will have between 1 and 10 elements inclusive. | ||||||||||||
| - | results will have between 1 and 10 elements inclusive. | ||||||||||||
| - | each element in guesses will contain exactly 4 characters and will only contain digits between '1' and '7' inclusive. | ||||||||||||
| - | each element in results will contain exactly 5 characters. | ||||||||||||
| - | each element of results will be formatted as follows: "<x>b <y>w", where <x> represents the number of black pegs and <y> represents the number of white pegs in a guess. <x> and <y> are non-negative integers whose sum is less than or equal to 4. | ||||||||||||
| - | results will never have "3b 1w", because that is impossible. | ||||||||||||
Examples |
|||||||||||||
| 0) | |||||||||||||
|
|||||||||||||
| 1) | |||||||||||||
|
|||||||||||||
| 2) | |||||||||||||
|
|||||||||||||
| 3) | |||||||||||||
|
|||||||||||||
| 4) | |||||||||||||
|
|||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
本题考虑到总共只有7^4种可能使用枚举暴力实现,在判断某一组合是否符合猜测是需优先考虑block leg
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*; public class Masterbrain {
boolean detect(int[] combine, int[] guesses, String result) {
int b, w;
b = w = 0;
int[] c = new int[8];
boolean[] ct = new boolean[4];
for (int i = 0; i < 4; i++) {
if (combine[i] == guesses[i]) {
b++;
c[combine[i]]--;
}
c[combine[i]]++;
}
for (int i = 0; i < 4; i++) {
if (c[guesses[i]] == 0)
continue;
if (combine[i] != guesses[i]) {
c[guesses[i]]--;
w++;
}
}
String tmp = String.format("%db %dw", b, w);
return tmp.trim().equalsIgnoreCase(result);
} public int possibleSecrets(String[] guesses, String[] results) {
int count = 0;
for (int i = 1; i < 8; i++)
for (int j = 1; j < 8; j++)
for (int k = 1; k < 8; k++)
for (int l = 1; l < 8; l++) {
int[] combine = new int[] { i, j, k, l };
int fd = 0;
for (int m = 0; m < guesses.length; m++) {
int[] guess = new int[4];
Integer g = Integer.parseInt(guesses[m]);
for (int n = 3; n >= 0; n--) {
guess[n] = g % 10;
g = g / 10;
}
boolean r = detect(combine, guess, results[m]);
if (!r)
fd++;
}
if (fd == 1)
count++;
}
return count;
}
}
SRM 146 DIV1 600的更多相关文章
- SRM 146 DIV1 800
Problem Statement The purpose of a roundabout is to control the flow of traffic at a busy inter ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- TopCoder SRM 722 Div1 Problem 600 DominoTiling(简单插头DP)
题意 给定一个$12*12$的矩阵,每个元素是'.'或'X'.现在要求$1*2$的骨牌铺满整个矩阵, 'X'处不能放置骨牌.求方案数. 这道题其实和 Uva11270 是差不多的,就是加了一些条件. ...
- 图论 SRM 674 Div1 VampireTree 250
Problem Statement You are a genealogist specializing in family trees of vampires. Vampire famil ...
- SRM 583 DIV1
A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...
- SRM 590 DIV1
转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlov ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
随机推荐
- 解决Shiro注解无效的问题
当Shiro集成到Spring mvc中,却发现shiro的权限注解不起作用,官方的配置是要支持注解,只需要将以下代码加到spring 配置文件中即可: <bean class="or ...
- 兵家必争之地——关于O2O商业模式的一点遐想
先来说说什么是O2O(online to offline)商业模式.创新工场CEO李开复在提及O2O模式时指出,“你如果不知道O2O至少知道团购,但团购只是冰山一角,只是第一步”.O2O营销模式又称离 ...
- OAF_开发系列17_实现OAF数组应用Vector / Hashmap / Hashtable / Arraylist(案例)
20150506 Created By BaoXinjian
- [Linux] IP绑定解释 BindIp
一.缘由: 今天安装Mongodb,本来想限制只能内网或者某几台机器可以访问,看到配置文件有个net.bindIp选项, 就自以为是的认为,他可以像nginx那样限制访问来源IP,其实大错特错.这里配 ...
- 深入理解Bootstrap笔记
框架介绍 1.框架简介 2.CSS基本语法 3.JavaScript基本语法 4.Bootstrap整体架构 5.12栅格系统 6.CSS组件架构设计思想 7.JavaScript插件架构 CSS布局 ...
- dedecms 图片集上传时提示错误信息“(FILEID:1|2|3..)“的解决
网上看到很多朋友遇到使用织梦程序一段时间后,发现上传图集时候老是失败,提示"提示FILEID:X错误,缩略图显示为红色Error"下面截图错误: 这问题今天也让我头疼了半天,好好的 ...
- gradle修改AndroidManifest.xml中的版本号
def VersionCode = "19" ant.replaceregexp(file:"../Assets/Plugins/Android/AndroidManif ...
- mac 下打开多个Eclipse
在Mac下只能打开一个Eclipse工具. 使用下面命令,在控制台中输入,可以打开多个Eclipse. open -n xx/xx/eclipse.app 例子: open -n /Users/use ...
- 主机映射Linux虚拟机硬盘到本地
Windows7上面通过VMware装了一个ubuntu的虚拟机,为了方便在window下直接查看和编辑linux系统下的代码,就想着远程映射硬盘,把Ubuntu的硬盘映射到主机中. 硬盘映射需要Sa ...
- Struts2基础使用教程:OGNL
取自<JAVAWEB整合开发王者归来> 是一种类似EL的语言,比EL强大的多 能访问对象的方法,例如list.size() 能访问静态属性与静态方法,方法是在类名前.方法前加上@.如@ja ...