POJ3185 The Water Bowls 反转(开关)
Description
use their wide snouts to flip bowls.
Their snouts, though, are so wide that they flip not only one bowl but also the bowls on either side of that bowl (a total of three or -- in the case of either end bowl -- two bowls).
Given the initial state of the bowls (1=undrinkable, 0=drinkable -- it even looks like a bowl), what is the minimum number of bowl flips necessary to turn all the bowls right-side-up?
Input
Output
Sample Input
0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0
Sample Output
3
Hint
Flip bowls 4, 9, and 11 to make them all drinkable:
0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 [initial state]
0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 [after flipping bowl 4]
0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 [after flipping bowl 9]
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [after flipping bowl 11]
#include <stdio.h>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <iostream>
#include <queue>
#include <list>
#include <algorithm>
#include <stack>
#include <map> using namespace std; int main()
{
#ifdef _DEBUG
freopen("e:\\in.txt", "r", stdin);
#endif
int side[21];
int side1[21];
for (int i = 0; i < 20; i ++)
{
scanf("%d", &side[i]);
}
int minCount = 50;
for (int i = 0; i < 4;i++)
{
int count1 = 0;
memcpy(side1, side, sizeof(side));
if (i == 1)
{
side1[0]++;
side1[1]++;
count1++;
}
else if (i == 2)
{
side1[18]++;
side1[19]++;
count1++;
}
else if (i == 3)
{
side1[0]++;
side1[1]++;
side1[18]++;
side1[19]++;
count1++;
count1++;
}
for (int i = 0; i <= 17; i++)
{
if (side1[i] & 1)
{
side1[i] ++;
side1[i + 1]++;
side1[i + 2]++;
count1++;
}
}
if (!(side1[1] & 1 || side1[18] & 1 || side1[19] & 1))
{
if (minCount > count1)
{
minCount = count1;
}
}
}
printf("%d\n", minCount);
return 1;
}
POJ3185 The Water Bowls 反转(开关)的更多相关文章
- POJ3185 The Water Bowls(反转法or dfs 爆搜)
POJ3185 The Water Bowls 题目大意: 奶牛有20只碗摆成一排,用鼻子顶某只碗的话,包括左右两只在内的一共三只碗会反向,现在给出碗的初始状态,问至少要用鼻子顶多少次才能使所有碗都朝 ...
- [Gauss]POJ3185 The Water Bowls
题意:反正就是要给的一串01的变成全0 能影响自己和左右 最少需要几步 01方程组 异或解 ][]; // 增广矩阵 ]; // 解 ]; // 标记是否为自由未知量 int n; void debu ...
- poj 3185 The Water Bowls(反转)
Description The cows have a line of water bowls water bowls to be right-side-up and thus use their w ...
- POJ 3185 The Water Bowls 【一维开关问题 高斯消元】
任意门:http://poj.org/problem?id=3185 The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ:3185-The Water Bowls(枚举反转)
The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7402 Accepted: 2927 Descr ...
- poj 3185 The Water Bowls
The Water Bowls 题意:给定20个01串(最终的状态),每个点变化时会影响左右点,问最终是20个0所需最少操作数? 水题..直接修改增广矩阵即可:看来最优解不是用高斯消元(若是有Gaus ...
- The Water Bowls [POJ3185] [开关问题]
题意 一串长度为20的0,1数列,每次翻转i,会影响i-1,i+1,也被翻转,最少翻转成0的步骤数是多少? Sample Input 0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 ...
- Greedy:The Water Bowls(POJ 3185)
水池 题目大意:给定一个20的数组,全都是0和1,可以翻一个数改变成另一个数(0或者1),但是其左右两边的数都会跟着变为原来的相反数,问你怎么用最小的操作数使全部数变成0 这一题的:满足 1:翻转次序 ...
- 挑战程序竞赛 反转开关 poj3276
这个我其实也没有看太懂它的证明过程. 1.若某一个位置被翻转了n次,则其实际上被翻转了n%2次. 2.分析易知翻转的顺序并不影响最终结果. 3.现在我们着眼于第1个位置,可知若要将第1个位置进行翻转只 ...
随机推荐
- ROS-URDF-活动关节
前言:介绍活动关节,并使机器人活动起来. 参考自:http://wiki.ros.org/urdf/Tutorials/Building%20a%20Movable%20Robot%20Model%2 ...
- css样式变 及实际用法
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Con ...
- Unity引擎的Player Settings介绍
我用的是unity5.4.3版本的 一.窗口打开: 从菜单栏查看播放器设置,选择 Edit->Project Settings->Player 二.全局设置 第一部分: Company N ...
- (转)i686只是cpu的指令等级,包括32bit和64bit
i代表intel系列的cpu 386 几乎适用于所有的 x86 平台,不论是旧的 pentum 或者是新的 pentum-IV 与 K7 系列的 CPU等等,都可以正常的工作! 那个 i 指的是 In ...
- express创建第一个web应用
Express 在初始化一个项目的时候需要指定模板引擎,默认支持Jade和ejs. 这里我们使用ejs模板引擎:(关于ejs的介绍可以先从百科里面了解一个大概)EJS是一个JavaScript模板库, ...
- java mongodb 使用MongoCollection,BasicDBObject 条件查询
废话不说,上代码 //链接数据库 MongoClient mongoClient = new MongoClient( "172.26.xxx.xxx" , 27017 ); Mo ...
- 【剑指Offer】58、对称的二叉树
题目描述: 请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 解题思路: 本题判断一棵树是不是对称的,和第18题可以对比分 ...
- window.open方法被浏览器拦截的处理方式
问题现象 当我们在一个 ajax 回调中执行 window.open 方法时,新页面会被浏览器拦截. 原因 在 Chrome 的安全机制里,非用户直接触发的 window.open 方法,是会被拦截的 ...
- nyoj29-求置转换问题
求转置矩阵问题 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 求一个三行三列的转置矩阵. 输入 第一行一个整数n<20,表示有n组测试数据,下面是n组数据;每组测 ...
- Luogu P1198 BZOJ 1012 最大数 (线段树)
手动博客搬家: 本文发表于20170821 14:32:05, 原地址https://blog.csdn.net/suncongbo/article/details/77449455 URL: (Lu ...