Problem L. Visual Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 326 Accepted Submission(s): 234
Problem Description
Little Q likes solving math problems very much. Unluckily, however, he does not have good spatial ability. Everytime he meets a 3D geometry problem, he will struggle to draw a picture.
Now he meets a 3D geometry problem again. This time, he doesn't want to struggle any more. As a result, he turns to you for help.
Given a cube with length a, width b and height c, please write a program to display the cube.
Input
The first line of the input contains an integer T(1≤T≤50), denoting the number of test cases.
In each test case, there are 3 integers a,b,c(1≤a,b,c≤20), denoting the size of the cube.
Output
For each test case, print several lines to display the cube. See the sample output for details.
Sample Input
2
1 1 1
6 2 4
Sample Output
..+-+
././|
+-+.+
|.|/.
+-+..
....+-+-+-+-+-+-+
.../././././././|
..+-+-+-+-+-+-+.+
./././././././|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/.
+-+-+-+-+-+-+.+..
|.|.|.|.|.|.|/...
+-+-+-+-+-+-+....
2018 Multi-University Training Contest 3
Recommend
chendu | We have carefully selected several similar problems for you: 6331 6330 6329 6328 6327
这题没什么好说的…找规律
但是自己要反思:
1.不能只顾看着样例,要自己考虑有没有其他特殊情况
2.找规律最好还是写一写整理一下,别一边敲一边改一边想,没效率呀
ac代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int k,t,n,a,b,c,count;
scanf("%d",&t);
while(t--) {
scanf("%d %d %d",&a,&b,&c);
for(int k=1; k<=b*2+c*2+1; k++) {
count=0;
for(int i=k; i<=b*2; i++) {
printf(".");
count++;
}
if(k%2!=0) {
for(int i=1; i<=a; i++) {
if(i==1)
printf("+-+");
else
printf("-+");
}
for(int i=1; i<=b*2-count&&k<=1+2*c&&i<=2*c; i++) {
if(i%2!=0)
printf(".");
else
printf("+");
}
for(int i=1; i<=2*b-k+2*c+1&&k>1+2*c&&i<=2*c; i++) {
if(i%2!=0)
printf(".");
else
printf("+");
}
} else {
if(k<=b*2)
for(int i=1; i<=a; i++) {
if(i==1)
printf("/./");
else
printf("./");
}
else
for(int i=1; i<=a; i++) {
if(i==1)
printf("|.|");
else
printf(".|");
}
for(int i=1; i<=b*2-count&&k<=1+2*c&&i<=2*c; i++) {
if(k>2*b)
if(i%2!=0) {
printf("/");
} else
printf("|");
else if(i%2!=0) {
printf("|");
} else
printf("/");
}
for(int i=1; i<=2*b-k+2*c+1&&i<=2*c&&k>1+2*c; i++) {
if(k>2*b)
if(i%2!=0) {
printf("/");
} else
printf("|");
else if(i%2!=0) {
printf("|");
} else
printf("/");
}
}
for(int i=2*c+1+2*b-k; i<2*b; i++) {
printf(".");
}
printf("\n");
}
}
}
学长的:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pr(n) cout << n << endl
#define ll long long
#define int64 __int64
using namespace std;
//Date:2018-7-30
//Author:HarryBlackCat
int row,column,b,a,c;
char mapp[maxnn][maxnn];
int pow2(int x) {
return 2 * x + 1;
}
void init_matrix() {
for(int i = 1; i <= row; i++)
for(int j = 1; j <= column; j++)
mapp[i][j] = '.';
}
int main() {
//cin.sync_with_stdio(false);//降低cin,cout时间
int t;
while(~ri(t)) {
while(t--) {
ri3(a,b,c);
row = pow2(c) + pow2(b) - 1;
column = pow2(b) + pow2(a) - 1;
init_matrix();
//printf("row:%d column:%d\n",row,column);
for(int i = 1,k = pow2(b); i <= pow2(b); i += 2,k -= 2) {
int counter = 0;
for(int j = 0; j < pow2(a); j++) {
if(counter % 2 == 0) {
mapp[i][j + k] = '+';
if(i != pow2(b))
mapp[i + 1][j + k - 1] = '/';
} else {
mapp[i][j + k] = '-';
}
counter++;
}
}
for(int i = pow2(b); i <= row; i += 2) {
int counter = 0;
for(int j = 1; j <= pow2(a); j++) {
if(counter % 2 == 0) {
mapp[i][j] = '+';
//printf("i:%d j:%d\n",i,j);
if(i != row)
mapp[i + 1][j] = '|';
} else {
mapp[i][j] = '-';
}
counter++;
}
}
//
for(int i = column,k = 1; k <= pow2(b); k += 2,i -= 2) {
int counter = 0;
for(int j = 0; j < pow2(c); j++) {
if(counter % 2 == 0) {
mapp[j + k][i] = '+';
if(k != pow2(b))
mapp[j + k + 1][i - 1] = '/';
}
else {
mapp[j + k][i] = '|';
// if(k != pow2(b))
// mapp[j + k][i - 1] = '/';
// pr(j + k);
// pr(i);
}
counter++;
}
}
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= column; j++) {
printf("%c",mapp[i][j]);
}
printf("\n");
}
}
}
return 0;
}