[CF442A] Borya and Hanabi (暴力bitmask)
题目链接:http://codeforces.com/problemset/problem/442/A
题目大意:给你n张卡片,你知道这n张卡片都是什么,但是不知道他们的位置。你每次可以请求朋友指出一种颜色的卡片,或者一种数字的卡片。问你最少需要多少次能够知道每个卡片的位置。
首先,如果其他所有卡片都知道了,最后一张卡片不需要指示就知道了。
然后我们枚举哪张是最后一张卡片。
将五种颜色放在x轴,5个数字放在y轴。
一次询问就是画一条线,先去掉交叉点,再看剩下的点是不是唯一在一条直线里。
bitmask,一共最多25条线。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <numeric>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ size()
#define ST begin()
#define ED end()
#define CLR clear()
#define ZERO(x) memset((x),0,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const double EPS = 1e-; struct POINT{
int x,y;
int hash,idx;
}; int n,tot;
vector<POINT> pts;
set<int> se;
vector<POINT> vx[],vy[]; POINT GetPoint(const char* buf){
POINT res;
if( buf[] == 'R' ) res.x = ;
else if( buf[] =='G' ) res.x = ;
else if( buf[] == 'B' ) res.x = ;
else if( buf[] == 'Y' ) res.x = ;
else if( buf[] == 'W' ) res.x = ;
res.y = buf[] -'';
res.hash = res.x*+res.y;
return res;
} void SplitPoints() {
for(int i=;i<pts.size();i++){
POINT &pt = pts[i];
vx[pt.x].PB(pt);
vy[pt.y].PB(pt); // printf("vx[%d].PB(%d)\n",pt.x,pt.idx);
// printf("vy[%d].PB(%d)\n",pt.y,pt.idx);
}
} bool check(int mask,int out) { int vis[];
for(int i=;i<;i++) vis[i] = ; for( int i=;i<;i++ ){
if( (mask>>i)& ) {
int now = i+;
if(now<=) {
if( vx[now].size()== ) return false;
} else {
now -= ;
if( vy[now].size()== ) return false;
}
}
} // if(mask==261) puts("****"); for( int i=;i<;i++ ) {
if( (mask>>i)& ) {
int now = i+;
// if(mask==261) printf("now i=%d\n",now);
if( now<= ) {
for(int j=;j<vx[now].size();j++){
if( vis[vx[now][j].idx] == ) continue;
vis[vx[now][j].idx]++;
}
} else {
now -= ;
for(int j=;j<vy[now].size();j++){
if( vis[vy[now][j].idx]== ) continue;
vis[vy[now][j].idx]++;
}
}
}
} for(int i=;i<;i++){
if( (mask>>i)& ) {
int now = i+;
if( now<= ) {
// x
int cnt = ;
for(int j=;j<vx[now].size();j++) if(vis[vx[now][j].idx]<) cnt++;
if( cnt== ) {
for(int j=;j<vx[now].size();j++) if( vis[vx[now][j].idx] < )
{
vis[vx[now][j].idx] = ; break;
}
}
} else {
// y
now -= ;
int cnt = ;
for(int j=;j<vy[now].size();j++) if(vis[vy[now][j].idx]<) cnt++;
if( cnt== ) {
for(int j=;j<vy[now].size();j++) if(vis[vy[now][j].idx]<){
vis[vy[now][j].idx] = ;
break;
}
}
}
}
} bool res = true;
for(int i=;i<tot;i++){
// printf("vis[%d]=%d\n",i,vis[i]);
if(vis[i]<&&i!=out) {
res = false;
break;
}
} return res;
} int main() {
tot = ;
scanf("%d",&n);
for(int i=;i<n;i++){
char buf[];
scanf("%s",buf);
POINT pt = GetPoint(buf);
if( se.find(pt.hash) == se.end() ){
se.insert(pt.hash);
pt.idx = tot++;
pts.PB(pt);
}
} // for(int i=0;i<pts.size();i++){
// printf("%d,%d\n",pts[i].x,pts[i].y);
// }
// printf("size = %d\n",pts.size()); SplitPoints();
int ans = *tot;
for(int i=;i<(<<);i++) {
for(int j=;j<tot;j++){
if( check(i,j) ) {
//if(__builtin_popcount(i)==10&&fff==-1) printf("i=%d , ans = %d\n",i,__builtin_popcount(i));
ans = min( ans,__builtin_popcount(i) );
}
}
}
// printf("tot = %d\n", tot);
printf("%d\n",ans);
return ;
}
[CF442A] Borya and Hanabi (暴力bitmask)的更多相关文章
- codeforces 422A A. Borya and Hanabi(暴力)
题目链接: A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力
A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/p ...
- Codeforces Round #253 (Div. 1) A Borya and Hanabi
A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #253 (Div. 2)——Borya and Hanabi
题目连接 题意: n表示有n个卡片.每一个卡片有一种颜色和一个数字(共五种不同的颜色和五个不同的数字). 事先知道每种卡片有几张.可是不知道详细的位置. 问须要几次提示就能够知道全部卡片的位置都在哪里 ...
- Codeforces 442A Borya and Hanabi
有五种花色 外加 五种点数 共25张牌,每次有n张牌,主人知道这n张牌中有哪些牌,并且哪种牌有几张,但是不知道具体是哪张牌,他可以问某种花色,然后知道了哪几张是该花色,也可以问点数,然后就知道了哪几张 ...
- Codeforces442A
A. Borya and Hanabi time limit per test:2 seconds memory limit per test: 256 megabytes input:standar ...
- Codeforces Round 253 (Div. 2)
layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces 442A
题目链接 A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- zone.js - 暴力之美
在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...
随机推荐
- robotframework接口测试初探2
python这个requests模块常被用来测试接口.使用RequestLibrary库测试之前,先来看下这个模块是怎样使用的 最简单的调用是 r=requests.get("http:// ...
- 透过代码理解python的静态方法、类方法与实例方法
话不多说,直接上程序: a = 111 class A(object): a = 1 def f_instance(self): print self.a @staticmetho ...
- eclipse点不出方法
window→preferences→java→editor→Content Assist→Advanced
- matlab小段代码学习
matlab读hdf文件到txt filename='E:\data\H1BDLD10110607231863921.L2B.HDF'; h=hdftool(filename); Latitude = ...
- cloudera manager安装spark后使用spark shell编写基于scala的world count
val file = sc.textFile("hdfs://zhcloudil-lcnode04:8020/user/cloudil/wc_spark.txt") val cou ...
- id生成策略 id工具类
import java.util.Random; /** * 各种id生成策略 * <p>Title: IDUtils</p> * <p>Description: ...
- nginx入门篇----功能特性
1.nginx功能特性 可以作为http服务器或者反向代理服务器 能够快速响应静态页面(html)的请求 支持FastCGI.SSL.Virtual Host.URL Rewrite.HTTP.Gzi ...
- iScroll知识点
1.如果你有一个复杂的DOM结构,最好在onload事件之后适当的延迟,再去初始化iScroll.最好给浏览器100或者200毫秒的间隙再去初始化iScroll. 2.iScroll作用于滚动区域的外 ...
- backbone学习总结(一)
入职第三天,新公司项目用到backbone+underscore+require等框架,前两天把项目的开发环境都配置好啦,项目也能跑起来,现在准备好好学习公司自己的框架以及用到的框架,有点想吐槽,开发 ...
- 实战之中兴ZXHN F460光猫破解超级密码+开启无线路由功能
本文面向小白用户,即使你不懂电脑看完你也会破解光猫,网上有些文章的操作方法是错误的.按照我这篇文章,只要型号对,那么肯定没问题!电信光纤入户,家里用的是电信送的中兴查看 ZXHN F460 中的全部文 ...