`
he91_com
  • 浏览: 375928 次
文章分类
社区版块
存档分类
最新评论

3364 Lanterns (异或方程组高斯消元)

 
阅读更多

基本思路。首先构造一个n*(m+1)的矩阵,同时标记一个行数row,row从零开始,然后找出每一列第一个非零的数,和第row行互换,

然后对row到n行,异或运算。最终的结果为2^(m-row)

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int array[55][55],n,m,h[55][55];
int main()
{
	int i,j,k,t,a,q;
	scanf("%d",&t);
	for(int v=1;v<=t;v++)
	{
		memset(array,0,sizeof(array));
		memset(h,0,sizeof(h));
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++)
		{
			scanf("%d",&k);
			while(k--)
			{
				scanf("%d",&a);
				array[a-1][i]=1;
			}
		}
		for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			h[i][j]=array[i][j];
		printf("Case %d:\n",v);
		scanf("%d",&q);
		while(q--)
		{
			for(i=0;i<n;i++)
			for(j=0;j<m;j++)
				array[i][j]=h[i][j];
			for(i=0;i<n;i++)
				scanf("%d",&array[i][m]);
			/*for(i=0;i<n;i++)
			{
				for(j=0;j<=m;j++)
					printf("%d ",array[i][j]);
				printf("\n");
			}*/
			__int64 ans=1;
			int row=0;
			for(i=0;i<m;i++)
			{
				for(j=row;j<n;j++)
					if(array[j][i])
						break;
				if(j==n)continue;
				if(j!=row)
				{
					for(k=0;k<=m;k++)
						swap(array[row][k],array[j][k]);
				}
				for(j=row+1;j<n;j++)
				{
					if(array[j][i])
					{
						for(k=0;k<=m;k++)
							array[j][k]^=array[row][k];
					}
				}
				row++;//这里不用担心row超过n,因为从n行开始,每行的数字都是0
			}
				for(j=row;j<n;j++)
					if(array[j][m])
					{
						ans=0;
						break;
					}
				int tmp=m-row;
				while(tmp--)
					ans*=2;
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


分享到:
评论

相关推荐

    UL 1576-2020 Flashlights and Lanterns.pdf

    UL 1576-2020 Flashlights and Lanterns.pdf

    Making sky lanterns from polygonal meshes

    Making sky lanterns from polygonal meshes

    The thirteen lanterns-开源

    用于记录麻将分数的 Web 应用程序。 应用程序记录组合并自动计算积分。 可以为所有玩过的游戏编辑玩家统计数据。 详情请见主页 http://mastermahjong.sourceforge.net

    Guiding-Lanterns:纠结和公共bot的官方Discord bot

    (以前称为“电晕的灯笼”) R /纠结的官方Discord bot 该项目已关闭,,请参见 屏幕截图 提及机器人(随机消息) 获取并更改前缀 发送您喜欢的电影的屏幕截图,图片和GIF! ... 随机报价(根据您的电影) ...

    Lanterns-script:Maya的Python脚本,可为Lights场景随机复制和放置灯笼

    灯笼脚本Maya的Python脚本,可为Lights场景随机复制和放置灯笼我在一个晚上基于Tangled的灯笼场景创建了这个场景,以便在Maya中练习Python脚本和建模。 该脚本将选定的灯笼重复5次,并将每个新实例放置在空间中稍微...

    Low Poly City Asset

    - 3 Lanterns - 3 Trash bins (5 prefabs) - 6 Flowers - 3 Parks - Bus station (2 prefabs) - hydrant, gate, table and others (11 prefabs) City structure parts: - roads (13 prefabs) - grass (4 prefabs) ...

    Deconstructing.Google.Cardboard.Apps.B016ETVGDA

    Google Cardboard is one of the most accessible ways to experience virtual reality today....Chapter 4 Lanterns and a Village for Cardboard Chapter 5 Google Cardboard - VR for the Masses

    Stone Lantern V1.0 (MC 1.5.1/1.5.2):开源-开源

    为什么在 Minecraft 中需要它: - Jack-O-Lanterns:我厌倦了必须找到南瓜。 然后必须种植,等待它们生长并收获它们。 你甚至不能在没有方块的情况下放置 Jack-O-Lanterns。 无论如何,谁愿意一直看着它? - 红石...

    灯笼

    Invision应用程序: ://invis.io/6X104DVF3JAH#/444085855_Explore_Lanterns应用程序预览: : 与设计师核对: 检查以不同字母表示的Pangram。 例如,波兰语没有全部字符Pchnąć w tę łódź jeża lub ośm skrzy...

    智能照明控制系统的设计.doc

    including sunlight intensity measurement circuit and pyroelectric infrared human measurement circuit, digital adjustable photoelectron ballast and lamps and lanterns and related software. System with...

Global site tag (gtag.js) - Google Analytics