[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执行过程的上下文,可以在异步任务之间进行持久性 ...
随机推荐
- Python::re 模块 -- 在Python中使用正则表达式
前言 这篇文章,并不是对正则表达式的介绍,而是对Python中如何结合re模块使用正则表达式的介绍.文章的侧重点是如何使用re模块在Python语言中使用正则表达式,对于Python表达式的语法和详细 ...
- tab切换效果
选项卡是一个神奇的网页效果,不论大小网站,比如B2B像阿里巴巴,慧聪网,还有B2C这个不用说了吧,爱逛网店的童鞋们都知道的,像京东商城,淘宝网,拍拍网,一号店,凡客诚品,等等各种网各种网店,选项卡不仅 ...
- archlinux vmware一些问题
虚拟机没法上网 sudo modprobe vmnet sudo vmware-network --start
- Roslyn 学习笔记(二)
参考:https://github.com/dotnet/roslyn/wiki/Getting-Started-C%23-Syntax-Analysis 语法分析过程主要用到以下类或结构: Synt ...
- 【剑指offer】出现次数超过一半的数字
题目描述:数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2. ...
- 使用TCP的HelloServer
HelloServer是一个在1234端口监听的服务端程序,它接受客户送来的数据,并且把这些数据解释为响应的ASCII字符,再对客户做出类似“Hello,...!"这样的响应.以下是Hell ...
- ayase系列
[冒个泡]技能视觉效果の自定义 by ayase [11-09 V2.4]任务数量转换属性点的lua脚本 [335]瞎倒腾的item.dbc生成工具..
- LINQ 联表查询 取count 值
linq to sql 实现左外部连接:var query=from a in A join b in B on a.ID equals b.aID into ab from a1 in ab.Def ...
- Asp.net MVC 的八个扩展点
http://www.cnblogs.com/richieyang/p/5180939.html MVC模型以低耦合.可重用.可维护性高等众多优点已逐渐代替了WebForm模型.能够灵活使用MVC提供 ...
- [Nginx] - PHP+FPM相关的配置
CodeIgniter的配置: worker_processes ; events { worker_connections ; } http { include mime.types; defaul ...