题意:

给20个水碗。朝上为‘0’或朝下为‘1’,每次操作使三个碗翻转,问使所有20个水碗都朝上,至少翻多少次?

题目:

The cows have a line of 20 water bowls from which they drink. The bowls can be either right-side-up (properly oriented to serve refreshing cool water) or upside-down (a position which holds no water). They want all 20 water bowls to be right-side-up and thus 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

Line 1: A single line with 20 space-separated integers

Output

Line 1: The minimum number of bowl flips necessary to flip all the bowls right-side-up (i.e., to 0). For the inputs given, it will always be possible to find some combination of flips that will manipulate the bowls to 20 0’s.

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

Explanation of the sample:

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]

分析:

这个题直接暴力过得,直接正反遍历,找最小值,还有一种构造增广矩阵类似于根据开关的关系构造有向图的邻接矩阵;构造增广矩阵,高斯消元,枚举自由元(二进制枚举状态),寻找最小值的方法,因为时间关系就没有去钻研,在这提供下思路。

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[30],b[30];
int ans,num;
int main(){for(int i=1;i<=20;i++){scanf("%d",&a[i]);b[i]=a[i];}num=ans=0;for(int i=1;i<=20;i++){if(a[i]==1){ans++;a[i+1]=!a[i+1];a[i+2]=!a[i+2];}}for(int i=20;i>=1;i--){if(b[i]==1){num++;b[i-1]=!b[i-1];b[i-2]=!b[i-2];}}ans=min(ans,num);printf("%d\n",ans);return 0;
}

The Water Bowls POJ - 3185(开关问题+暴力)相关推荐

  1. POJ 3185 开关问题

    题意 传送门 POJ 3185 题解 开关问题的原理是枚举小部分开关的翻转的状态,使余下开关都可以直接判断是否翻转.这里每一个开关会造成左右两个开关同时翻转,枚举最左侧一个开关是否翻转,此时能影响到它 ...

  2. POJ3185 The Water Bowls(反转法or dfs 爆搜)

    POJ3185 The Water Bowls 题目大意: 奶牛有20只碗摆成一排,用鼻子顶某只碗的话,包括左右两只在内的一共三只碗会反向,现在给出碗的初始状态,问至少要用鼻子顶多少次才能使所有碗都朝 ...

  3. POJ 1830 开关问题 【01矩阵 高斯消元】

    任意门:http://poj.org/problem?id=1830 开关问题 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...

  4. POJ - 3080 Blue Jeans(暴力+KMP)

    题目链接:点击查看 题目大意:给出n组长度为60的字符串,问这n组中最长的公共连续子串是什么,若有多个不同的最长公共子串,输出字典序最小的那个 题目分析:一开始看到这个题目的时候我是没有想到暴力的.. ...

  5. POJ 1830.开关问题(高斯消元)

    题目链接 Solutin: 将每个开关使用的情况当成未知数,如果开关i能影响到开关j,那么系数矩阵A[j][i]的系数为1. 每个开关增广矩阵的值是开关k的初状态异或开关k的目标状态,这个应该很容易想 ...

  6. Bailian2972 确定进制(POJ NOI0113-34,POJ NOI0201-1973)【暴力+进制】

    问题链接:POJ NOI0113-34 确定进制. 问题链接:POJ NOI0201-1973 确定进制. 确定进制 描述 6*9 = 42 对于十进制来说是错误的,但是对于13进制来说是正确的.即, ...

  7. POJ 1830 开关问题 高斯消元

    题意:给你N个开关,其中某些开关之间是相互影响的,即一个开关控制多个,那么每个开关操作与否为一个变元,有N个变元,开关之间相互影响的系数设为1,否则为0,对模2高斯消元求解自由变元个数. #inclu ...

  8. poj 1830 开关问题

    开关问题 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9328   Accepted: 3754 Description ...

  9. poj 3080-Blue Jeans(暴力KMP)

    传送门: poj 3080 题意: 给出一系列长度为60的字符串,让求出它们的最大的公共子序列 题解: 1.既然是公共子序列,那么在其中一个数据里面可能会有一个子串是满足条件的,那么我们可以将其中的一 ...

最新文章

  1. 浅谈数据库乐观锁、悲观锁
  2. 基于视觉的在线地图:一种Transformer网络方法
  3. DVWA安装——一个菜鸟的入门教程
  4. socket 编程的端口和地址复用
  5. 机器学里面的一些概念-召回率,精确度等的介绍
  6. 2020-09-27 What is Sector-Bounded Nonlinearities?
  7. ios 后台唤醒应用_IOS开发之----详解在IOS后台执行
  8. SAP Commerce Cloud 架构概述
  9. Kylin 2.0升级总结
  10. JDK1.8 String常量池详解
  11. 华为跨域bgp_通知:2019华为认证体系全新升级!
  12. mysql 连接查询分组_详解MySQL中的分组查询与连接查询语句
  13. 挥别百度,那些顶级技术人才都去哪儿了?
  14. UI音乐播放之入门篇AudioSerVicesPlay
  15. Excel表格如何筛选重复内容(筛选重复数据的方法)
  16. HTML5期末考核大作业,网站——旅游景点。 学生旅行 游玩 主题住宿网页
  17. (附源码)spring boot图书管理系统 毕业设计160934
  18. hostapd_cli 使用命令
  19. 2017.05.22 房多多 曾熙闭门会
  20. 在小公司做项目经理有意义吗_产品经理–是否具有战略意义?

热门文章

  1. C语言试题六十八之请编写函数实现亲密数
  2. Android之java.lang.ClassCastException: *****cannot be cast to*******
  3. C和指针之部分理解和编码总结
  4. C语言之sprintf使用总结
  5. Android之如何解决刚下载的Android studio(包括上面的菜单栏)乱码问题
  6. Android之RecyclerView 实现真正的Gallery效果
  7. 用高等数学“铲雪”!这个200多年前的证明太厉害了,有城市用它省了2000多万..........
  8. 身家4400亿美元的他,吃低于3美元的早餐,和2个老婆同居28年!
  9. 宝宝学数学的第一套书,秒杀题海战术!上小学前应该这样学数学!
  10. 马斯克脑机接口_马斯克的脑机接口,让我倍感担忧