HDU2091(预处理+格式控制)
来源:互联网 发布:群发短信软件电脑版 编辑:程序博客网 时间:2024/05/22 01:43
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2091
解题思路:
预处理存储空格,然后手动算出g[ 0 ][ (n * 2 - 1 ) / 2 ] = ch,接下来根据规律对每行从左往右扫一遍,从右往左扫一遍。
最坑的莫过于输出格式,每行不能有空格,这点对于预处理做的有点麻烦。每行要先从后往前扫,找到最后一个ch的位置,这样才能保证每行输出后面没有多余空格。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;const int maxn = 1111;char g[1111][1111];void init(){ for(int i = 0 ; i < 1111 ; i ++) { for(int j = 0 ; j < 1111 ; j ++) g[i][j] = ' '; }}void solve(char ch , int n){ init(); int k = (2*n-1)/2; g[0][k] = ch; for(int i = 1 ; i < n ; i ++ ) { if(i == n - 1) { for(int j = 0 ; j < 2 * n - 1 ; j ++) { g[i][j] = ch; } } else { for(int j = 0 ; j <= k ; j ++) { if(g[i-1][j] == ch) { g[i][j-1] = ch; break; } } for(int j = 2 * n - 2 ; j >= k ; j --) { if(g[i-1][j] == ch) { g[i][j+1] = ch; break; } } } } for(int i = 0 ; i < n ; i ++) { int key; for(int j = 2 * n - 2 ; j >= 0 ; j --) if(g[i][j] == ch) { key = j; break; } for(int j = 0 ; j <= key ; j ++) { cout << g[i][j]; } cout << endl; }}int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int n; char ch; int flag = 0; while(cin >> ch) { if(ch == '@') break; cin >> n; if(flag) { cout << "\n"; } flag = 1; solve(ch , n); }}
0 0
- HDU2091(预处理+格式控制)
- hdu2091
- HDU2091
- HDU2091:空心三角形
- hdu2091 空心三角形
- hdu2091空心三角形
- HDU2091空心三角形
- HDU2091(基础题)
- 格式控制
- HDU2091——空心三角形
- HDU2091 打印 等腰空心字符串
- python 预处理XML格式文档经验总结
- 控制符控制输出格式
- 格式精度控制
- C++流格式控制
- delphi控制Excel格式
- Printf()输出格式控制
- printf格式控制符
- 1 apache虚拟主机设置
- ASP.net Reuqest请求常用操作
- String,StringBuilder性能对比
- Nodejs http、url模块
- 正则与NSPredicate 应用
- HDU2091(预处理+格式控制)
- 用MyEclipse2014自动加载ssh无法连接数据库问题
- ubuntu 13.04 安装 JDK
- AttributeSet 帮助类,读取Android的属性---1
- 二叉树(11)----求二叉树的镜像,递归和非递归方式
- AttributeSet 帮助类,读取Android的属性---2
- oc nil, Nil, NULL和NSNull的区别
- 微软完整的SQLHelper
- 【灌水】天草逆向, esp定律脱壳