题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=6330
题目
Problem L. Visual Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 970 Accepted Submission(s): 619
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
..+-+ ././| +-+.+ |.|/. +-+.. ....+-+-+-+-+-+-+ .../././././././| ..+-+-+-+-+-+-+.+ ./././././././|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/. +-+-+-+-+-+-+.+.. |.|.|.|.|.|.|/... +-+-+-+-+-+-+....
Source
2018 Multi-University Training Contest 3
Recommend
chendu | We have carefully selected several similar problems for you: 6425 6424 6423 6422 6421
题意
a*b*c的立方体,画出立体图。
题解
模拟题,都巨复杂,主要是以前模拟题都是xjb写,一般也都刚对了,这次发现很多大佬都用画布的方式来写,至少是模拟题技巧0的突破,纪念一下。
用二维数组表示出一个画布,找规律往画布里面填充。这个题刚开始xjb写竟然错了,发现问题后改的好麻烦啊,然后看大佬们都是用这样的方法,重点位置填充即可。其实我个人感觉更类似与找规律。刚开始学C的时候经常会写这种画图形的模拟题,很简单,其实就是找规律。这个题就好像是多个模拟题拼在一起的。
写一堆for循环,各种判定,把整个图分成多个部分:例如左上角右下角的一堆点,我们可以单独画出来。中间我们可以单独画出来,上面斜着的我们也能单独画出来。那么我就先按照规律画,最后一层一层覆盖,遍历输出画布就行了。代码里面大概写了点注释。
C++ 15ms AC
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<sstream>
#include<iterator>
#include<math.h>
#include<malloc.h>
#include<string.h>
#include<stack>
#define TIME std::ios::sync_with_stdio(false)
#define LL long long
#define MAX 210
#define INF 0x3f3f3f3f
using namespace std;
int T,a,b,c,i,j,k;
char dw[MAX][MAX];
void init(){
for(int i = 0;i < MAX;i++){
for(int j = 0;j < MAX;j++){
dw[i][j] = '0';
}
}
}
int main() {
TIME;
cin >> T;
while(T--){
cin >> a >> b >> c;
init();
// 画布重点,确定画布范围
int x = 2*a+1+b*2;
int y = 2*c+1+b*2;
for(i = 1;i <= 2*b;i++){
// 画左上角的点
for(j = 1;j <= 2*b-i+1;j++){
dw[i][j] = '.';
}
// 画上面斜着的部分
if(i % 2 == 1){
for(k = 1;k <= 2*a+1;k++){
if(k % 2 == 1){
dw[i][j] = '+';
}else{
dw[i][j] = '-';
}
j++;
}
// 斜着的画完要补立体图中竖着的部分
if(j <= x){
for(k = j;k <= x;k++){
if(dw[x][y])
if(k % 2 == 0){
dw[i][k] = '.';
}else{
dw[i][k] = '+';
}
}
}
}else{
for(k = 1;k <= 2*a+1;k++){
if(k % 2 == 1){
dw[i][j] = '/';
}else{
dw[i][j] = '.';
}
j++;
}
if(j <= x){
for(k = j;k <= x;k++){
if(dw[x][y])
if(k % 2 == 0){
dw[i][k] = '/';
}else{
dw[i][k] = '|';
}
}
}
}
}
// 画正面部分,这里全画完
for(i = 2*b+1;i <= y;i++){
if(i % 2 == 1){
for(j = 1;j <= 2*a+1;j++){
if(j % 2 == 1){
dw[i][j] = '+';
}else{
dw[i][j] = '-';
}
}
for(;j <= x;j++){
if(j % 2 == 1){
dw[i][j] = '+';
}else{
dw[i][j] = '.';
}
}
}else{
for(j = 1;j <= 2*a+1;j++){
if(j % 2 == 1){
dw[i][j] = '|';
}else{
dw[i][j] = '.';
}
}
for(;j <= x;j++){
if(j % 2 == 1){
dw[i][j] = '|';
}else{
dw[i][j] = '/';
}
}
}
}
// 画右下角的点,直接覆盖上面画的,这样上面就不考虑不能画的部分
for(i = y;i > y-2*b;i--){
int num = y-i;
num = 2*b - num;
for(j = x;j > x - num;j--){
dw[i][j] = '.';
}
}
// 输出
for(i = 1;i <= y;i++){
for(j = 1;j <= x;j++){
cout << dw[i][j];
}
cout << endl;
}
}
system("pause");
return 0;
}