Codeforces Beta Round #7

A - Kalevitch and Chess

A famous Berland’s painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.

As before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.

Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client’s requirements.

It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client’s needs. You are asked to help Kalevitch with this task.

Input

The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client’s requirements, W character stands for a white square, and B character — for a square painted black.

It is guaranteed that client’s requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).

Output

Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client’s requirements.

Examples

Input

WWWBWWBW
BBBBBBBB
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW

Output

3

Input

WWWWWWWW
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW

Output

1

今天做评奖的各种统计,做完统计脑子已经蒙了。一道简单题,结果我理解错题意了。
这道题的题意有点绕,一开始的棋盘全为白色,输入客户要求的棋盘,输出至少几笔才能达成客户的要求。
判断每一行/列是否全为B,如果全为B,就增加一次刷的次数。
注意特判如果刷的次数是16,表示全为B,这时只需要刷8次即可。

#include <cstdio>
#include <iostream>
using namespace std;

char m[10][10];

int main(void)
{
	int cnt, ans = 0;
	for (int i = 0; i < 8; i++)
		cin >> m[i];
	for (int i = 0; i < 8; i++)
    {
        cnt = 0;
        for (int j = 0; j < 8; j++)
        {
            if (m[i][j] == 'B')
                cnt++;
        }
        if (cnt == 8)
            ans++;
    }
    for (int j = 0; j < 8; j++)
    {
        cnt = 0;
        for (int i = 0; i < 8; i++)
        {
            if (m[i][j] == 'B')
                cnt++;
        }
        if (cnt == 8)
            ans++;
    }
    if (ans == 16)
        ans = 8;
    cout << ans << endl;
	return 0;
}

C - Line

A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.

Input

The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.

Output

If the required point exists, output its coordinates, otherwise output -1.

Examples

Input

2 5 3

Output

6 -3

扩展欧几里得

#include <iostream>
#include <cstdio>
using namespace std;

typedef long long ll;

ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if(b == 0)
	{
        x = 1;
        y = 0;
        return a;
    }
    ll d = exgcd(b, a % b, x, y);
    ll z = x; x = y; y = z - y * (a / b);
    return d;
}

int main(void)
{
    ll a, b, c, x, y;
    scanf("%lld%lld%lld", &a, &b, &c);
    c = -c;
    ll d = exgcd(a, b, x, y);
    if (c % d == 0) 
		printf("%lld %lld\n", x * c / d, y * c / d);
    else 
		printf("-1\n");
    
    return 0;
}

题解:https://blog.csdn.net/lihuanz/article/details/82319636

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值