标签:style http color os io for ar 2014
一道找规律的题,可以看出,大的三角形可以划分成好多个三层的三角形:
【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(找规律),布布扣,bubuko.com
【UVA】11040 - Add bricks in the wall(找规律)
标签:style http color os io for ar 2014
原文地址:http://blog.csdn.net/u013451221/article/details/38584245