HDU 6330--Visual Cube(构造,计算)
Posted flyerbird
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 6330--Visual Cube(构造,计算)相关的知识,希望对你有一定的参考价值。
- 将这个立方体分块,分成上中下三个部分,利用长宽高计算行列,最后输出即可。
每个部分都分成奇偶行来输出,总共有(2*(b+c)+1)行,共(2*(a+b)+1)列。设当前行为(i),划分方式:当行数小于等于(2*b)时,在上部,当$i > (2 * b) $ && (i<=2*c+1)时,在中部,其余在下部。这样的划分可以应对绝大部分情况,但是对于上部有一中情况是不包括的,当$b>c $时,如果继续之前的划分,那么在头部判定之后,它依然符合下部的判定,所以这时也被当作下部输出,这不是预期的结果,所以在上部加上额外的判定。
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main(void) {
int t, a, b, c;
cin >> t;
while (t-- > 0) {
cin >> a >> b >> c;
for (int i = 1; i <= (2 * (b + c) + 1); i++) {
//if (i != 1)cout << endl;
//head
if (i % 2 == 1 && i <= (2 * b)) {
for (int j = 1; j <= 2*(b-i/2); j++) {
cout << ".";
}
for (int j = 2 * (b - i / 2) + 1; j <= 2 * (b - i / 2) + a * 2; j+=2) {
cout << "+-";
}
cout << "+";
if (b < c || i <= (2 * c + 1)) {
for (int j = 2 * (b - i / 2) + a * 2 + 2; j <= 2 * (a + b) + 1; j += 2) {
cout << ".+";
}
}
else
{
cout << ".";
for (int j = 1; j <= c; j++) {
cout << "+.";
}
for (int j = 2 * (b - i / 2) + a * 2 + 2*c+3; j <= 2 * (a + b) + 1; j++) {
cout << ".";
}
}
cout << endl;
continue;
}
if (i % 2 == 0 && i <= (2 * b)) {
for (int j = 1; j <= 2 * (b - i / 2)+1; j++) {
cout << ".";
}
for (int j = 2 * (b - i / 2) + 1; j <= 2 * (b - i / 2) + a * 2; j += 2) {
cout << "/.";
}
if (b < c ||i<=(2*c+1)) {
for (int j = 2 * (b - i / 2) + a * 2 + 2; j <= 2 * (a + b) + 1; j += 2) {
cout << "/|";
}
}
else
{
cout << "/";
for(int j=1;j<=c;j++){
cout << "|/";
}
for (int j = 2 * (b - i / 2) + a * 2+2*c+3; j <= 2 * (a + b) + 1; j++) {
cout << ".";
}
}
cout << endl;
continue;
}
//middle
if (i % 2 == 1 && i > (2 * b)&& i<=2*c+1) {
for (int j = 1; j <= 2 * a; j+=2) {
cout << "+-";
}
cout << "+";
for (int j = 2 * (a+1); j <= 2 * (a + b) + 1; j += 2) {
cout << ".+";
}
cout << endl;
continue;
}
if (i % 2 == 0 && i > (2 * b) && i <= 2 * c + 1) {
for (int j = 1; j <= 2 * a; j+=2) {
cout << "|.";
}
cout << "|";
for (int j = 2 * (a + 1); j <= 2 * (a + b) + 1; j += 2) {
cout << "/|";
}
cout << endl;
continue;
}
//bottom
if (i % 2 == 1 && i > (2 * c + 1)) {
for (int j = 1; j <= 2 * a; j+=2) {
cout << "+-";
}
cout << "+";
int k = (2 * (c + b) + 1 - i) / 2+1;
for (int j = 1; j <= k-1; j++) {
cout << ".+";
}
for (int j = 2 * a + 1 + 2 * k; j <= 2 * (a + b) + 2; j++) {
cout << ".";
}
cout << endl;
continue;
}
if (i % 2 == 0 && i > (2 * c + 1)) {
for (int j = 1; j <= 2 * a; j+=2) {
cout << "|.";
}
int k = (2 * (c + b) + 1 - i) / 2+1;
for (int j = 1; j <= k; j++) {
cout << "|/";
}
for (int j = 2 * a + 1 + 2 * k; j <= 2 * (a + b) + 1; j++) {
cout << ".";
}
cout << endl;
continue;
}
}
}
return 0;
}
以上是关于HDU 6330--Visual Cube(构造,计算)的主要内容,如果未能解决你的问题,请参考以下文章