题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4480
题意:有N个国家,设计一座大楼使每个国家都与其他国家相邻,相邻包括上下左右。
题解:N最大50,采取两层,第一层每行相同,第二层每列相同,这样最后就能满足都相邻的条件。
AC代码:
#include <iostream>
#include <cstring>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
int n,m,l,w;
char s[55];
int main(int argc, char const *argv[])
{
int k = 'a'-'0';
for(int i=1;i<=26;i++)
{
int now = k+i-1;
s[i]=now+'0';
}
k = 'A'-'0';
for(int i=1;i<=25;i++)
{
int now =k+i;
s[26+i]=now+'0';
}
int t = 0;
while(cin>>n)
{
if(t==1)cout<<endl;
m=l=n;
cout<<2<<" "<<m<<" "<<l<<endl;
_for(i,1,m)
{
_for(j,1,l)
{
cout<<s[i];
}
cout<<endl;
}
cout<<endl;
_for(i,1,m)
{
_for(j,1,l)
{
cout<<s[j];
}
cout<<endl;
}
cout<<endl;
t=1;
}
return 0;
}