今日头条2017编程--手串

#include <iostream>
#include <vector>

using namespace std;

//该颜色是否合格
bool IsOk(vector<int> &a, int m)
{
	int n = a.size() - 1;
	for (int i = 1; i <= n; ++i)
	{
		vector<int> tmpV(m);
		int tmp = 0;
		for (int j = 0; j < tmpV.size(); ++j)
		{
			tmpV.at(j) = i + j;
			if (tmpV.at(j) > n)
				tmpV.at(j) = tmpV.at(j) - n;
			tmp += a.at(tmpV.at(j));
		}
		if (tmp > 1)
			return false;
	}
	return true;
}

int main() {
	//输入部分
	int n, m, c;
	cin >> n >> m >> c;
	vector<vector<int> > iVec(n + 1, vector<int>(c + 1, 0));
	int t;
	int count;
	for (int i = 0; i < n; ++i)
	{
		cin >> count;
		while (count > 0)
		{
			cin >> t;
			iVec.at(i + 1).at(t) = 1;
			count--;
		}
	}
	//矩阵转置
	vector<vector<int> > twoMat(c + 1, vector<int>(n + 1, 0));
	for (int i = 1; i <= c; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			twoMat.at(i).at(j) = iVec.at(j).at(i);
		}
	}
	//调用函数对每种情况进行考察
	int res = 0;
	for (int i = 1; i <= c; ++i)
	{
		if (!IsOk(twoMat.at(i), m))
			res++;
	}
	cout << res << endl;

	system("pause");
	return 0;
}


#字节跳动#
全部评论
LZ可以阐述一下算法思路么?
点赞 回复 分享
发布于 2017-09-11 09:16

相关推荐

不愿透露姓名的神秘牛友
12-10 15:21
华为-媒体院 算法 n*16 硕士985
点赞 评论 收藏
分享
12-15 11:27
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务