Codeforces 592

A. PawnChess
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».

This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.

Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c.

There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.

Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.

Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.

Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.

Input

The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.

It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.

Output

Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.

Examples
input
........
........
.B....B.
....W...
........
..W.....
........
........
output
A
input
..B.....
..W.....
......B.
........
.....W..
......B.
........
........
output
B
Note

In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.

/*
  简单的模拟题
  给你一个8×8的矩阵 .表示可走的路 B表示black棋 W表示white
  A下白棋 B下黑棋 A先走
  A要让他的白棋到第一排 B要让他的黑棋到最后一排 A先走
  数据保证有一方获胜 不存在打平的情况
  如果棋子要前进的地方有别的棋子 这个棋子不能走过去
  第二个样例可以很好的解释这一点 直接模拟一遍即可
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
char s[15][15];
int mp[15][15]={0};
char mark_1[15][15],mark_2[15][15];
int main(void)
{
    for(int i=0;i<8;i++)
        scanf("%s",s[i]);
    int mi_1=10,mi_2=0;
    int flag_1=0,flag_2=0;
    for(int j=0;j<8;j++)
    {
        flag_1=0,flag_2=0;
        int temp=-1;
        for(int i=0;i<8;i++)
        {
            if(s[i][j]=='B')
            {
                if(flag_1==0) flag_1=1;
                temp=i;
                flag_2=0;
            }
            if(s[i][j]=='W')
            {
                flag_2=1;
                temp=-1;
                if(flag_1==1) continue;  //说明有黑棋挡路
                else if(flag_1==0)
                {
                    flag_1=2;
                    mi_1=min(i,mi_1);
                }
            }
        }
        if(flag_2==0) mi_2=max(mi_2,temp);
    }
    //printf("%d %d\n",mi_1,7-mi_2);
    if(mi_1<=7-mi_2) puts("A");
    else puts("B");
    return 0;
}


B. The Monster and the Squirrel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.

Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2, 3, ..., n (in this particular order). And then she puts a walnut in each region inside the polygon.

Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.

Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?

Input

The first and only line of the input contains a single integer n (3 ≤ n ≤ 54321) - the number of vertices of the regular polygon drawn by Ari.

Output

Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.

Examples
input
5
output
9
input
3
output
1
Note

One of the possible solutions for the first sample is shown on the picture above.


/*
  数学题 找规律
  题意:给你一个有n个顶点的凸多边形,每个点依次标号为1~n
        从标号1开始到n不停的跟不相邻的点连接,不可以跟其他连的线相交
        然后问你将这个凸多边形分成个几个部分。
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
	long long n;
	while(scanf("%I64d",&n)!=EOF)
		printf("%I64d\n",(n-2)*(n-2));
	return 0;
}

C. The Big Race
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of Lmeters today.

Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.

While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).

Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.

Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?

Input

The first line of the input contains three integers tw and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.

Output

Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.

The fraction  (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p andq are divisible by d.

Examples
input
10 3 2
output
3/10
input
7 1 2
output
3/7
Note

In the first sample Willman and Bolt will tie in case 16 or 7 are chosen as the length of the racetrack.


/*
  题意:给你一个数t。问你在[1,t]里面有多少个整数num
        满足num % w == num % b。
        输出num/t
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
int main(void)
{
    unsigned long long t,w,b,gcd,lcm,ans,temp;
    cin>>t>>w>>b;
    gcd=__gcd(w,b);
    lcm=w/gcd;
    ans=t/lcm/b;
    temp=ans;
    ans+=ans*(min(w,b)-1)+min(t-ans*lcm*b,min(w,b)-1);
    gcd=__gcd(ans,t);
    cout<<ans/gcd<<"/"<<t/gcd<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值