[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执行过程的上下文,可以在异步任务之间进行持久性 ...
随机推荐
- mysql max_allowed_packet
系统linux > show global max_allowed_packet; >set global max_allowed_packet=1024*1024: 退出mysql,重启 ...
- Hibernate save, saveOrUpdate, persist, merge, update 区别
Hibernate Save hibernate save()方法能够保存实体到数据库,正如方法名称save这个单词所表明的意思.我们能够在事务之外调用这个方法,这也是我不喜欢使用这个方法保存数据的原 ...
- python 获取html源代码里标签之间的文本用get_text()
例: 输出<span class="w-txt">分享</span>中的文本"分享" contents = bsObj.find_all ...
- ios系统(苹果手机)按钮显示为圆角和渐变的问题
按钮在安卓手机上显示正常,但在苹果手机上会显示如下: 解决办法:给该按钮的样式加上:-webkit-appearance:none;这样按钮就会显示正常
- 最小生成树——prim算法
prim算法是选取任意一个顶点作为树的一个节点,然后贪心的选取离这棵树最近的点,直到连上所有的点并且不够成环,它的时间复杂度为o(v^2) #include<iostream>#inclu ...
- 安装Adobe系列时遇到的问题解决
安装错误,错误摘要如下: Exit Code: 6 Please see specific errors below for troubleshooting. For example, ERROR: ...
- Atom安装activate-power-mode插件(震动炫酷)
1.下载安装Atom,地址:https://atom.io/ 2.下载安装activate-power-mode插件,地址:https://github.com/JoelBesada/activate ...
- Pyside开篇杂记
最近学习刚开始学习pyside,基本了解了一些类的用法,个人感觉就接触而言与pyqt并无本质区别. 双方资料基本可以相互借鉴,个人更倾向与pyside,查阅资料时也经常会在pyqt内得到解决方案. 之 ...
- 给linux安全模块LSM添加可链式调用模块(一)
前些日子接了个外包的活,了解了一下Linux安全模块,发现了安全模块中的一些问题. 关于linux安全模块LSM在此就不多说了,大家google下就明白了. 这里主要介绍的是如何修改这个模块,使它可链 ...
- label标签使用过程中遇到的问题
最近在做东西时候使用到了label标签,由于之前很少使用label标签,所以就遇到一个很奇怪的问题.什么问题呢?下面来看一个效果 <!DOCTYPE html> <html> ...