UVa 11040 Add bricks in the wall (水题递推)
题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔。
析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - a[i][j-1] - a[i][j+1]) / 2;然后偶数行就推出来了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define print(a) printf("%d\n", (a))
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int a[15][15]; int main(){
cin >> n;
while(n--){
memset(a, 0, sizeof(a));
for(int i = 1; i < 10; i += 2)
for(int j = 1; j <= i; j += 2)
cin >> a[i][j];
for(int i = 1; i < 10; i++)
for(int j = 2; j <= i; j++)
if(!a[i][j]) a[i][j] = (a[i-2][j-1] - a[i][j-1] - a[i][j+1]) / 2;
for(int i = 2; i < 9; i += 2)
for(int j = 1; j <= i; j++)
a[i][j] = a[i+1][j] + a[i+1][j+1];
for(int i = 1; i < 10; i++)
for(int j = 1; j <= i; j++)
if(j == i) printf("%d\n", a[i][j]);
else printf("%d ", a[i][j]);
}
return 0;
}
UVa 11040 Add bricks in the wall (水题递推)的更多相关文章
- UVA 11040 Add bricks in the wall
https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() ...
- UVA 11040 Add bricks in the wall(线性组合)
砖块上的数字最终都可以看作是最后一行的线性组合,独立变元最多9个. 这类题的一般做法,线性组合都可以列出方程然后高斯消元. 对于这道题,只要确定最后一行剩下的4个变量就好了,对于最后一行的j位置,它对 ...
- Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现
今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...
- uva 748 Exponentiation 浮点数乘方运算 高精度水题
输入的前六位数表示一个小数,然后输入一个数表示几次方.要求用高精度算出结果. 高精度水题,主要注意处理小数点,先在输入时把小数点提取出来并记录位置,用普通乘法计算出结果后由后向前计算位置添加小数点. ...
- UVA 1541 - To Bet or Not To Bet(概率递推)
UVA 1541 - To Bet or Not To Bet 题目链接 题意:这题题意真是神了- -.看半天,大概是玩一个游戏,開始在位置0.终点在位置m + 1,每次扔一个硬币,正面走一步,反面走 ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- UVA 699 The Falling Leaves (二叉树水题)
本文纯属原创.转载请注明出处,谢谢. http://blog.csdn.net/zip_fan. Description Each year, fall in the North Central re ...
- UVa 699 The Falling Leaves (树水题)
Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on ...
- UVA 1642 Magical GCD(gcd的性质,递推)
分析:对于区间[i,j],枚举j. 固定j以后,剩下的要比较M_gcd(k,j) = gcd(ak,...,aj)*(j-k+1)的大小, i≤k≤j. 此时M_gcd(k,j)可以看成一个二元组(g ...
随机推荐
- PS 如何使用液化工具给人物减肥
进入"液化", 有个收缩按钮, 可以选择范围大小, 想瘦哪里, 瘦多少都OK 最终效果图 1.打开原图,进入通道面板,选择菜单图像计算,计算红色通道,保留人物见图. ...
- IO模型:同步、异步、阻塞、非阻塞
前言: 在Linux的网络编程中,同步IO(synchronous IO).异步IO(asynchronous IO).阻塞IO(blocking IO).非阻塞IO(non-blocking IO) ...
- ZOJ 3230 Solving the Problems(数学 优先队列啊)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230 Programming is fun, Aaron is ...
- Desktop Management Interface & System Management BIOS
http://en.wikipedia.org/wiki/Desktop_Management_Interface Desktop Management Interface From Wikipedi ...
- Yii之路(第八)
[URL地址美化]给域名地址做一个别名伪静态.通过设置服务器服务.做域名地址的转换工作. urlManager地址美化,通过程序的方式实现地址的美化工作 http://xxxxx.com/index. ...
- navicat-premium11.1.6 x64关键
Navicat Premium version patch 11.2.16.0 >navicat.exe0000000001CECCBC:80->C60000000001CECCBD: ...
- Cannot instantiate the type AppiumDriver,AppiumDriver升级引发的问题
转自:http://blog.csdn.net/zhubaitian/article/details/39717889 1. 问题描述和起因 在使用Appium1.7.0及其以下版本的时候,我们可以直 ...
- ES6常用语法简介import export
ES6常用语法简介import export let与var用法区别 //var var a = []; for (var i = 0; i < 10; i++) { a[i] = functi ...
- 白帽子讲web安全读后感
又是厚厚的一本书,为了不弄虚做假,只得变更计划,这一次调整为读前三章,安全世界观,浏览器安全和xss.其它待用到时再专门深入学习. 吴翰清是本书作者,icon是一个刺字,圈内人称道哥.曾供职于阿里,后 ...
- springCloud和docker笔记(1)——微服务架构概述
1.微服务设计原则 1)单一职责原则:只关注整个系统中单独.有界限的一部分(SOLID原则之一) 2)服务自治原则:具备独立的业务能力和运行环境,可独立开发.测试.构建.部署 3)轻量级通信机制:体量 ...