CF549B Looksery Party

贪心

这题根本没有无解的情况。。。因为所有人都不去也是一种方案。。。

那么如何贪呢?我们发现,除了a[i]==0的人,其他人都可以不参加,但是a[i]==0的人认识自己,所以他参加了就可以满足条件,那么相应的他认识的人能接受的信息条数就要减一,然后判断是不是a[k]==0等于就继续更新,然后就没有然后了

代码

//By AcerMo
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=500;
int ans=0;
int jud[M];
int n,a[M];
int map[M][M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;	
} 
int main()
{
	n=read();char s[M][M];
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
	for (int k=1;k<=n;k++)
	map[i][k]=s[i][k]-'0';
	for (int i=1;i<=n;i++) a[i]=read();
	while (1)
	{
		int i=1;
		while (i<=n)
			if (a[i]==0) break;
				else i++;
		if (i==n+1) break;
		jud[i]=1;ans++;
		for (int k=1;k<=n;k++)
			if (map[i][k]) a[k]--;
	}
	cout<<ans<<endl;
	for (int i=1;i<=n;i++)
		if (jud[i]) cout<<i<<" ";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/acerandaker/article/details/81069838