设为首页 加入收藏

TOP

poj 3185 The Water Bowls(高斯消元)
2015-07-20 17:49:52 来源: 作者: 【 】 浏览:3
Tags:poj 3185 The Water Bowls 高斯

The Water Bowls
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4352 Accepted: 1721

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

USACO 2006 January Bronze


高斯消元的简单题:


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; int a[24][24],x[24]; int equ,var;//方程数和变元数 void Debug() { for(int i=0;i
      
       a[max_r][col]) max_r=j; } if(max_r!=i) { for(int k=0;k<=var;k++) { swap(a[i][k],a[max_r][k]); } } if(a[i][col]==0) { i--; continue; } for(int j=i+1;j
       
        0?1:0; sum=0; for(int i=equ-2;i>=0;i--) { int temp=a[i][var]; for(int j=i+1;j
        
         





】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇题目1004:Median 下一篇uva 1428 - Ping pong(树状数组)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)
·索引堆及其优化 - 菜 (2025-12-24 20:18:50)
·Shell 中各种括号的 (2025-12-24 19:50:39)
·Shell 变量 - 菜鸟教 (2025-12-24 19:50:37)