【UVA】11040 - Add bricks in the wall(找规律)

一道找规律的题,可以看出,大的三角形可以划分成好多个三层的三角形:

【x】

【a】【x-a】

【y】 【    】【z】

这里面xyz都已知,所以可以求出a = (x + y - z ) /2

14043615 11040 Add bricks in the wall Accepted C++ 0.019 2014-08-15 06:02:50

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<string>
#include<sstream>
#include<ctime>
using namespace std;
#define _PI acos(-1.0)
#define INF (1 << 10)
#define esp 1e-9
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pill;
/*===========================================
===========================================*/
#define MAXD 20 + 10
int Grap[MAXD][MAXD];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        for(int i = 1 ; i <= 9 ; i+=2){
            for(int j = 1 ; j <= i ; j += 2)
                scanf("%d",&Grap[i][j]);
        }
        for(int i = 1 ; i <= 9 ; i++){
            for(int j = 1 ; j <= i ; j++){
                if(i & 1){ /*如果是奇数行*/
                     if(j % 2 == 0){
                         Grap[i][j] = Grap[i - 1][j - 1] - Grap[i][j - 1];
                     }
                }
                else{/*如果是偶数行*/
                   if(j & 1){
                      Grap[i][j] = (Grap[i - 1][j] + Grap[i + 1][j] - Grap[i + 1][j + 2] )/ 2;
                   }
                   else{
                      Grap[i][j] = Grap[i - 1][j - 1] - Grap[i][j - 1];
                   }
                }
            }
        }
        for(int i = 1 ; i <= 9 ; i++){
            for(int j = 1 ; j <= i ; j++){
                printf("%d",Grap[i][j]);
                if(j < i)
                    printf(" ");
            }
            printf("\n");
        }
    }
    return 0;
}

【UVA】11040 - Add bricks in the wall(找规律)

时间: 2024-10-13 15:31:49

【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 a[10][10]; int main() { int T,d; scanf("%d",&T); while(T--) { for(int i=1;i<=5;i++) for(int j=1;j<=i;j++) scanf("%d",&a[i*2-1][j*2-1

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&

UVA-11040-Add Bricks in the wall(规律、递推)

由于这个排列的行数和列数已经固定了,所以比较好找规律,由最下面一行和倒数第三行可以得出最下面一行完整的数排列,所以整个排列就可以递推出来了,my ugly code(我没用上题目中的后几行数据): #include<stdio.h> #include<iostream> #include<math.h> using namespace std; int main() { int n;cin>>n; while(n--) { int temp,temp1,te

UVa11040 - Add bricks in the wall (规律递推)

找规律的题 [x] [a][x-a] [y] [    ][z] 这里面xyz都已知,所以可以求出a = (x + y - z ) /2 #include<cstdio> int a[9][9]; int main() { int t; scanf("%d",&t); while(t--){ for(int i=0;i<9;i+=2) for(int j=0;j<=i;j+=2) scanf("%d",&a[i][j]); f

UVa 11040 (水题) Add bricks in the wall

题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到A92 = (A71 - A91 - A93) / 2. 以此类推,就能得到最下面一整行的数.有了这个“地基”以后,所有的数就都能算出来了. 1 #include <cstdio> 2 3 int a[10][10]; 4 5 int main() 6 { 7 //freopen("in

UVA - 808 Bee Breeding (建立坐标系&amp;找规律)

题目: 输入两个格子的编号a和b(a,b≤10000),求最短距离.例如,19和30的距离为5(一条最短路是19-7-6-5-15-30). 思路: 如图建立坐标系,然后看两个点的向量如果位于二四象限答案为向量坐标绝对值的和,向量位于一三象限答案为向量坐标绝对值的最大值. 看网上的博客的思路--(菜是原罪) 难点是建立坐标系. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1000000000 #define F

uva 10954 Add All(排序)

uva 10954 Add All Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, let's add

UVA - 1646 - Edge Case(找规律)

题意:n(3 <= n <= 10000)个结点组成一个圈,求匹配(即没有公共点的边集)的个数. 找规律为斐波那契的性质,因为数太大所以用的java大数. import java.math.BigInteger; import java.util.Scanner; public class Main{ public static int MAXN = 10000 + 10; public static BigInteger []c = new BigInteger[MAXN]; public

UVA - 11076 Add Again (重复元素的排列)

Summation of sequence of integersis always a common problem in Computer Science. Rather than computing blindly,some intelligent techniques make the task simpler. Here you have to find thesummation of a sequence of integers. The sequence is an interes