B. Looksery Party
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/549/problem/B
Description
The Looksery company, consisting of n staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends messages to his contacts about how cool it is. At the same time everyone is trying to spend as much time on the fun as possible, so they send messages to everyone without special thinking, moreover, each person even sends a message to himself or herself.
Igor and Max, Looksery developers, started a dispute on how many messages each person gets. Igor indicates n numbers, the i-th of which indicates how many messages, in his view, the i-th employee is going to take. If Igor guesses correctly at least one of these numbers, he wins, otherwise Max wins.
You support Max in this debate, so you need, given the contact lists of the employees, to determine whether there is a situation where Igor loses. Specifically, you need to determine which employees should come to the party, and which should not, so after all the visitors send messages to their contacts, each employee received a number of messages that is different from what Igor stated.
Igor and Max, Looksery developers, started a dispute on how many messages each person gets. Igor indicates n numbers, the i-th of which indicates how many messages, in his view, the i-th employee is going to take. If Igor guesses correctly at least one of these numbers, he wins, otherwise Max wins.
You support Max in this debate, so you need, given the contact lists of the employees, to determine whether there is a situation where Igor loses. Specifically, you need to determine which employees should come to the party, and which should not, so after all the visitors send messages to their contacts, each employee received a number of messages that is different from what Igor stated.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of employees of company Looksery.
Next n lines contain the description of the contact lists of the employees. The i-th of these lines contains a string of length n, consisting of digits zero and one, specifying the contact list of the i-th employee. If the j-th character of the i-th string equals 1, then the j-th employee is in the i-th employee's contact list, otherwise he isn't. It is guaranteed that the i-th character of the i-th line is always equal to 1.
The last line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ n), where ai represents the number of messages that the i-th employee should get according to Igor.
Next n lines contain the description of the contact lists of the employees. The i-th of these lines contains a string of length n, consisting of digits zero and one, specifying the contact list of the i-th employee. If the j-th character of the i-th string equals 1, then the j-th employee is in the i-th employee's contact list, otherwise he isn't. It is guaranteed that the i-th character of the i-th line is always equal to 1.
The last line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ n), where ai represents the number of messages that the i-th employee should get according to Igor.
Output
In the first line print a single integer m — the number of employees who should come to the party so that Igor loses the dispute.
In the second line print m space-separated integers — the numbers of these employees in an arbitrary order.
If Igor wins the dispute in any case, print -1.
If there are multiple possible solutions, print any of them.
Sample Input
3
101
010
001
0 1 2
Sample Output
1
1
HINT
题意
每个人都热衷发短信,就是每个人会给一个电话本,然后有个人就在猜每个人能够收到多少个短信,然后让你构造出一个数据,把这个cha掉
题解:
d[i]表示每个人还要收到多少个短信,遇到d[i]=0的就表示这个人已经符合条件了,所以我们就得派出这个人,因为每个人必然会给自己发短信,所以就不符合了
然后就用这个思路,直接扫一遍就好了
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 2000001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** string s[maxn]; int d[maxn]; vector<int> ans; int main() { //test; int n=read(); for(int i=0;i<n;i++) cin>>s[i]; for(int i=0;i<n;i++) d[i]=read(); while(1) { int flag=0; for(int i=0;i<n;i++) { if(d[i]==0) { flag++; for(int j=0;j<s[i].size();j++) { if(s[i][j]=='1') d[j]--; } ans.push_back(i+1); } } if(flag==0) break; } printf("%d ",ans.size()); sort(ans.begin(),ans.end()); for(int i=0;i<ans.size();i++) cout<<ans[i]<<" "; }