B. Looksery Party
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/549/problem/B
Description
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
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[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s[maxn];
int d[maxn];
vector<int> ans;
int main()
{
//test;
int n=read();
for(int i=;i<n;i++)
cin>>s[i];
for(int i=;i<n;i++)
d[i]=read();
while()
{
int flag=;
for(int i=;i<n;i++)
{
if(d[i]==)
{
flag++;
for(int j=;j<s[i].size();j++)
{
if(s[i][j]=='')
d[j]--;
}
ans.push_back(i+);
}
}
if(flag==)
break;
}
printf("%d\n",ans.size());
sort(ans.begin(),ans.end());
for(int i=;i<ans.size();i++)
cout<<ans[i]<<" ";
}