Codeforces Round #192 (Div. 2) 。。很水的只过了两题- -

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

You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows:

The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.

Please output the maximum number of cake cells that the cakeminator can eat.

Input

The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these:

  • '.' character denotes a cake cell with no evil strawberry;
  • 'S' character denotes a cake cell with an evil strawberry.

Output

Output the maximum number of cake cells that the cakeminator can eat.

Sample test(s)
input
3 4
S...
....
..S.
output
8
Note

For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).


题意
给出一个地图,上面'S'代表草莓, '.'代表蛋糕,一次只能吃一行或者一列,求出不吃草莓的情况下,最多能吃到多少蛋糕。

果断直接暴力。从行开始,一行没草莓就可以吃,然后在从列开始,这里要注意,行每吃掉一行,在找列的时候就会少掉一格蛋糕。
轻松水过这题。。
#include <stdio.h>
#include <string.h>

int r, c;
char map[20][20];
int main()
{
    int i, j;
    memset(map, 'S', sizeof(map));
    scanf("%d%d", &r, &c);
    getchar();
    for (i = 1; i <= r; i++)
    {
        for (j = 1; j <= c; j++)
        {
            scanf("%c", &map[i][j]);
        }
        getchar();
    }
    
    int sum = 0;
    int sb = 0;
    for (i = 1; i <= r; i ++)
    {
        for (j = 1; j <= c; j ++)
            if (map[i][j] == 'S')
                break;
            if( j == c + 1)
            {
                sum += c;
                sb++;
            }
    }
    for (i = 1; i <= c;i++)
    {
        for (j = 1; j <= r; j++)
            if (map[j][i] == 'S')
                break;
            if (j == r + 1)
                sum += r - sb;
    }
    printf("%d\n",sum);
    return 0;
}

B. Road Construction
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.

Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.

Input

The first line consists of two integers n and m .

Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ nai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.

It is guaranteed that every pair of cities will appear at most once in the input.

Output

You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.

If there are several solutions, you may print any of them.

Sample test(s)
input
4 1
1 3
output
3
1 2
4 2
2 3
Note

This is one possible solution of the example:

These are examples of wrong solutions:

The above solution is wrong because it doesn't use the minimum number of edges ( 4 vs  3). In addition, it also tries to construct a road between cities  1 and  3, while the input specifies that it is not allowed to construct a road between the pair.

The above solution is wrong because you need to traverse at least  3 roads to go from city  1 to city  3, whereas in your country it must be possible to go from any city to another by traversing at most  2 roads.

Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city  1 to  32 to  3, and  4 to  3.


题意
输入n个国家,m条道路。以下m列代表m条不可建设的道路。。
要求出每个城市相通,且每两个城市之间只要最多经过2条路就可以到达。输出一种情况即可。。

刚开始没看清楚题意中有m < n / 2这个条件。想复杂了。其实只要找出一个城市,他没有和其他城市不能连接的话,就以这个城市为中心,和其他每个城市分别相连,就是一种满足的情况。。
很水- - 但是因为条件没看仔细看了好一会。。

#include <stdio.h>
#include <string.h>

int n, m;
int a, b;
int map[1005][1005];
int vis[1005];
int lu[2222][2];
int main()
{
    int i, j;
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; i ++)
    {
        scanf("%d%d", &a, &b);
        map[a][b] = map[b][a] = -1;
        vis[a] = vis[b] = 1;
    }
    for (i = 1; i <= n; i ++)
    {
        if (vis[i] == 0)
        {
            break;          
        }
    }
    int t = 0;
    for (j = 1; j <= n; j ++)
    {
        if (j != i)
        {
            lu[t][0] = i;
            lu[t][1] = j;
            t ++;
        }
    }
    printf("%d\n", n - 1);
    for (i = 0; i < n - 1; i ++)
        printf("%d %d\n", lu[i][0], lu[i][1]);
    return 0;
}

C题。。
C. Purification
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:

The cleaning of all evil will awaken the door!

Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.

The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.

You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.

Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

Input

The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

Output

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

Sample test(s)
input
3
.E.
E.E
.E.
output
1 1
2 2
3 3
input
3
EEE
E..
E.E
output
-1
input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
output
3 3
1 3
2 2
4 4
5 3
Note

The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.

In the second example, it is impossible to purify the cell located at row 1 and column 1.

For the third example:


当时没有什么明确的思路,以为用暴搜。结果没写出来,。
看了别人题解才明白有一定规律的。。

题意大概就是你能施放净化魔法。清楚邪恶的点。一次施放能清除掉横排竖排。。
问最少要施放几次,并且输出释放的位置
其实对于一个n*n 只需要施放 最少n次就可以了。 如果存在一个竖排横排都被占据了 的情况 就会导致有点不能清除。。
大致思路是这样,,似乎挺水的。。

D,E 还是老样子,,,几乎没看
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值