Ghostbusters

时间限制: 1 Sec  内存限制: 128 MB
提交: 33  解决: 7
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The Bureau of Approved Peripherals for Computers (BAPC) is designing a new standard for computer keyboards. With every new norm and regulation, hardware becomes obsolete easily, so they require your services to write firmware for them.
A computer keyboard is an array of M rows and N columns of buttons. Every button has an associated probability. Furthermore, every column and every row of buttons has an associated cable, and every pressed button connects their row cable with their column cable (and vice versa!). The keyboard detects key presses by “sampling”. It sends an electric signal through the first row. This signal spreads to columns that are connected to it through pressed buttons
on that column and to rows connected to these columns through other pressed buttons and so on. Every row or column that is connected, possibly indirectly, to the original row via pressed buttons receives the signal. The firmware stores which columns have received the signal. This process is repeated for every row.
It is easy to identify what was pressed if only one key was pressed. In this case only one pair (row, column) will make contact. But keyboards allow to press more than one key at the same time and unfortunately some combinations of key presses are impossible to tell apart. 
This phenomenon is called “ghosting”. For example, in a 2 × 2 keyboard, all combinations of three or four presses are impossible to tell apart, since every pair (row, column) makes electric contact (maybe indirectly), as can be seen in Figure 3.

Figure 3: Four examples of connected wires in a keyboard. Bold lines of the same colour indicate wires that are connected via pressed buttons, which are depicted as red dots. The two sets of pressed buttons on the right cannot be distinguished from each other, since they connect the same rows and columns.
The BAPC wants to deal with the problem of ghosting by finding the most likely combination of pressed keys that could have produced a particular set of signals.

输入

The input consists of
• A line containing two integers, M the number of rows of the keyboard and N the number of columns, with 1 ≤ M, N ≤ 500. 
• M lines with N numbers each, where the jth number in the ith line indicates the probability 0 < p < 0.5 that the key in row i and column j is pressed. Here 0 ≤ i ≤ M − 1 and 0 ≤ j ≤ N − 1.
• M lines, each with an integer 0 ≤ k ≤ N and a list of k integers. The list of integers on the ith line indicates the columns that received the signal emitted by the ith row.

输出

Output the set of pressed keys that is most likely given the input. Any solution that achieves the maximum probability will be accepted. For each pressed key output a line with two integers r and c, separated by a space, indicating the row r and the column c of the key. The lines must be outputted in lexicographical order, that is, output first the keys whose row is lower and if the rows are the same output first the key whose column is lower.

样例输入

2 2
0.1 0.4
0.4 0.4
2 0 1
2 0 1

样例输出

0 1
1 0
1 1

思路:题意晦涩难懂,读明白就非常简单!

AC代码:

 #include <bits/stdc++.h>
using namespace std;
struct UnionFind
{
vector<int> par,ra,si;
int c;
UnionFind(int n):par(n),ra(n,),si(n,),c(n)
{
for(int i=;i<n;++i) par[i]=i;
}
int findd(int i)
{
return (par[i]==i?i:(par[i]=findd(par[i])));
}
bool same(int i,int j)
{
return findd(i)==findd(j);
}
int get_size(int i)
{
return si[findd(i)];
}
int countt()
{
return c;
}
void merg(int i, int j)
{
if((i=findd(i))==(j=findd(j))) return;
c--;
if(ra[i]>ra[j]) swap(i,j);
par[i]=j;
si[j]+=si[i];
if(ra[i]==ra[j]) ra[j]++;
}
};
struct prob
{
double p;
int r,c;
};
bool cmp(const prob &l, const prob &r)
{
return l.p>r.p;
}
bool super_cmp(const prob &l,const prob &r)
{
return tie(l.r,l.c)<tie(r.r,r.c);
}
int main()
{
int m,n;
scanf("%d %d",&m,&n);
vector<prob> ps;
ps.reserve(m*n);
for(int r=;r<m;++r)
{
for(int c=;c<n;++c)
{
prob p{,r,c};
scanf("%lf",&p.p);
ps.push_back(p);
}
}
UnionFind target(m+n),cur(m+n);
for(int r=;r<m;++r)
{
int k,c;
scanf("%d",&k);
while(k--) scanf("%d",&c),target.merg(r,m+c);
}
sort(ps.begin(),ps.end(),cmp);
vector<prob> ans;
for(auto &p:ps)
{
if(target.same(p.r,m+p.c) && !cur.same(p.r,m+p.c))
{
cur.merg(p.r,m+p.c),ans.push_back(p);
}
}
sort(ans.begin(),ans.end(),super_cmp);
for(auto &x:ans) printf("%d %d\n",x.r,x.c);
return ;
}

最新文章

  1. 的vim和emacs常用配置记录
  2. MapWinGIS.ocx 注册
  3. 使用Sublime Text3开发AngularJs
  4. Linux常用命令笔记
  5. Eclipse Memory Analyzer,内存泄漏插件,安装使用一条龙
  6. 在uwp中复活常用的vb库函数
  7. CC Debugger调试下载接口
  8. 【C++Q】
  9. POJ3080 - Blue Jeans(KMP+二分)
  10. Symmetry(对称轴存在问题)
  11. Delphi获取当前系统时间(使用API函数GetSystemTime)
  12. mysql数据库修改数据库编码,字段编码与表编码(转) good
  13. 生成JSON数据--Gson(谷歌)方法
  14. Mybatis foreach标签含义
  15. db2 runstats和reorg
  16. 【托业】【新东方托业全真模拟】TEST05~06-----P5~6
  17. 如何在cygwin中运行crontab定时脚本[利刃篇]
  18. python的类变量和对象变量[转]
  19. web前端学习笔记:文本属性
  20. Crash dump进程信息

热门文章

  1. mc02_配置本地git仓库并上传到github
  2. python 之 paramiko
  3. plSql添加快捷键设置
  4. Silverlight 用DependencyProperty 自定义ImageButton控件 定义属性
  5. Android studio配置push commits
  6. HTML6即将到来,你没有看错是HTML6
  7. (转)AIX下的MPIO、RDAC、SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系)
  8. (转)linux route命令深入浅出与实战案例精讲
  9. 3n+1猜想
  10. java.lang.IllegalStateException: FragmentManager is already executing transactions 及 SmartTabLayout复用