[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执行过程的上下文,可以在异步任务之间进行持久性 ...
随机推荐
- 由于OCR文件损坏造成Oracle RAC不能启动的现象和处理方法
v$cluster_interconnects 集群节点间通信使用的IP地址 错误信息 使用了公网进行连接 SQL> select * from v$cluster_interconnects; ...
- PHP 如何获取当前的域名
PHP 如何获取当前的域名.这是PHP最基础的东西,也是用得最多的,记录下来 <? //获取当前的域名: echo $_SERVER['SERVER_NAME']; //获取来源网址,即点击来到 ...
- 4.Rabbits and Recurrence Relations
Problem A sequence is an ordered collection of objects (usually numbers), which are allowed to repea ...
- jQuery中的Ajax几种请求方法
在网上查的几种Ajax的请求的方法: jQuery 确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯.废话少说,直接进入正题,我 ...
- groupspecWidhoutAuthorizations与groupspecWidthAuthorizations的区别
GroupSpecifier是一个用来定义group所有参数的类.首先,将它命名为“myGroup/g1”.然后设置 serverChannel与Stratus进行沟通.最后发布.这样,我们就完成了P ...
- oracle执行计划之-表连接方式
转载自:http://blog.csdn.net/tianlesoftware/article/details/5826546 在多表联合查询的时候,如果我们查看它的执行计划,就会发现里面有多表之间的 ...
- underscore.extend.js
/** * 基于underscore的扩展 * @module lib/underscoreExtend */ (function() { // 全局可能用到的变量 var arr = []; var ...
- 将网页另存为PDF文件的方法
使用google chrome浏览器测试,其他浏览器应该也是差不多的方法. 步骤1: 打开需要转换的网页: 步骤2: 点击右上角的三点按键,或者快捷键Ctrl+P,调用的打印页面: 步骤3: 选择目标 ...
- 《Matrix Computation 3rd》读书笔记——第2章 矩阵分析
- SQLServer 数据库查看死锁、堵塞的SQL语句
http://www.cnblogs.com/zhuque/archive/2012/11/08/2763343.html 死锁和堵塞一直是性能测试执行中关注的重点. 下面是我整理的监控sql ser ...