暴力状压 [Usaco2007 Open]Fliptile 翻格子游戏

Discrete Optimization (Coursera) 学习笔记 Week 1 introduction (开个帖子) Week 1 Introduction 这位教授Pascal Van Hentenryck 真的算是优化领域神级别的人物了吧?截一张Google scholar的图大家感受一下… 居然在Coursera上看到了他开的课:Discrete Optimization。试听了几节后,发现讲得很有激情,而且深入浅出。遂决定花暑假跟完这一门课。 这门课每周花两三个小时介绍基础概念,然后得花十几个小时写作业(coding)… 一开始以为Coursera上的课的作业应该不会太难,然后第一次作业(knapsack)我就被 阅读详情
 

问题 B: [Usaco2007 Open]Fliptile 翻格子游戏

时间限制: 5 Sec  内存限制: 128 MB

题目描述

Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M x N grid (1 <= M <= 15; 1 <= N <= 15) of square tiles, each of which is colored black on one side and white on the other side. As one would guess, when a single white tile is flipped, it changes to black; when a single black tile is flipped, it changes to white. The cows are rewarded when they flip the tiles so that each tile has the white side face up. However, the cows have rather large hooves and when they try to flip a certain tile, they also flip all the adjacent tiles (tiles that share a full edge with the flipped tile). Since the flips are tiring, the cows want to minimize the number of flips they have to make. Help the cows determine the minimum number of flips required, and the locations to flip to achieve that minimum. If there are multiple ways to achieve the task with the minimum amount of flips, return the one with the least lexicographical ordering in the output when considered as a string. If the task is impossible, print one line with the word "IMPOSSIBLE".

 约翰知道,那些高智力又快乐的奶牛产奶量特别高.所以他做了一个翻瓦片的益智游戏来娱乐奶牛.在一个M×N(1≤M,N≤15)的骨架上,每一个格子里都有一个可以翻转的瓦片.瓦片的一面是黑色的,而另一面是白色的.对一个瓦片进行翻转,可以使黑变白,也可以使白变黑.然而,奶牛们的蹄子是如此的巨大而且笨拙,所以她们翻转一个瓦片的时候,与之有公共边的相邻瓦片也都被翻转了.那么,这些奶牛们最少需要多少次翻转,使所有的瓦片都变成白面向上呢?如杲可以做到,输出字典序最小的结果(将结果当成字符串处理).如果不能做到,输出“IMPOSSIBLE”.

输入

* Line 1: Two space-separated integers: M and N

* Lines 2..M+1: Line i+1 describes the colors (left to right) of row i of the grid with N space-separated integers which are 1 for black and 0 for white

    第1行输入M和N,之后M行N列,输入游戏开始时的瓦片状态.0表示白面向上,1表示黑面向上.

输出

* Lines 1..M: Each line contains N space-separated integers, each specifying how many times to flip that particular location.

    输出M行,每行N个用空格隔开的整数,表示对应的格子进行了多少次翻转.

样例输入

4 4
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1


样例输出

0 0 0 0
1 0 0 1
1 0 0 1
0 0 0 0

OUTPUT DETAILS:

After flipping at row 2 column 1, the board will look like:
0 0 0 1
1 0 1 0
1 1 1 0
1 0 0 1

After flipping at row 2 column 4, the board will look like:
0 0 0 0
1 0 0 1
1 1 1 1
1 0 0 1

After flipping at row 3 column 1, the board will look like:
0 0 0 0
0 0 0 1
0 0 1 1
0 0 0 1

After flipping at row 3 column 4, the board will look like:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

Another solution might be:
0 1 1 0
0 0 0 0
0 0 0 0
0 1 1 0
but this solution is lexicographically higher than the solution above.

提示

    其实和状压并没有太大的关系,只是用来枚举第一行状态。
     因为一个点翻两次又变回原来的颜色,所以要么不翻,要么只翻一次,而且这个点的状态至于他周围四个点及自己翻不翻还有自己初始状态有关。
     如果加和为偶数,那么翻到了白色,
     枚举第一行的状态,那么他最后的状态只与下一行有关,又因为这一行必须全是白色,所以可以一直推出最后一行的状态。最后判断最后一行能否满足全为白,满足则此状态为合法,
     
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,a[20][20],xp[16],f[20][20],ans=10000;
int main()
{
    //freopen("fliptile.in","r",stdin);
//	freopen("fliptile.out","w",stdout);
	cin>>m>>n;
	for(int i=1;i<=m;i++)
	   for(int j=1;j<=n;j++)
	   	   scanf("%d",&a[i][j]),f[i][j]=2;
     xp[0]=1;
     for(int i=1;i<=n;i++)
        xp[i]=xp[i-1]*2;
	int d[20],b[20][20],cnt=0;
	for(int i=0;i<xp[n];i++)
	{
	    cnt=0;
		for(int j=1;j<=n;j++)
		{
			d[j]=a[1][j];
			if(i&xp[j-1])
			   b[1][j]=1,cnt++;
			else
			   b[1][j]=0;
			if(i&xp[j-1])
		       d[j]+=1;
    		if(j!=1&&(i&xp[j-2]))
    		   d[j]+=1;
    		if(j!=n&&(i&xp[j]))
    		   d[j]+=1;
		}
		for(int j=2;j<=m;j++)
        {
        	for(int k=1;k<=n;k++)
        	  if(d[k]%2)
        	  {
        	     d[k]=1;
        	     b[j][k]=1;
        	     cnt++;
			 }
			 else
			 {
			     d[k]=0;b[j][k]=0;
			 }
			for(int k=1;k<=n;k++)
			{
				d[k]+=a[j][k];
				if(k!=1)d[k]+=b[j][k-1];
				if(k!=n)d[k]+=b[j][k+1];
				d[k]+=b[j-1][k];
			}
		}
		int p=0;
		for(int j=1;j<=n;j++)
		   if(d[j]%2){p=1;break;}
		if((!p)&&ans>cnt)
		{
	   	    for(int w=1;w<=m;w++)
	   	    {
	   	    	int o=0;
	   	        for(int j=1;j<=n;j++)
	   	          if(f[w][j]>b[w][j])
	   	          {
	   	          	   ans=cnt;
	   	          	   for(int k=1;k<=m;k++)
	   	          	      for(int h=1;h<=n;h++)
	   	          	         f[k][h]=b[k][h];
	   	          	    o=1;break;
				  }
	   	          else
	   	          {
	   	          	   if(f[w][j]<b[w][j]){o=1;break;}
				  }
				  if(o==1)break;
			}
		}
	}
	if(ans==10000)
	{printf("IMPOSSIBLE\n");return 0;}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		  cout<<f[i][j]<<" ";
		cout<<endl;
	}
}

激光焦点动态跟踪技术实战大揭秘:电容式与同轴视觉的巅峰对决 激光焦点动态跟踪技术是保证激光加工质量的关键因素。本文对比评测了电容式和同轴视觉两种主流技术:电容式响应速度快、成本低,适合高速稳定加工环境,但易受电磁干扰;同轴视觉精度高、抗干扰强,适合精密加工和复杂工件,但成本较高且处理速度受限。评测结果表明,企业应根据加工需求、预算和环境选择合适技术。未来该技术将向智能化、多技术融合方向发展,为工业应用提供更优解决方案。 阅读详情

相关推荐

Nornir自动化简单介绍-网络设备信息收集

作为网工,学会通过执行脚本,可以自动化的完成日常一些设备相关配置或信息收集等工作,可以说是事半功倍。 Nornir就是这样一个自动化网络运维工具。按照官网上的说明: Nornir是用python编写的自动化框架,可与python一起使用。Nornir旨在通过提供一个纯Python框架来解决这些问题。 详细参考: Github GitHub - nornir-automation/nornir: Pluggable multi-threaded framework with inventory .

Gun&rose 7804

Fliptile(状态压缩/枚举)

3279 – Fliptile (poj.org)Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ≤ N ≤ 15) of square tiles, each of whic

Crushlikearush的博客 316

2024最新指南:如何用Python批量下载Sentinel-2数据(附避坑清单)

本文提供2024年最新Python批量下载Sentinel-2遥感数据的完整指南,涵盖环境配置、API准备、核心下载流程实现及实战避坑清单。通过智能查询器、断点续传下载器等实用工具,帮助用户高效获取遥感数据,避免常见网络问题和数据完整性验证失败。

silver的专栏 618

题解:POJ 3279 Fliptile (BFS)

D - Fliptile Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d &%I64u Description Farmer John knows that an intellectually satisfied cow is a happy cow who will gi

sun897949163的博客 1553

Thinkpad可以安装Win11吗?Thinkpad升级Win11教程

win11正式版推出之后,不少用户也想要体验一把新系统,但是不知道thinkpad是否支持win11,其实基本上现在在售的都是可以升级win11的。2、如果大家使用的是老款的ThinkPad,那么可以通过软件来检测自己是否支持win11。【电脑健康状况检查下载】答:在售的ThinkPad都是可以支持win11的,但是部分旧版本不支持。2、这时候想要升级win11的话,就可以通过镜像系统的方式来跳过系统检测。3、如果使用上面的软件检测可以支持win11,那么只要进入“设置”

xhp618的博客 2985

【ARM CoreLink 系列 7 -- TZC-400控制器简介】

为了确保内存能够正确识别总线的信号控制位,新增一个TrustZone地址空间控制器(TrustZone Address Space Controller,TZASC)组件来实现对内存地址的安全扩展,将内存区域划分为安全内存区域和非安全内存区域,安全世界可以访问安全内存和非安全内存,而普通世界只能访问非安全内存,如下图所示:图 1-1内存区域的划分是在系统启动时通过配置 TZASC 组件(TZC-400/TZC-380)来实现的。TZC-400由和使能情况;安全访问权限;Base地址;

CodingCos的博客 1633

[kuangbin]专题一 简单搜索 Fliptile POJ - 3279【DFS】

【题目描述】 Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ≤...

inv0ker的博客 305

ASPICE学习笔记

ASPICE的全称是Automotive SPICE。

汽车电子软件领域知识分享 1355

BZOJ1647: [Usaco2007 Open]Fliptile 翻格子游戏 Dfs

1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 566  Solved: 228 [Submit][Status][Discuss] Description Farmer John knows that an intellectually satisfi

Oakley 1255

MFC实现键盘钩子(附完整源码)

MFC实现键盘钩子(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 389

001、NPU是什么?为什么嵌入式设备需要它?

本文通过作者调试工业相机板卡的经历,引出嵌入式设备为何需要NPU(神经网络处理器)的探讨。文章对比了CPU和NPU的设计哲学差异,指出NPU通过专用乘加器阵列和优化的数据流,能高效处理神经网络运算。作者分析了嵌入式设备使用NPU的三大优势:算力提升、功耗降低和实时性保障,并介绍了三类常见NPU形态。通过一个YOLOv5模型调试案例,揭示了NPU使用中的常见陷阱,最后给出五条实用建议,强调理解NPU原理和局限的重要性。文章生动展现了NPU在嵌入式AI应用中的关键作用。

m0_50546716的博客 125

Fliptile 开关问题 poj 3279

Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4031 Accepted: 1539 Description Farmer John knows that an intellectually satisfied cow is a happy ...

weixin_33863087的博客 222

Python爬虫实战:基于Scrapy和Playwright的深交所数据采集

本文将详细介绍如何使用Python最新技术栈(Scrapy框架结合Playwright浏览器自动化)爬取深圳证券交易所(www.szse.cn)的公开数据。文章包含完整项目搭建、反爬策略应对、数据解析存储等全流程实现,并附详细代码示例和性能优化建议。python复制下载# 上市公司基本信息# 财务数据revenue = scrapy.Field() # 营业收入net_profit = scrapy.Field() # 净利润eps = scrapy.Field() # 每股收益。

2201_76125261的博客 949

1647: [Usaco2007 Open]Fliptile 翻格子游戏

1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit:5 SecMemory Limit:64 MBSubmit:423Solved:173[Submit][Status][Discuss] Description Farmer John knows that an intellectually satisfied ...

168

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

【BZOJ】1647: [Usaco2007 Open]Fliptile 翻格子游戏(暴力)

http://www.lydsy.com/JudgeOnline/problem.php?id=1647 自己太弱。。。看题解。。 竟然是枚举第一行的放法,,,因为一定要全部变0,所以将前一行1的在这一行翻转掉就好了。。。因为是一定要翻掉前一行,所以正确性显然。。。。。。。。。。。。 T_T 表示智商不够 #include <cstdio> #include ...

126

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

bzoj 1647: [Usaco2007 Open]Fliptile 翻格子游戏(枚举)

1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 727  Solved: 287 [Submit][Status][Discuss] Description Farmer John knows that an intellectually satisfied cow

加载中... 634

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

bzoj 1647: [Usaco2007 Open]Fliptile 翻格子游戏【dfs】

这个可以用异或高斯消元,但是我不会呀我用的暴搜 2的m次方枚举第一行的翻转情况,然后后面的就定了,因为对于一个j位置,如果i-1的j位置需要翻,那么一定要翻i的j,因为这是i-1的j最后翻的机会 按字典序搜索然后取次数min即可 #include<cmath> #include<cstdio> #include<cstring> #include&l...

weixin_30470857的博客 142

Fliptile

B - Fliptile  Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M× N grid (1 ≤ M

EmilyHoward的博客 549

D - Fliptile POJ3279 搜索(反转开关经典问题,二进制表示集合)

D - Fliptile Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3279 Description Farmer John knows that an intellectually satisfied cow is a happy

qwesde 984

POJ 3279 Fliptile (暴力枚举+DFS)

p.s. 黑白棋反转问题 Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ ...

weixin_43841060的博客 317

POJ - 3279 - Fliptile (翻转问题+DFS+思维 )

POJ - 3279 - Fliptile (翻转问题+DFS+思维 ) Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate ...

weixin_43179892的博客 427

POJ--3279.Fliptile(递推)

Fliptile Time Limit:2000MS Memory Limit:65536K Total Submissions:32918 Accepted:11520 Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for c...

with_wine的博客 535

POJ3279母牛翻方格-开关问题)

开关问题。状态压缩入门 题意:有一个n*m的棋盘,0表示白色,1表示黑色。每次可以翻转当前位置,它的上下左右四个位置也会被相应翻转。问最少翻转多少次会使所有棋面显示为白色,并给出需要翻转的位置,0表示不翻转,1表示翻转。 思路:可以利用第一层的 2^n 种状态来进行枚举。依次翻转到最后一行,如果最后一行均为白色,那么这种第一层状态可以达到效果。记录下来,最后取最少翻转次数的结果输出。 Descri...

i_like1ac的博客 429

奶牛翻盖问题 二进制压缩枚举

原题: Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ≤ N...

头秃程序员的日常 438

Fliptile (DFS)

题目链接: Fliptile 大致题意: 给定一个01矩阵, 大小为N*M, 每次可以选定一个格子, 将该格子与其上下左右四个格子进行反转, (0变1, 1变0), 问至少操作多少次可以将矩阵中的所有数值变为0. 若有解则输出翻转次数最少的翻转情况(若翻转次数最少的情况有多种, 则输出翻转字典序最小的.), 否则输出 IMPOSSIBLE. 解题思路: 我们很容易发现, 如果对1个格子进行偶数次翻转, 那将是没有意义的, 所以每个格子的情况只有翻转和不翻转两种情况. 一共N*M个格子, 每一个格子都有两种情

Fau的博客 329
上一篇: 暴力DP+离散化 bzoj1592 Making the Grade
下一篇: tarjin+暴力 [POI2008]枪战Maf
QTY_
博客等级 码龄9年 13粉丝 211原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值