比赛——The Water Bowls
来源:互联网 发布:淘宝网短棉衣 编辑:程序博客网 时间:2024/05/21 09:12
我说命运有时候真的很搞笑,上一个博客写的题目的方法思路这道题目就直接用上了。无语。。。
题目:
The Water Bowls
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 28 Accepted Submission(s) : 9
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?
0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0
3
解题思路:
这道题目的意思是翻碗,一次行翻要翻得的那个和它两旁的那两个,也就是说三个。求最小需要翻的次数;
一共有20个碗,所以最多需要翻20次。从翻一次,一直找到翻20次,题目说了一定可以翻完,所以不考虑翻20次还不成功的情况。
还有就是要考虑初始情况全是0的这种情况,这种情况下输出是0,我就因为这个WA了一次,郁闷;
#include<stdio.h>
int bowl[20];
int pan()
{
int i;
for(i=0;i<20;i++)
if(bowl[i]==1)
return 0;
return 1;
}
void change(int i)
{
if(i>=0&&i<20)
bowl[i]=(bowl[i]+1)%2;
}
void fan(int i)
{
change(i-1);change(i);change(i+1);
}
int ves(int m, int n)
{
int i;
if(pan())return 1;
if(n==0)return 0;
for(i=m;i<20;i++)
{
fan(i);
if(ves(i+1,n-1))
return 1;
fan(i);
}
return 0;
}
int main()
{
int i,con[20],j;
for(i=0;i<20;i++)
{
scanf("%d",&con[i]);
bowl[i]=con[i];
}
if(pan())
{
printf("0\n");
return 0;
}
for(i=1;i<=20;i++)
{
for(j=0;j<20;j++)
bowl[j]=con[j];
if(ves(0,i)==1)
break;
}
printf("%d\n",i);
return 0;
}
- 比赛——The Water Bowls
- POJ3185——The Water Bowls
- POJ3185-The Water Bowls
- POJ3185:The Water Bowls
- POJ3185-The Water Bowls
- PKU 3185 The Water Bowls
- poj 3185 The Water Bowls
- POJ 3185 (The Water Bowls)
- PKU 3185 The Water Bowls
- POJ 3185 The Water Bowls
- poj 3185 The Water Bowls
- POJ 3185 The Water Bowls
- poj3185 The Water Bowls 高斯消元
- POJ 3185 The Water Bowls
- POJ-3185-The Water Bowls
- POJ3185 The Water Bowls【高斯消元法】
- poj-3185 The Water Bowls
- The Water Bowls POJ 3185
- 图书馆数据库系统的模拟练习
- POJ-2251
- 整合SSH过程中遇到错误之运行项目action取不到自动装配的bean
- POJ-2259
- 变量在内存中的存放位置
- 比赛——The Water Bowls
- HDU-1224 最短路 SPFA
- POJ-2262
- 关于“大局观”的一些思考
- POJ-3006
- 一些负载均衡器的介绍材料
- POJ-3094
- POJ-3195
- POJ-22551