UVA1605 Building for UN(思维)

本题vjudge链接

  • 题意:有一栋楼,有 n ( n ≤ 50 ) n(n \le 50) n(n50)个国家要开会,每个国家至少分配一个位置,让你输出一种方案,H层,每层W行L列,使得任意两个国家要能相邻,层数也算相邻
  • 按紫书说的构造一种解出来,只需要两层就好了,每层 n × n n \times n n×n的格子,第一层第i行是第i个国家,第二层第j列是第j个国家,
  • 这个模型有点像放筷子,有n双筷子,分别都有左和右,要想让每个左筷子都能接触到其他右筷子的方案就是在第一层筷子横着放,第二层竖着放就行了
  • 代码如下
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n;
char str[55];

void solve() {
    printf("%d %d %d\n", 2, n, n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) printf("%c", str[i]);
        puts("");
    }
    puts("");
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) printf("%c", str[j]);
        puts("");
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("D:/MYCODE/vsCode-c/test.in", "r", stdin);
    freopen("D:/MYCODE/vsCode-c/test.out", "w", stdout);
#endif
    for (int i = 0; i < 26; i++) str[i] = 'a' + i;
    for (int i = 0; i < 26; i++) str[26 + i] = 'A' + i;
    while (~scanf("%d", &n)) solve();
    return 0;
}

原地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值