题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6330
题目:
题意:给你长宽高,让你画出一个正方体。
思路:模拟即可,湘潭邀请赛热身赛原题,不过比那个容易很多,湘潭那个没写==,这个模拟还是很难受的,写了好久……
代码实现如下:
1 #include <set> 2 #include <map> 3 #include <queue> 4 #include <stack> 5 #include <cmath> 6 #include <bitset> 7 #include <cstdio> 8 #include <string> 9 #include <vector> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 16 typedef long long ll; 17 typedef pair<ll, ll> pll; 18 typedef pair<int, ll> pil;; 19 typedef pair<int, int> pii; 20 typedef unsigned long long ull; 21 22 #define lson i<<1 23 #define rson i<<1|1 24 #define bug printf("********* "); 25 #define FIN freopen("D://code//in.txt", "r", stdin); 26 #define debug(x) cout<<"["<<x<<"]" <<endl; 27 #define IO ios::sync_with_stdio(false),cin.tie(0); 28 29 const double eps = 1e-8; 30 const int mod = 10007; 31 const int maxn = 100 + 7; 32 const double pi = acos(-1); 33 const int inf = 0x3f3f3f3f; 34 const ll INF = 0x3f3f3f3f3f3f3f; 35 36 int t, a, b, c, n, m; 37 char mp[maxn][maxn]; 38 39 int main() { 40 //FIN; 41 scanf("%d", &t); 42 while(t--) { 43 scanf("%d%d%d", &a, &b, &c); 44 n = 2 * c + 1 + 2 * b; 45 m = 2 * a + 1 + 2 * b; 46 //初始化 47 for(int i = 1; i <= n; i++) { 48 for(int j = 1; j <= m; j++) { 49 mp[i][j] = '.'; 50 } 51 } 52 //上方(正方体正面的上面那条边为界线,下同)的+-构造 53 for(int i = 1; i <= 2 * b; i += 2) { 54 for(int j = 2 * b - i + 2; j <= 2 * b - i + 2 + 2 * a; j++) { 55 if(j & 1) mp[i][j] = '+'; 56 else mp[i][j] = '-'; 57 } 58 for(int j = 2 * b - i + 2 + 2 * a + 2; j <= m; j++) { 59 if(j & 1) mp[i][j] = '+'; 60 } 61 } 62 //|/构造 63 for(int i = 2; i <= 2 * b; i+=2) { 64 for(int j = 2 * b - i + 2; j <= m; j++) { 65 if(j % 2 == 0) mp[i][j] = '/'; 66 } 67 for(int j = m; j >= m - i + 2; j -= 2) { 68 mp[i][j] = '|'; 69 } 70 } 71 for(int i = 2 * b + 2; i <= n; i += 2) { 72 for(int j = 1; j <= m; j += 2) { 73 mp[i][j] = '|'; 74 } 75 for(int j = 2 * a + 2; j <= m; j+= 2) { 76 mp[i][j] = '/'; 77 } 78 } 79 //下方的+-构造 80 for(int i = 2 * b + 1; i <= 2 * c + 1; i += 2) { 81 for(int j = 1; j <= 2 * a + 1; j++) { 82 if(j & 1) mp[i][j] = '+'; 83 else mp[i][j] = '-'; 84 } 85 for(int j = 2 * a + 2; j <= m; j++) { 86 if(j & 1) mp[i][j] = '+'; 87 } 88 } 89 for(int i = n; i > 2 * c + 1; i-=2) { 90 for(int j = 1; j <= 2 * a + 1; j++) { 91 if(j & 1) mp[i][j] = '+'; 92 else mp[i][j] = '-'; 93 } 94 for(int j = 2 * a + 2; j <= m; j++) { 95 if(j & 1) mp[i][j] = '+'; 96 } 97 } 98 //我上面的处理会让下方一些应该为.的变成其他的,所以需要用.覆盖回来 99 int y = 0; 100 for(int i = 1; i < 2 * b + 1; i++) { 101 for(int j = 1; j <= 2 * b + 1 - i; j++) { 102 mp[i][j] = '.'; 103 } 104 } 105 for(int i = n; i > 2 * c + 1; i--) { 106 for(int j = 2 * a + 2 + y; j <= m; j++) { 107 mp[i][j] = '.'; 108 } 109 y++; 110 } 111 for(int i = 1; i <= n; i++) { 112 for(int j = 1; j <= m; j++) { 113 printf("%c", mp[i][j]); 114 } 115 printf(" "); 116 } 117 } 118 return 0; 119 }