Educational Codeforces Round 5 :(codeforces 616)

A. Comparing Two Long Integers

You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.

The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().

Input

The first line contains a non-negative integer a.

The second line contains a non-negative integer b.

The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.

Output

Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".

Sample test(s)
Input
9
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
=
Input
0123
9
Output
>
Input
0123
111
Output
>


/*  problem:cf-616A           */
/*  author: dang              */
/*  date:   2016-1-24  14:18  */
/*  题目大意:
    比较数字大小,比较水。
*/
#include<cstring>
#include<cstdio>
int main(){
    char stra[1000005], strb[1000005];
    int lena, lenb, i, j;
    scanf("%s",stra);
    scanf("%s",strb);
    lena=strlen(stra);  lenb=strlen(strb);
    for(i = 0; i < lena; i++){
        if(stra[i]!='0')  break;
    }
    for(j = 0; j < lenb; j++) if(strb[j]!='0') break;
    if(lena-i > lenb-j) printf(">\n");
    else if(lena-i<lenb-j) printf("<\n");
    else {
        for(;stra[i]==strb[j]&&i<lena&&j<lenb;i++,j++){}
        if(stra[i]==strb[j]) printf("=\n");
        else if(stra[i]>strb[j]) printf(">\n");
        else printf("<\n");
    }
    return 0;
}


B. Dinner with Emma

Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.

Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.

Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan.

Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.

Output

Print the only integer a — the cost of the dinner for Jack and Emma.

Sample test(s)
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note

In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.

In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.


/*  problem:cf-616B           */
/*  author: dang              */
/*  date:   2016-1-24  14:34  */
/*  题目大意:
    找到每一行的最小值,然后取其中的最大值
*/

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
int main(){
    int n, m;
    int a, minx;
    int ans=0;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i ++){
        minx = 0;
        for(int j = 0; j < m;j++){
            scanf("%d", &a);
            if(minx==0) minx=a;
            else minx=min(minx,a);
        }
        if(ans==0) ans=minx;
        else ans=max(ans,minx);
    }
    printf("%d\n", ans);
    return 0;
}

C. The Labyrinth

You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.

Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component.

For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (x, y). You should do it for each impassable cell independently.

The answer should be printed as a matrix with n rows and m columns. The j-th symbol of the i-th row should be "." if the cell is empty at the start. Otherwise the j-th symbol of the i-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces.

To make your output faster it is recommended to build the output as an array of n strings having length m and print it as a sequence of lines. It will be much faster than writing character-by-character.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the field.

Each of the next n lines contains m symbols: "." for empty cells, "*" for impassable cells.

Output

Print the answer as a matrix as described above. See the examples to precise the format of the output.

Sample test(s)
Input
3 3
*.*
.*.
*.*
Output
3.3
.5.
3.3
Input
4 5
**..*
..***
.*.*.
*.*.*
Output
46..3
..732
.6.4.
5.4.3
Note

In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner).

/*  problem:cf-616C           */
/*  author: dang              */
/*  date:   2016-1-24  16:26  */
/*  题目大意:
     
*/
/*  超时                       */
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <iostream>
using namespace std;
int n, m;
char maps[1005][1005];
int vis[10005][1005];
int ans;
struct node{
    int x, y;
    node(int a = 0, int b = 0):x(a),y(b){} // 需要默认值
};
//vis标记!
void dfs(int x, int y){
    ans ++; vis[x][y] = 1;
    if(vis[x+1][y]==0&&maps[x+1][y] == '.') dfs(x+1,y);
    if(vis[x][y+1]==0&&maps[x][y+1] == '.') dfs(x, y+1);
    if(vis[x-1][y]==0&&maps[x-1][y] == '.') dfs(x-1, y);
    if(vis[x][y-1]==0&&maps[x][y-1] == '.') dfs(x, y-1);
}


int main(){
    queue<node> q;
    node p;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++){
        scanf("%s", maps[i]);
        for(int j = 0; j < m ; j++){
            if(maps[i][j] == '*'){
                q.push(node(i, j));
            }
        }
    }
    while(!q.empty()){

       p = q.front();
       q.pop();
       ans = 0;
       memset(vis, 0, sizeof(vis));
       dfs(p.x, p.y);
//       printf("i:%d  j:%d  ans:%d\n",p.x, p.y , ans);
       maps[p.x][p.y]='0'+ans%10;
    }
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j++){
            printf("%c", maps[i][j]);
        }
        printf("\n");
    }
    return 0;
}

/*  problem:cf-616C           */
/*  author: dang              */
/*  date:   2016-1-25  10:20  */
/*
    染色法ac
*/


#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <iostream>
using namespace std;
int n, m;
char maps[1005][1005];
int vis[10005][1005];
int ans, a[1000005], b;
//vis标记!
void dfs(int x, int y, int k){
    vis[x][y] = k;    b++;
    if(vis[x+1][y]==0&&maps[x+1][y] == '.') dfs(x+1,y, k);
    if(vis[x][y+1]==0&&maps[x][y+1] == '.') dfs(x, y+1,k);
    if(vis[x-1][y]==0&&maps[x-1][y] == '.') dfs(x-1, y,k);
    if(vis[x][y-1]==0&&maps[x][y-1] == '.') dfs(x, y-1,k);
}


int main(){
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++){
        scanf("%s", maps[i]);
    }
    int k = 0;
    memset(vis, 0, sizeof(vis)); memset(a, 0, sizeof(a));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(maps[i][j]=='.'&&vis[i][j]==0){
                b = 0;
                dfs(i, j, ++k);
                a[k] = b;
            }
        }
    }
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            if(maps[i][j]=='*'){
                int x=1, x1=0, x2=0, x3=0, x4=0;
                if(i+1<n)  x1 = vis[i+1][j];
                if(j+1<m)  x2 = vis[i][j+1];
                if(i-1>=0) x3 = vis[i-1][j];
                if(j-1>=0) x4 = vis[i][j-1];
//                x += x1;
                x += a[x1];
                if(x1!= x2){
//                  x += x2;
                    x += a[x2];
                    if(x1!=x3&&x2!=x3) {
//                   x += x3;
                        x += a[x3];
                        if(x1!=x4&&x2!=x4&&x3!=x4)  x += a[x4];
                    }
                    else {
                        if(x1!=x4&&x2!=x4) x += a[x4];
                    }
                }
                else {
                    if(x1!=x3){
                        x += a[x3];
                        if(x1!=x4&&x3!=x4) x += a[x4];
                    }
                    else {
                        if(x1!=x4) x += a[x4];
                    }
                }
                maps[i][j] = '0' + x%10;
            }

        }
    }
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j++){
            printf("%c", maps[i][j]);
        }
        printf("\n");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值