</pre>叠筐</h1><strong><span style="font-family:Arial;font-size:12px;color:green;font-weight:bold">Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13712 Accepted Submission(s): 3569</span></strong><div class="panel_title" align="left">Problem Description</div><div class="panel_content">需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Input</div><div class="panel_content">输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Output</div><div class="panel_content">输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="font-family:Courier New,Courier,monospace">11 B A
5 @ W</div>
Sample Output
AAAAAAAAA
ABBBBBBBBBA
ABAAAAAAABA
ABABBBBBABA
ABABAAABABA
ABABABABABA
ABABAAABABA
ABABBBBBABA
ABAAAAAAABA
ABBBBBBBBBA
AAAAAAAAA
@@@
@WWW@
@W@W@
@WWW@
@@@
Author
qianneng
Source
</pre>叠筐</h1><strong><span style="font-family:Arial;font-size:12px;color:green;font-weight:bold">Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13712 Accepted Submission(s): 3569</span></strong><div class="panel_title" align="left">Problem Description</div><div class="panel_content">需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Input</div><div class="panel_content">输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Output</div><div class="panel_content">输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。</div><div class="panel_bottom"> </div><div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="font-family:Courier New,Courier,monospace">11 B A
5 @ W</div>
AAAAAAAAA ABBBBBBBBBA ABAAAAAAABA ABABBBBBABA ABABAAABABA ABABABABABA ABABAAABABA ABABBBBBABA ABAAAAAAABA ABBBBBBBBBA AAAAAAAAA @@@ @WWW@ @W@W@ @WWW@ @@@
开始时以为是深搜,最后发现直接规律输出即可
//@auther yangZongJun
/********************************************//**
Date : 2014/02/17
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2074
题 意:搜索
解题思路:
***********************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 85;
const int INF = 2100000000;
//深搜错误代码
int n;
char center, surround;
char graph[MAXN][MAXN];
void dfs(int x, int y)
{
// if(! (0<=x&&x<n || 0<=y&&y<n || graph[x][y]==' ')) return ;
for(int i = -1; i <= 1; i++)
{
for(int j=-1; j<= 1; j++)
{
int xx = x+i, yy = y+j;
if(i == 0 && j== 0) continue;
//if(! (0<=xx&&xx<n || 0<=yy&&yy<n || graph[xx][yy]==' ')) return ;
//if(!(0<=xx&&xx<n && 0<=yy&&yy<n) &&(graph[xx][yy]==center || graph[xx][yy]==surround)) return ;
if(0<=xx&&xx<n && 0<=yy&&yy<n && graph[xx][yy]==' ')
{
if(graph[x][y] == center)
{
graph[xx][yy] = surround;
}
else
{
graph[xx][yy] = center;
}
dfs(xx, yy);
}
}
}
return ;
}
int main()
{
freopen("input.txt", "r", stdin);
while(~scanf("%d %c %c", &n, ¢er, &surround))
{
//cout << center << surround << endl;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
graph[i][j] = ' ';
graph[n/2][n/2] = center;
dfs(n/2, n/2);
graph[0][0] = ' ';
graph[0][n-1] = ' ';
graph[n-1][0] = ' ';
graph[n-1][n-1] = ' ';
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
printf("%c", graph[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}
AC代码:
//@auther yangZongJun
/********************************************//**
Date : 2014/02/17
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2074
题 意:输出图形
解题思路:
***********************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 85;
const int INF = 2100000000;
int n;
char center, surround;
char graph[MAXN][MAXN];
int main()
{
// freopen("input.txt", "r", stdin);
int cas = 0;
while(~scanf("%d %c %c", &n, ¢er, &surround))
{
if(cas) printf("\n");//没两个样例之间输出空格
if(n == 1)//1时特判一下
{
if(cas) printf("%c\n", center);continue;
}
//cout << center << surround << endl;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
graph[i][j] = ' ';
graph[n/2][n/2] = center;
for(int i=1; i<=n/2; i++)
{
int temp = n/2-i;
if(temp==-1) break;
char ch;
if(i%2==1)
{
ch = surround;
}
else ch = center;
for(int j=0; j<2*i+1; j++)
{
graph[temp][temp+j] = ch;
}
int tt = n/2+i;
for(int j=0; j<2*i+1; j++)
{
graph[tt][temp+j] = ch;
}
int t3 = n/2-i;
for(int j=0; j<2*i+1; j++)
{
graph[t3+j][t3] = ch;
}
int t4 = n/2+i;
for(int j=0; j<2*i+1; j++)
{
graph[t3+j][t4] = ch;
}
}
graph[0][0] = ' ';
graph[0][n-1] = ' ';
graph[n-1][0] = ' ';
graph[n-1][n-1] = ' ';
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
printf("%c", graph[i][j]);
}
printf("\n");
}
//printf("\n");
cas++;
}
return 0;
}