zoukankan      html  css  js  c++  java
  • Codeforces Round #480 (Div. 2) B. Marlin

    题目地址:http://codeforces.com/contest/980/problem/B

    官方题解:

    题意:

      有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民在(4,n)钓鱼;还有一个村庄在(4,1),村民在(1,n)钓鱼;现在要修建k个宾馆,不能修建在边界上,问能否给出一种安排方案使得两个村庄的村民到他们各自的活动地点的最短路的条数相等。

    思路:

      画了几个实例就应该知道,无论n和k是多少,都可以构建出合理的方案,并且 0k2×(n2),所以全是YES。

      如果k为偶数,那么就上下对称,一列一列横着输出;当k为奇数,我采用的是首先把第二排从中间开始向两边填满,然后第三排则是从中间一格的两边开始填。

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<string>
     6 #include<iostream>
     7 #include<map>
     8 #include<vector>
     9 #include<set>
    10 #include<queue>
    11 using namespace std;
    12 const int N = 100;
    13 int main() {
    14     int n, k;
    15     char ans[5][N];
    16     scanf("%d %d", &n, &k);
    17     printf("YES
    ");
    18     for (int i = 0; i < 5; i++)
    19     {
    20         for (int j = 0; j < N; j++)
    21         {
    22             ans[i][j] = '.';
    23         }
    24     }
    25     if (k % 2 == 0) 
    26     {
    27         int p = 2;
    28         while (k > 0) 
    29         {
    30             ans[2][p] = '#';
    31             ans[3][p] = '#';
    32             p++;
    33             k -= 2;
    34         }
    35     }
    36     else 
    37     {
    38         if (k == 1) 
    39         {
    40             ans[2][n / 2 + 1] = '#';
    41         }
    42         else if (k == 3) 
    43         {
    44             int s = (n + 1) / 2;
    45             ans[2][s] = '#';
    46             ans[2][s - 1] = '#';
    47             ans[2][s + 1] = '#';
    48         }
    49         else 
    50         {
    51             ans[2][2] = '#';
    52             ans[2][3] = '#';
    53             ans[3][2] = '#';
    54             int p = 4;
    55             k -= 3;
    56             while (k > 0) 
    57             {
    58                 k -= 2;
    59                 ans[2][p] = '#';
    60                 ans[3][p] = '#';
    61                 p++;
    62             }
    63         }
    64     }
    65     for (int i = 1; i <= 4; i++) 
    66     {
    67         for (int j = 1; j <= n; j++) 
    68         {
    69             printf("%c", ans[i][j]);
    70         }
    71         printf("
    ");
    72     }
    73     return 0;
    74 }
  • 相关阅读:
    转帖:解决从9.2.0.1升级到9.2.0.7出现的错误
    最近在公司内部作了一次WCF的培训
    SourceSafe的命令行
    公司再过一两个月就要关门了
    MimeType
    ORACLE 10G 如何使用超过1.7G的内存
    切换网卡
    热键
    Oracle数据库碎片整理
    Hydra安装与使用
  • 原文地址:https://www.cnblogs.com/Tangent-1231/p/9013593.html
Copyright © 2011-2022 走看看