Codeforces Beta Round #2

2019-11-02 16:01:19来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

Codeforces Beta Round #2

Codeforces Beta Round #2   A. Winner   The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input

The first line contains an integer number n (1  ≤  n  ≤  1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.

Output

Print the name of the winner.

Examples input
3
mike 3
andrew 5
mike 2
output
andrew
input
3
andrew 3
andrew 2
mike 5
output
andrew
题意:大概意思就是给你一些人玩游戏的过程,问你游戏结束时,谁的总分最高,要注意的就是如果最后总分有一样的,那就是先得到最高分的人获胜。
代码奉上:
#include <bits/stdc++.h>
using namespace std;
string s[10002],a;
int n,i,o[100032],m=-0x3f3f3f,temp;
map<string,int>p,t;
main()
{
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        cin>>s[i]>>o[i];
        p[s[i]]+=o[i];
    }
    for(i=0; i<n; i++)
        if(p[s[i]]>m)
            m=p[s[i]];
    for(i=0; i<n; i++)
    {
        if((t[s[i]]+=o[i])>=m&&p[s[i]]>=m)
        {
            cout<<s[i]<<endl;
            break;
        }
    }
    return 0;
}
B. The least round way  

There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that

  • starts in the upper left cell of the matrix;
  • each following cell is to the right or down from the current cell;
  • the way ends in the bottom right cell.

Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.

Input

The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109).

Output

In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.

Examples input
3
1 2 3
4 5 6
7 8 9
output
0
DDRR

 题意:这个题就是给你一个n*n的矩阵,然后让你从左上角走到右下角,问走过的路线每个数都乘起来,然后找出结果中末尾0的个数最少的以及这条路线是如何走的,只能向右或向下。

代码如下:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int f[1001][1001][2],n,x,k;
char g[1001][1001][2];
void gao(int x,int y)
{
    if(x==1&&y==1)//如果是起点,返回
        return;
    if(g[x][y][k])//判断g的,1记录的向下,0记录的向右
        gao(x-1,y),putchar('D');
    else
        gao(x,y-1),putchar('R');
}
int main()
{
    scanf("%d",&n);
    memset(f,0,sizeof(f));
    for(int i=2; i<=n; ++i)
        f[0][i][0]=f[0][i][1]=f[i][0][0]=f[i][0][1]=inf;//让第一行的上一行和第一列的前一列
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=n; ++j)
        {
            scanf("%d",&k);
            if(!k)//当前值为零
                x=i;//标记一下,记录第几行存在0
            else
            {
                while(k%2==0)
                    ++f[i][j][0],k/=2;//如果当前位置的值为2的倍数,则记录进0中,存进数值除以2的值
                while(k%5==0)
                    ++f[i][j][1],k/=5;//如果当前数值是5的倍数,测记录进1中,存进数值除以5的值
            }
            for(int k=0; k<2; k++)//统计行进过程中2的倍数和5的倍数
            {
                if(g[i][j][k]=f[i-1][j][k]<f[i][j-1][k])//判断此行的上一行的2的倍数个数小于此列的上一列的2的倍数的个数,也就是当前位置的上一个位置,左边和上边,那个方向的2更少,g为一的时候,则是向下走
                    f[i][j][k]+=f[i-1][j][k];//则进行此位置加上上一行的2或5的倍数的个数,就把那个方向的数加上
                else//否则则是另一个方向,向右走的
                    f[i][j][k]+=f[i][j-1][k];//否则就是此位置加上上一列2或5的倍数的个数
            }
        }
    }
    k=f[n][n][1]<f[n][n][0];//最后一个位置的2和5个数那个比较多
    if(x&&f[n][n][k]>1)//说明前面至少有一对2和5,也就是至少有一个零,同时如果过程中有为零的,也就是x被标记过,那就是只存在一个零,相当于就一个10。
    {
        cout<<"1\n";//接下来就是输出过程中以x这个点为十字路口,前面一个方向,后面一个方向
        for(int i=2; i<=x; i++)
            putchar('D');
        for(int i=2; i<=n; i++)
            putchar('R');
        for(int i=x+1; i<=n; i++)
            putchar('D');
    }
    else
        printf("%d\n",f[n][n][k]),gao(n,n);//先输出最少的对数,因为一个是记数2的,一个是记数5的
    return 0;
}

 


原文链接:https://www.cnblogs.com/guttentag/p/11782765.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:详解并查集

下一篇:自定义日历(四)-区间选择控件