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.
![](https://i-blog.csdnimg.cn/blog_migrate/b07f1c94b77de276c19d53f1d8109787.png)
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.
The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.
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.
9
+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+
20
+------------------------+
|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;
}
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.
![](https://i-blog.csdnimg.cn/blog_migrate/841f05bcd894dab17bdfb218d678f4eb.png)
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.
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.
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
3 3 ><> v^v
NO
4 6 <><> v^v^v^
YES
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;
}
#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;
}