UVa11040 - Add bricks in the wall
2014-07-25 17:57
330 查看
题意:45块石头堆砌起来从上到下1,2,3,...,9块。每块上的数是下面两块的和。目前只有奇数行的奇数个位置上有数,求所有的数。
思路:存数组wall[i][j],i,j分别代表行列。先算出奇数行剩余的数,wall[i][j]=(wall[i-2][j-1]-wall[i][j-1]-wall[i][j+1])/2。然后算偶数行,两块加起来就行了。
思路:存数组wall[i][j],i,j分别代表行列。先算出奇数行剩余的数,wall[i][j]=(wall[i-2][j-1]-wall[i][j-1]-wall[i][j+1])/2。然后算偶数行,两块加起来就行了。
#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <iomanip> #include <cstdlib> #include <string> #include <memory.h> #include <vector> #include <queue> #include <stack> #include <ctype.h> #define INF 1000000 using namespace std; int wall[10][10]; int main(){ int N; cin>>N; while(N--){ for(int i=1;i<10;i+=2){ for(int j=1;j<=i;j+=2){ cin>>wall[i][j]; } } for(int i=3;i<10;i+=2){ for(int j=2;j<=i;j+=2){ wall[i][j]=(wall[i-2][j-1]-wall[i][j-1]-wall[i][j+1])/2; } } for(int i=2;i<9;i+=2){ for(int j=1;j<=i;j++){ wall[i][j]=wall[i+1][j]+wall[i+1][j+1]; } } for(int i=1;i<10;i++){ for(int j=1;j<=i;j++){ cout<<wall[i][j]; if(j!=i)cout<<" "; } cout<<endl; } } return 0; }
相关文章推荐
- UVa 11040 (水题) Add bricks in the wall
- UVa 11040 - Add bricks in the wall
- UVa 11040 - Add bricks in the wall(规律)
- UVa 11040 - Add bricks in the wall
- UVa 11040 - Add bricks in the wall
- uva 11040 - Add bricks in the wall
- Add bricks in the wall UVA - 11040——递推
- UVA11040 - Add bricks in the wall
- UVa11040 - Add bricks in the wall (规律递推)
- UVA 11040 Add bricks in the wall
- UVa 11040 Add bricks in the wall (水题递推)
- UVA 11040(p342)----Add Bricks in the Wall
- UVA 11040 Add bricks in the wall(线性组合)
- 【UVA】11040 - Add bricks in the wall(找规律)
- UVa 11040 - Add bricks in the wall
- UVA-11040-Add Bricks in the wall(规律、递推)
- UVA 11040 - Add bricks in the wall
- UVA1426-Add Bricks in The Wall
- 11040 - Add bricks in the wall
- 习题10-1 11040 Add bricks in the wall 砌砖