穷举法破解集合小游戏~

游戏网站:http://www.setgame.com/puzzle/set.htm

游戏规则:

1、三种颜色(红、绿、紫)

2、三种外形(方形、椭圆形、花形)

3、三种背景阴影(实心、点、轮廓)

4、三种个数(1、2、3)

找出其中 3 个,满足:要么其中属性全相同,要么属性全不相同。

 

破解思路:穷举所有3个一组的情形,找出满足的。

源代码:

package com.gq.algorithm;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SetPlay {
List<Item> items = new ArrayList<Item>();
private void init()
{
items.add( new Item(Color.RED, 		Shape.FLORIATED, 	Shading.DOT, 	3) );
items.add( new Item(Color.PURPLE, 	Shape.SQUARENESS, 	Shading.LINE, 	2) );
items.add( new Item(Color.RED, 		Shape.FLORIATED, 	Shading.DOT, 	2) );
items.add( new Item(Color.GREE, 	Shape.ELLIPSE, 		Shading.LINE, 	2) );
items.add( new Item(Color.PURPLE, 	Shape.FLORIATED, 	Shading.DOT, 	3) );
items.add( new Item(Color.RED, 		Shape.ELLIPSE, 		Shading.DOT, 	2) );
items.add( new Item(Color.GREE, 	Shape.FLORIATED, 	Shading.DOT, 	3) );
items.add( new Item(Color.RED, 		Shape.FLORIATED, 	Shading.DOT, 	1) );
items.add( new Item(Color.GREE, 	Shape.ELLIPSE, 		Shading.SOLID, 	2) );
items.add( new Item(Color.RED, 		Shape.SQUARENESS, 	Shading.LINE, 	1) );
items.add( new Item(Color.GREE, 	Shape.ELLIPSE, 		Shading.LINE, 	3) );
items.add( new Item(Color.PURPLE, 	Shape.SQUARENESS, 	Shading.SOLID, 	3) );
}
private void play()
{
for( int i=0 ; i<items.size()-2 ; i++ )
{
for( int j=i+1 ; j<items.size()-1 ; j++ )
{
for( int k=j+1 ; k<items.size() ; k++ )
{
if( isSet( items.get(i), items.get(j), items.get(k)) )
{
System.out.println( "{" + (i+1) + ", " + (j+1) + ", " + (k+1) + "}" );
}
}
}
}
}
private boolean isSet( Item... items)
{
Map<Color, Integer> colorCount = new HashMap<Color, Integer>();
Map<Shape, Integer> shapeCount = new HashMap<Shape, Integer>();
Map<Shading,Integer> shadingCount = new HashMap<Shading,Integer>();
Map<Integer,Integer> numCount = new HashMap<Integer,Integer>();
for( Item item : items )
{
// 颜色
if( colorCount.get( item.getColor() ) == null )
{
colorCount.put( item.getColor(), 1);
}
else
{
int count = colorCount.get( item.getColor() );
colorCount.put( item.getColor(), ++count );
}
// 形状
if( shapeCount.get( item.getShape()) == null )
{
shapeCount.put( item.getShape(), 1 );
}
else
{
int count = shapeCount.get( item.getShape() );
shapeCount.put( item.getShape(), ++count );
}
// 背景阴影
if( shadingCount.get( item.getShading()) == null )
{
shadingCount.put( item.getShading(), 1 );
}
else
{
int count = shadingCount.get( item.getShading() );
shadingCount.put( item.getShading(), ++count );
}
// 个数
if( numCount.get( item.getNum()) == null )
{
numCount.put( item.getNum(), 1 );
}
else
{
int count = numCount.get( item.getNum() );
numCount.put( item.getNum(), ++count );
}
}
if( isAllSameOrAllDiff( colorCount.size() ) 
&& isAllSameOrAllDiff( shapeCount.size()) 
&& isAllSameOrAllDiff( shadingCount.size())
&& isAllSameOrAllDiff( numCount.size()) )
{
return true;
}
return false;
}
private boolean isAllSameOrAllDiff( Integer count )
{
if( count == null )
{
return false;
}
if( count == 1 || count == 3 )
{
return true;
}
return false;
}
public static void main(String[] args) 
{
SetPlay setPlay = new SetPlay();
setPlay.init();
setPlay.play();
}
}
class Item{
private final Color color;
private final Shape shape;
private final Shading shading;
private final int num;
public Item(Color color, Shape shape, Shading shading, int num) {
super();
this.color = color;
this.shape = shape;
this.shading = shading;
this.num = num;
}
public Color getColor() {
return color;
}
public Shape getShape() {
return shape;
}
public Shading getShading() {
return shading;
}
public int getNum() {
return num;
}
}
enum Color{
/**
* 红色
*/
RED,
/**
* 绿色
*/
GREE,
/**
* 紫色
*/
PURPLE
}
enum Shape{
/**
* 方形
*/
SQUARENESS,
/**
* 椭圆形
*/
ELLIPSE,
/**
* 花形
*/
FLORIATED
}
enum Shading{
/**
* 实心
*/
SOLID,
/**
* 点
*/
DOT,
/**
* 轮廓
*/
LINE
}


 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/497782.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AI时代数据之争,我们需要什么样的“数据权”?

来源&#xff1a; 腾讯研究院作者&#xff1a;田小军 腾讯研究院高级研究员1、未来是AI云端的数据竞争时代“兵无常势&#xff0c;水无常形”&#xff0c;今年11月4日&#xff0c;我国《反不正当竞争法》历时24年后首次修订&#xff0c;专设“互联网专条”用以规制互联网行业竞…

android点击通知后消失,通知栏点击后消失解决方法

通知栏点击后消失怎么使通知栏点击后消失啊&#xff1f;以下为我的代码&#xff0c;能实现将信息放入通知栏&#xff0c;但是点击后不消除。。。private void showNotification(String temp) {// 创建一个NotificationManager的引用NotificationManager notificationManager (…

Struts2 的Action 命名重复检测

原因&#xff1a;在实际项目中发现 <action /> 的 name 重复时候&#xff0c;Struts2 并不会报错而是随意找一个去执行&#xff01; 为了避免重复的情况发生&#xff0c;特地写了一个检测的程序&#xff1a; package barcode;import java.io.IOException; import java.i…

预测性智能的力量:AI 和机器学习将如何改变美国政府决策?

来源&#xff1a;36Kr在每个联邦机构中&#xff0c;重要的见解都隐藏在这些年来收集的大量数据集中。 但是由于美国联邦政府数据科学家的匮乏&#xff0c;如果真的要这么做的话&#xff0c;那么从这些数据中提取价值是非常耗时的。 然而&#xff0c;随着数据科学&#xff0c;人…

android 源码分析notification,# Notification 源码分析

引言notification.jpgNotification 在v7版本下从4.0后增加了Media Style. 今天我们分析下Notification在v7版本的源码。有助于我们针对不同版本的Notification做出合适样式选择。Notification使用流程现在我们使用Notification基本都是如下步骤:NotificationCompat.Builder bui…

广州签发全国首张微信身份证,AI成主要证明技术

来源&#xff1a;人工智能学家AItists概要&#xff1a;12月25日&#xff0c;广州市公安局南沙区分局、腾讯、建设银行等10余家单位发起的“微警云联盟”在广州南沙成立&#xff0c;现场签发了全国首张微信身份证“网证”。12月25日&#xff0c;广州市公安局南沙区分局、腾讯、建…

android底层设置相机帧率,Android Camera previewFrame 提高 fps

/*** http://my.oschina.net/lifj/blog/705104**/在做Camera预览的时候&#xff0c;通过PreviewFrame()方法获取数据&#xff0c;但是发现fps很低&#xff0c;一直在10~12fps徘徊。当然&#xff0c;有人推荐使用setPreviewCallbackWithBuffer。试了一下&#xff0c;fps没有明显…

android 视频做背景图片,视频后面怎么加背景图片?安卓手机给视频添加背景图片的方法...

狸窝是帮助用户解决问题 提供教程解决方案 在这个过程中有使用我们自己开发的软件 也有网上找的工具 只要帮助用户解决问题就好&#xff01;同意则往下继续了解学习 ...注意此教程方案是:『安卓手机端教程方案』。很多手机视频分享平台对视频参数都会有要求&#xff0c;手机上大…

MySQL中information_schema

来源&#xff1a;http://hi.baidu.com/starsw001/item/d151bd591cfb7f01e7c4a557 大家在安装或使用MYSQL时&#xff0c;会发现除了自己安装的数据库以外&#xff0c;还有一个information_schema数据库。 information_schema数据库是做什么用的呢&#xff0c;使用WordPress博客…

量子计算远没到可收割的时候

来源&#xff1a;风云之声概要&#xff1a;我们重视量子计算&#xff0c;是因为它的潜力&#xff0c;而不是它的现状。它确实有革命性的潜力&#xff0c;只是还需要艰苦的努力&#xff0c;绝不是一蹴而就的&#xff0c;更不是已经处在商业盈利的边缘&#xff0c;等着大家一哄而…

android 通知灯 测试,Android灯光系统通知灯【转】

标签&#xff1a;一、通知灯应用程序的编写1、首先实现一个按钮功能xmlns:tools"http://schemas.android.com/tools" android:layout_width"match_parent"android:layout_height"match_parent" android:paddingLeft"dimen/activity_horizon…

简评黑客利器——中国菜刀

来源&#xff1a;http://edu2b.sinaapp.com/?p236&replytocom17 作者&#xff1a;XXX 我是一个玩黑很多年的人&#xff0c;入侵了大大小小的服务器无数&#xff0c;体验着入侵快感的同时&#xff0c;自己的技术和经验也不断提高&#xff0c;在渗透过程中收集了大大小小的…

2017,AI偏见为何如此受关注?

来源&#xff1a;亿欧概要&#xff1a;从荒谬到令人不寒而栗&#xff0c;算法偏见在社会中产生越来越大的影响&#xff0c;而且这一问题已经暴露多年。但直到2017年&#xff0c;人们对AI算法偏见的公众意识似乎才达到了一个临界点。佛罗里达州的一项犯罪预测算法错误地将黑人罪…

android aidl工具,【Android】AIDL介绍和实例讲解

前言为使应用程序之间能够彼此通信&#xff0c;Android提供了IPC (Inter Process Communication&#xff0c;进程间通信)的一种独特实现&#xff1a; AIDL (Android Interface Definition Language&#xff0c; Android接口定义语言)。网上看了几篇关于AIDL的文章&#xff0c;写…

MySQL新建用户,授权,删除用户,修改密码

来源&#xff1a;http://www.cnblogs.com/analyzer/articles/1045072.html 首先要声明一下&#xff1a;一般情况下&#xff0c;修改MySQL密码&#xff0c;授权&#xff0c;是需要有mysql里的root权限的。 注&#xff1a;本操作是在WIN命令提示符下&#xff0c;phpMyAdmin同样…

机器学习 TOP 10 必读论文 | 资源

来源&#xff1a;AI科技大本营编辑 | DonnaMedium上的机器学习深度爱好者必关注的账号Mybridge照例对11月发表的学术论文进行了排名&#xff0c;整理出了10篇必读论文&#xff0c;建议收藏深读。1. Alpha Zero&#xff1a;用强化学习算法对中国象棋和国际象棋进行自我修炼&…

爱奇艺首页底部导航按钮android,仿爱奇艺/腾讯视频ViewPager导航条实现

仿爱奇艺/腾讯视频ViewPager导航条实现&#xff0c;支持自定义导航条高度&#xff0c;宽度&#xff0c;颜色变化&#xff0c;字体大小变化。支持多种滚动模式&#xff0c;支持自定义每个TabView的样式。项目地址&#xff1a;https://github.com/KCrason/DynamicPagerIndicatord…

详解MYSQL数据库密码的加密方式及破解方法

来源&#xff1a;http://www.heibai.net/articles/hacker/mimapojie/2009/0908/841.html MYSQL数据库用户密码跟其它数据库用户密码一样&#xff0c;在应用系统代码中都是以明文出现的&#xff0c;在获取文件读取权限后即可直接从数据库连接文件中读取&#xff0c;例如asp代码中…

4-Docker命令之docker logs

1.docker logs介绍 docker logs命令是用来获取docker容器的日志 2.docker logs用法 docker logs [参数] CONTAINER [root@centos79 ~]# docker logs --helpUsage: docker logs [OPTIONS] CONTAINERFetch the logs of a containerAliases:docker container logs, docker lo…

亚马逊等智能音箱“偷听”用户 被指收集隐私

来源&#xff1a;中国评论通讯社概要&#xff1a;近日&#xff0c;美国消费者保护组织Consumer Watchdog出具的一份报告显示&#xff0c;来自亚马逊和谷歌的专利申请曝光了其智能音箱是如何“偷听”用户的。据英国《每日邮报》报道&#xff0c;近日&#xff0c;美国消费者保护…