博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3185 The Water Bowls
阅读量:6337 次
发布时间:2019-06-22

本文共 2708 字,大约阅读时间需要 9 分钟。

The Water Bowls
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6731   Accepted: 2650

Description

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]

Source

/** @Author: Lyucheng* @Date:   2017-08-04 15:12:25* @Last Modified by:   Lyucheng* @Last Modified time: 2017-08-04 17:00:37*//* 题意:给你一个20的01序列,每次你可以反转相邻的三个点,问你至少反转多少次才能使得所有的点变成0 思路:开关反转问题,一个序列如果有解的话,那么需要反转的区间是一定的,有个区间反转两次是没有    意义的,如果一个点为1那么所在区间是一定要进行反转的,并且只翻转一次,所有可以两头开始模拟    反转,比较一下大小*/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAXN 25using namespace std;int pos1[MAXN];int pos2[MAXN];int res1;int res2;inline void init(){ res1=0; res2=0;}int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(scanf("%d",&pos1[1])!=EOF){ pos2[1]=pos1[1]; for(int i=2;i<=20;i++){ scanf("%d",&pos1[i]); pos2[i]=pos1[i]; } init(); for(int i=1;i<=20;i++){ if(pos1[i]==1){ if(i==20) res1=21;//无解 res1++; pos1[i]=!pos1[i]; pos1[i+1]=!pos1[i+1]; pos1[i+2]=!pos1[i+2]; } } for(int i=20;i>=1;i--){ if(pos2[i]==1){ if(i==1) res2=21;//无解 res2++; pos2[i]=!pos2[i]; pos2[i-1]=!pos2[i-1]; pos2[i-2]=!pos2[i-2]; } } printf("%d\n",min(res1,res2)); } return 0;}

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/7286139.html

你可能感兴趣的文章
webstorm常用功能FTP,及常用快捷键
查看>>
eclipse html 打开方式
查看>>
[求助] win7 x64 封装 出现 Administrator.xxxxx 的问题
查看>>
人类投资经理再也无法击败电脑的时代终将到来了...
查看>>
一个最小手势库的实现
查看>>
HoloLens开发手记 - Vuforia开发概述 Vuforia development overview
查看>>
Android支付之支付宝封装类
查看>>
<亲测>CentOS中yum安装ffmpeg
查看>>
【分享】马化腾:产品设计与用户体验
查看>>
【机器学习PAI实践十】深度学习Caffe框架实现图像分类的模型训练
查看>>
全智慧的网络:思科十年来最具颠覆性的创新
查看>>
怎样将现有应用迁移到 VMware NSX
查看>>
赛门铁克收购以色列移动安全初创公司Skycure 旨在构建网络安全防御平台
查看>>
《Photoshop蒙版与合成(第2版)》目录—导读
查看>>
“最佳人气奖”出炉!4月27号,谁能拿到阿里聚安全算法挑战赛的桂冠?
查看>>
《网页美工设计Photoshop+Flash+Dreamweaver从入门到精通》——2.6 图层与图层样式...
查看>>
《iOS组件与框架——iOS SDK高级特性剖析》——第2章,第2.7节获取线路
查看>>
Spring中 @Autowired标签与 @Resource标签 的区别
查看>>
人工智能凭什么毁灭人类
查看>>
[LeetCode]--349. Intersection of Two Arrays
查看>>