UVa 1605 联合国大楼

Posted 谦谦君子,陌上其华

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVa 1605 联合国大楼相关的知识,希望对你有一定的参考价值。

https://vjudge.net/problem/UVA-1605

题意:有n个国家,要求设计一栋楼并为这n个国家划分房间,要求国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的。

思路:乍一看很难的样子,但真的是很简单。一共只要两层,每层都是n*n的,第一层第i行全是国家i,第二层第j列全是国家j。

         但是如果不是这样做的话好像还是挺难的。

         

 1 #include<iostream>  
 2 #include<algorithm>
 3 #include<string>
 4 #include<cstring>
 5 #include<sstream>
 6 using namespace std;
 7 
 8 char ans[60] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 9 
10 int n;
11 
12 int main()
13 {
14     //freopen("D:\\txt.txt", "r", stdin);
15     while (cin>>n && n)
16     {
17         cout << "2 " << n << " " << n << endl;
18         for (int i = 0; i < n; i++)
19         {
20             for (int j = 0; j < n; j++)
21                 cout << ans[i];
22             cout << endl;
23         }
24         cout << endl;
25         for (int i = 0; i < n; i++)
26         {
27             for (int j = 0; j < n; j++)
28                 cout << ans[j];
29             cout << endl;
30         }
31     }
32     return 0;
33 }

 

以上是关于UVa 1605 联合国大楼的主要内容,如果未能解决你的问题,请参考以下文章

UVa 1605 - Building for UN

例题 8-2 UVA-1605Building for UN

UVA1605-Building for UN(思维)

uva 1605

UVa1605 Building for UN (构造法)

五角大楼计划扩展其有争议的Maven AI项目