# 洛谷 P1058 立体图

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 #include #include #include #include #include #define ll long long #define pii pair #define PINF 0x7fffffff #define NINF 0x80000000 using namespace std; int m, n, am, an; int arr[55][55]; char output[500][500]; int calM(int m, int mh, int tm) { //每行挑最大的执行一次     return (tm - m + 1) * 2 + max(1 + 3 * mh, 1 + 2 * (m - 1)); } inline int calN(int m, int n) { //整体执行一次     return 1 + 4 * n + 2 * m; } inline void printLine(int x, int y) {     output[x][y] = output[x][y + 4] = '+';     output[x][y + 1] = output[x][y + 2] = output[x][y + 3] = '-'; } inline void printRow(int x, int y) {     output[x][y] = output[x + 2][y - 2] = '+';     output[x + 1][y - 1] = '/'; } inline void printHeight(int x, int y) {     output[x][y] = output[x + 3][y] = '+';     output[x + 1][y] = output[x + 2][y] = '|'; } inline void printSpace(int x, int y) {     output[x + 1][y] = output[x + 1][y + 1] = output[x + 1][y + 2] = ' ';     output[x + 3][y - 1] = output[x + 3][y] = output[x + 3][y + 1] = ' ';     output[x + 4][y - 1] = output[x + 4][y] = output[x + 4][y + 1] = ' ';     output[x + 2][y + 3] = output[x + 3][y + 3] = ' '; } inline void printCube(int x, int y) { //左上角坐标     printLine(x, y);     printLine(x + 2, y - 2);     printLine(x + 5, y - 2);     printRow(x, y);     printRow(x, y + 4);     printRow(x + 3, y + 4);     printHeight(x + 2, y - 2);     printHeight(x + 2, y + 2);     printHeight(x, y + 4);     printSpace(x, y); } inline void printCube2(int l, int r, int h) {     printCube(am - 3 * h - 2 * (m-l+1), 1+2 * (m - l + 1) + (r - 1) * 4); } inline void printAns() {     for (int i = 1; i <= am; i++) {         cout << output[i] + 1 << endl;     }     cout << endl; } int main() {     cin >> m >> n;     an = calN(m, n);     for (int i = 1; i <= m; i++) {         int mmax = 0;         for (int j = 1; j <= n; j++) {             cin >> arr[i][j];             mmax = max(mmax, arr[i][j]);         }         am = max(am, calM(i, mmax, m));     }     for (int i = 1; i <= am; i++) {         for (int j = 1; j <= an; j++) {             output[i][j] = '.';         }     }     for (int i = 1; i <= m; i++) {         for (int j = 1; j <= n; j++) {             for (int k = 1; k <= arr[i][j]; k++) {                 printCube2(i, j, k);                 //printAns();             }         }     }     printAns(); }

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 #include #include #include #include #include #include #define ll long long #define pii pair #define PINF 0x7fffffff #define NINF 0x80000000 using namespace std; int m, n, am, an; int arr[55][55]; char output[500][500]; int calM(int m, int mh, int tm) { //每行挑最大的执行一次     return (tm - m + 1) * 2 + max(1 + 3 * mh, 1 + 2 * (m - 1)); } inline int calN(int m, int n) { //整体执行一次     return 1 + 4 * n + 2 * m; } inline void printLine(int x, int y) {     output[x][y] = output[x][y + 4] = '+';     output[x][y + 1] = output[x][y + 2] = output[x][y + 3] = '-'; } inline void printRow(int x, int y) {     output[x][y] = output[x + 2][y - 2] = '+';     output[x + 1][y - 1] = '/'; } inline void printHeight(int x, int y) {     output[x][y] = output[x + 3][y] = '+';     output[x + 1][y] = output[x + 2][y] = '|'; } inline void printSpace(int x, int y) {     output[x + 1][y] = output[x + 1][y + 1] = output[x + 1][y + 2] = ' ';     output[x + 3][y - 1] = output[x + 3][y] = output[x + 3][y + 1] = ' ';     output[x + 4][y - 1] = output[x + 4][y] = output[x + 4][y + 1] = ' ';     output[x + 2][y + 3] = output[x + 3][y + 3] = ' '; } inline void printCube(int x, int y) { //左上角坐标     printLine(x, y);     printLine(x + 2, y - 2);     printLine(x + 5, y - 2);     printRow(x, y);     printRow(x, y + 4);     printRow(x + 3, y + 4);     printHeight(x + 2, y - 2);     printHeight(x + 2, y + 2);     printHeight(x, y + 4);     printSpace(x, y); } inline void printCube2(int l, int r, int h) {     printCube(am - 3 * h - 2 * (m - l + 1), 1 + 2 * (m - l + 1) + (r - 1) * 4); } inline void printArray() {     cout << "Printing each element of the array:" << endl;     for (int i = 1; i <= m; i++) {         for (int j = 1; j <= m; j++) {             cout << arr[i][j] << " ";         }         cout << endl;     } } inline void printAns() {     for (int i = 1; i <= am; i++) {         cout << output[i] + 1 << endl;     }     cout << endl; } int main() {     srand((unsigned)time(NULL));     cout << "Please input the side length "n" of the cube array (n<=50):";     int len;     cin >> len;     m = n = len;     an = calN(m, n);     cout << "Please input the max height "mh" of cubes in each array item (1<=mh<=100):";     int mh;     cin >> mh;     cout << "Do you want to show the whole process of filling?(Answer with 0[No] or 1[Yes]):";     bool flag;     cin >> flag;     for (int i = 1; i <= m; i++) {         int mmax = 0;         for (int j = 1; j <= n; j++) {             arr[i][j] = rand() % mh + 1;             mmax = max(mmax, arr[i][j]);         }         am = max(am, calM(i, mmax, m));     }     for (int i = 1; i <= am; i++) {         for (int j = 1; j <= an; j++) {             output[i][j] = '.';         }     }     cout << "Automatically generated an array,printed in the following.Press ENTER to continue." << endl;     printArray();     cin.get(); cin.get();     for (int i = 1; i <= m; i++) {         for (int j = 1; j <= n; j++) {             for (int k = 1; k <= arr[i][j]; k++) {                 if (flag)cout << "Printing cube on postion(" << i << "," << j << "," << k << ")." << endl;                 printCube2(i, j, k);                 if (flag)printAns();             }         }     }     cout << "Printing Final Result:" << endl;     printAns(); }