2018-07-31 | Contest 3 HDU 6330 Visual Cube

本文介绍了一种解决三维立方体可视化问题的算法,通过分析输入的立方体尺寸,使用特定的规律绘制出立方体的视觉表现。文章提供了详细的代码实现,包括初始化矩阵、绘制立方体边框和顶点的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

 

用户表: Users +-------------+---------+ | Column Name | Type | +-------------+---------+ | user_id | int | | user_name | varchar | +-------------+---------+ user_id 是该表的主键(具有唯一值的列)。 该表中的每行包括用户 ID 和用户名。 注册表: Register +-------------+---------+ | Column Name | Type | +-------------+---------+ | contest_id | int | | user_id | int | +-------------+---------+ (contest_id, user_id) 是该表的主键(具有唯一值的列的组合)。 该表中的每行包含用户的 ID 和他们注册的赛事。 编写解决方案统计出各赛事的用户注册百分率,保留两位小数。 返回的结果表按 percentage 的 降序 排序,若相同则按 contest_id 的 升序 排序。 返回结果如下示例所示。 示例 1: 输入: Users 表: +---------+-----------+ | user_id | user_name | +---------+-----------+ | 6 | Alice | | 2 | Bob | | 7 | Alex | +---------+-----------+ Register 表: +------------+---------+ | contest_id | user_id | +------------+---------+ | 215 | 6 | | 209 | 2 | | 208 | 2 | | 210 | 6 | | 208 | 6 | | 209 | 7 | | 209 | 6 | | 215 | 7 | | 208 | 7 | | 210 | 2 | | 207 | 2 | | 210 | 7 | +------------+---------+ 输出: +------------+------------+ | contest_id | percentage | +------------+------------+ | 208 | 100.0 | | 209 | 100.0 | | 210 | 100.0 | | 215 | 66.67 | | 207 | 33.33 | +------------+------------+ 解释: 所有用户都注册了 208、209 和 210 赛事,因此这些赛事的注册率为 100% ,我们按 contest_id 的降序排序加入结果表中。 Alice 和 Alex 注册了 215 赛事,注册率为 ((2/3) * 100) = 66.67% Bob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33%
最新发布
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值