Bayan 2015 Contest Warm Up

A. Bayan Bus
time limit per test   2 seconds
memory limit per test  256 megabytes
题目连接:传送门

The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.

The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.

In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.

Input

The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.

Output

Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.

Sample test(s)
Input
9
Output
+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+
Input
20
Output
+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+


意解: 纯模拟题; 

AC代码:


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char a[10][100] =
{
    "+------------------------+",
    "|#.#.#.#.#.#.#.#.#.#.#.|D|)",
    "|#.#.#.#.#.#.#.#.#.#.#.|.|",
    "|#.......................|",
    "|#.#.#.#.#.#.#.#.#.#.#.|.|)",
    "+------------------------+"
};

int main()
{
    int n;
    cin>>n;
    for(int i = 1; n; i += 2)
    {
        for(int j = 1; j <= 4 && n; j++)
        {
            if(a[j][i] == '#')
            {
                n--;
                a[j][i] = 'O';
            }
        }
    }
    for(int i = 0; i < 6; i++)
        puts(a[i]);
    return 0;
}

B. Strongly Connected City

time limit per test  2 seconds

memory limit per test  256 megabytes

Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.

The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.

Input

The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets.

The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.

The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.

Output

If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".

Sample test(s)
Input
3 3
><>
v^v
Output
NO
Input
4 6
<><>
v^v^v^
Output
YES
Note

The figure above shows street directions in the second sample test case.


意解: 给你一个n*m的矩阵,每一行每一列都有特定的方向,问图是否强联通.

         易知强联通图必须满足有一个环,包含所有的顶点. 容易想到只要四个角成环就行. 分顺时针和逆时针.

         dfs爆搜也行.

AC代码:

#include <iostream>
#include <cstdio>

using namespace std;

int n,m;
char a[2][30];

int check(char c)
{
    int k;
    switch(c)
    {
        case 'v': return 1;
        case '>': return 2;
        case '^': return 3;
        case '<': return 4;
    }
}

bool solve()
{
    int  b[4];
    b[0] = check(a[0][0]);
    b[1] = check(a[0][n - 1]);
    b[2] = check(a[1][0]);
    b[3] = check(a[1][m - 1]);
    if(b[0] == 4 && b[1] == 2 && b[2] == 1 && b[3] == 3) return true;
    if(b[0] == 2 && b[1] == 4 && b[2] == 3 && b[3] == 1) return true;
    return false;
}

int main()
{
    scanf("%d %d",&n,&m);
    scanf("%s %s",a[0],a[1]);
    puts(solve() ? "YES" : "NO");
    return 0;
}


DFS版本:


#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;
typedef pair<int,int> P;

int n,m,vis[30][30],count;
char a[2][30];
vector<P> G[30];

int check(char c)
{
    int k;
    switch(c)
    {
        case 'v': return 1;
        case '>': return 1;
        case '^': return -1;
        case '<': return -1;
    }
}

void dfs(int x, int y)
{
    if(vis[x][y]) return ;
    P c = G[x][y];
    vis[x][y] = 1;
    count++;
    int ua = y + c.first;
    int ub = x + c.second;
    if(ua >= 0 && ua < m) dfs(x,ua);
    if(ub >= 0 && ub < n) dfs(ub,y);
}

bool solve()
{

        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < m; k++)
            {
                G[j].push_back(make_pair(check(a[0][j]),check(a[1][k])));
            }
        }

        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                count = 0;
                memset(vis,0,sizeof(vis));
                dfs(i,j);
                if(count != n * m) return false;
            }
        }

        return true;

}

int main()
{
    scanf("%d %d",&n,&m);
    scanf("%s %s",a[0],a[1]);
    puts(solve() ? "YES" : "NO");
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值