博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3185 The Water Bowls(高斯消元)
阅读量:6715 次
发布时间:2019-06-25

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

The Water Bowls
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3340   Accepted: 1298

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

[]   [Go Back]   []   []

  Go Back  

 

 

 

高斯消元。。

做了一题高斯消元。。。总结个好的模板。。其他的都是虐菜啊

 

 

 

/*POJ 1753*/#include
#include
#include
#include
#include
using namespace std;const int MAXN=30;const int INF=0x3fffffff;int a[MAXN][MAXN];//增广矩阵int x[MAXN];int free_x[MAXN];// 高斯消元法解方程组(Gauss-Jordan elimination).(-2表示有浮点数解,但无整数解,//-1表示无解,0表示唯一解,大于0表示无穷解,并返回自由变元的个数)//有equ个方程,var个变元。增广矩阵行数为equ,分别为0到equ-1,列数为var+1,分别为0到var.int Gauss(int equ,int var){ int i,j,k; int max_r;// 当前这列绝对值最大的行. int col;//当前处理的列 int ta,tb; int LCM; int temp; int free_index; int num=0; for(int i=0;i<=var;i++) { x[i]=0; free_x[i]=0; } //转换为阶梯阵. col=0; // 当前处理的列 for(k = 0;k < equ && col < var;k++,col++) {
// 枚举当前处理的行.// 找到该col列元素绝对值最大的那行与第k行交换.(为了在除法时减小误差) max_r=k; for(i=k+1;i
abs(a[max_r][col])) max_r=i; } if(max_r!=k) { // 与第k行交换. for(j=k;j
>=1; } for(j=k-1;j>=0;j--) { int tmp=a[j][var]; for(int l=j+1;l
0)a[i][i-1]=1; if(i<19)a[i][i+1]=1; }}int main(){ // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); while(scanf("%d",&a[0][20])!=EOF) { init(); for(int i=1;i<20;i++)scanf("%d",&a[i][20]); int ans=Gauss(20,20); printf("%d\n",ans); } return 0;}

 

 

 

转载地址:http://hbkmo.baihongyu.com/

你可能感兴趣的文章
BZOJ 4144 Dijkstra+Kruskal+倍增LCA
查看>>
阻塞与非阻塞,同步与异步
查看>>
HTML段落自动换行的样式设置
查看>>
Android实现左右滑动指引效果
查看>>
html里frame导航框架实现方法
查看>>
shell编程系列5--数学运算
查看>>
在 UWP 应用中创建、使用、调试 App Service (应用服务)
查看>>
Active MQ C#实现
查看>>
C#实现秒表程序
查看>>
cJSON 使用笔记
查看>>
CF1163E Magical Permutation
查看>>
BroadcastReceiver
查看>>
redis备份实操
查看>>
重要更新-Word 2003查找替换最后一个实例的第四种方法
查看>>
实现大屏幕全国监控各地流量和负载质量
查看>>
高性能HTTP加速器Varnish(安装配置篇)
查看>>
如何取消OneNote的粘贴来源地址
查看>>
编程乐趣:C#实现读取12306余票信息
查看>>
视频编码的常见参数基本概念
查看>>
用python写一个专业的传参脚本
查看>>