POJ 3185 The Water Bowls(开关问题)
来源:互联网 发布:7u分享网络怎么提现 编辑:程序博客网 时间:2024/06/05 13:52
Description
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]
有20个碗排成一排,有些碗口朝上,有些碗口朝下。每次可以反转其中的一个碗,但是在反转该碗时,该碗左右两边的碗也跟着被反转(如果该碗为边界上的碗,则只有一侧的碗被反转)。求最少需要反转几次,可以使得所有碗口均朝上
这题很坑,,测试数据,,
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
可以从俩边遍历取最小值,不然考虑的情况太多容易卡特殊数据,,,
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
int dir1[30],dir2[30], f[30];
int main()
{
while(scanf("%d",&dir1[0])!=EOF)
{
memset(f,0,sizeof(f));
for(int i=1; i<20; i++)
{
scanf("%d", &dir1[i]);
}
memcpy(dir2,dir1,sizeof(dir1));
int cnt1=0, cnt2=0, res;
for(int i=0;i<=19;i++)
{
if(dir1[i]==1)
{
if(i==19)
{
cnt1=inf;
break;
}
cnt1++;
dir1[i+1]=!dir1[i+1];
dir1[i+2]=!dir1[i+2];
}
}
for(int i=19;i>=0;i--)
{
if(dir2[i]==1)
{
if(i==0)
{
cnt2=inf;
break;
}
cnt2++;
dir2[i-1]=!dir2[i-1];
dir2[i-2]=!dir2[i-2];
}
}
res=min(cnt1,cnt2);
printf("%d\n",res);
}
return 0;
}
- poj 3185 The Water Bowls(高斯消元 开关问题)
- POJ 3185 The Water Bowls(开关问题)
- poj 3185 The Water Bowls 反转(开关)
- poj 3185 The Water Bowls 反转问题
- poj3185 The Water Bowls 开关问题
- poj3185 The Water Bowls 开关问题
- poj -- 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- POJ 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls
- POJ 3185 (The Water Bowls)
- POJ 3185 The Water Bowls
- poj 3185 The Water Bowls
- POJ 3185 The Water Bowls
- POJ 3185 The Water Bowls
- POJ-3185-The Water Bowls
- poj-3185 The Water Bowls
- undefined并不是null,数组可以使用名字当索引
- ORACLE --- 常用知识
- CentOS 6.4_64下安装LANMP_WDCP2.5以及升级PHP、MYSQL版本流程
- 使用Navicat for Mysql连接装在虚拟机Ubuntu16.04上的mysql服务器
- 百度地图开发总结
- POJ 3185 The Water Bowls(开关问题)
- 【NOIP模拟】鼎纹
- 复数的指数表示
- 从无到有系列之HBase-入门操作02
- Hbase Mapreduce操作
- MongoDB C++ 数组的写操作
- arcgis engine GP重分类格式 remap
- iOS开发:如何跳到系统设置里的各种设置界面
- 第02章:简单Java程序