1. 程式人生 > >Problem L Visual Cube

Problem L Visual Cube

rec 情況 show for play comm output 模擬 ota

Problem L Visual Cube

題目:

Problem L. Visual Cube

http://acm.hdu.edu.cn/showproblem.php?pid=6330

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 55 Accepted Submission(s): 45


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(1T50), denoting the number of test cases.
In each test case, there are 3 integers a,b,c(1a,b,c20), 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

思路:

  模擬題,先用‘’.‘’填充所有的,然後先填頂面,再填正面,最後填側面。題目不難,但是有些復雜,所以要細心,註意分類討論,註意邊界的情況。

代碼:

#include<cstdio>
using namespace std;
char s[100][100];
int maxn = 100
; void put(int row,int col) { for(int i=1; i<=row; i++) { for(int j=1; j<=col; j++) printf("%c",s[i][j]); puts(""); } } int main() { int t; scanf("%d",&t); while(t--) { int a,b,c; scanf("%d%d%d",&a,&b,&c); for(int i=1; i<100; i++) for(int j=1; j<100; j++) s[i][j]=.; ///頂面 int indexj = b*2+1; for(int i=1; i<=b*2; i++) { if(i%2) { for(int j=indexj; j<=indexj+2*a; j++) { if(j%2)s[i][j]=+; else s[i][j]=-; } } else { for(int j=indexj; j<=indexj+2*a; j++) { if(j%2==0)s[i][j]=/; else s[i][j]=.; } } indexj--; } ///正面 for(int i=b*2+1; i<=b*2+1+c*2; i++) { if((i-b*2)%2) { for(int j=1; j<=a*2+1; j++) { if(j%2)s[i][j]=+; else s[i][j]=-; } } else { for(int j=1; j<=a*2+1; j++) { if(j%2)s[i][j]=|; else s[i][j]=.; } } } ///側面 int indexi=2*b+1; for(int j=a*2+1; j<=a*2+b*2+1; j++) { if((j-a*2)%2) { for(int i=indexi; i<=indexi+c*2; i++) { if((i-indexi)%2==0) s[i][j]=+; else s[i][j]=|; } } else { for(int i=indexi; i<=indexi+c*2; i++) { if((i-indexi)%2==0) s[i][j]=/; else s[i][j]=.; } } indexi--; } int hh = b*2+1+c*2; int ll = a*2+b*2+1; put(hh,ll); } return 0; }

Problem L Visual Cube