Codeforces Beta Round #2

A - Winner

CodeForces-2A

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

因为用了一个end变量名,应该是和namespace std里的起了冲突,一直编译错误,后来改成了End就通过了。
改编自下面大佬的代码

#include <iostream>
#include <string>
#include <map>
using namespace std;

map <string, int> End, process;//最终的分数,过程的分数 
string arr[1005];//每次的人 
int arr2[1005];//每次的分数 

int main(void)
{
	int n, cnt;
	cin >> n;
	for (int i = 0; i < n; i++) 
	{
		cin >> arr[i] >> arr2[i];
		End[arr[i]] += arr2[i]; 
	}
	int max = 0;//最大的分数 
	for (int i = 0; i < n; i++)
	{
		if (End[arr[i]] > max)
			max = End[arr[i]];
	}
	for (int i = 0; i < n; i++)
	{
		process[arr[i]] += arr2[i];
		if (End[arr[i]] == max && process[arr[i]] >= max)
		{
			cout << arr[i] << endl;
			break;
		}
	}
	return 0;
}

一份良心题解:https://blog.csdn.net/u012860063/article/details/40512245

B - The least round way

CodeForces - 2B

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 10^9).

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

不出现0的话,就直接输出结果0最少的路径。
如果出现0的话,以后就结果就只能是0,把0当作10。如果存在结果没有0的路径,就输出,如果不存在,那么就直接输出出现0的路径。
改编自下面大佬的代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int N = 1005, INF = 0x3f3f3f3f;

int path[N][N][2];
int dp[N][N][2], a[N][N][2];
int zerox, zeroy, x;
string s;
bool flag;

int main(void)
{
	int n;
    scanf("%d", &n);
    flag = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            scanf("%d", &x);
            if (!x)
            { 
                a[i][j][0] = a[i][j][1] = 1;
                zerox = i, zeroy = j, flag = 1;
            }
            else//统计2和5的个数 
            {
                while(x % 2 == 0) {a[i][j][0]++; x /= 2;}
                while(x % 5 == 0) {a[i][j][1]++; x /= 5;}
            }
        }
    for (int k = 0; k < 2; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                int ans = INF;
                if (i == 0 && j == 0) 
					ans = 0;
                if (i != 0 && dp[i - 1][j][k] < ans)//从上面转移过来 
					ans = dp[i - 1][j][k];
                if (j != 0 && dp[i][j - 1][k] < ans)//从左边转移过来 
					ans = dp[i][j - 1][k], path[i][j][k] = 1;
                dp[i][j][k] = ans + a[i][j][k];
            }
    int k = dp[n - 1][n - 1][0] < dp[n - 1][n - 1][1] ? 0 : 1;//记录的是0的个数 
    //转移的过程出现0且最少的0数大于1 
	if (flag && dp[n - 1][n - 1][k] > 1)
    {
    	for (int i = 0; i < zeroy; i++)
            s += "R";
        for (int i = 0; i < zerox; i++)
            s += "D";
        for (int i = 0; i < n - zeroy - 1; i++)
            s += "R";
        for (int i = 0; i < n - zerox - 1; i++)
            s += "D";
        cout << 1 << endl << s << endl;
    }
    //没有出现0   
    else
	{
        int i = n - 1, j = n - 1;
        while (i > 0 || j > 0)
        {
            if (path[i][j][k] == 1)
                s += "R", j--;
            else
                s += "D", i--;
        }
    	reverse(s.begin(), s.end());
        cout << dp[n - 1][n - 1][k] << endl << s << endl;
    }
    return 0;
}

题解:
https://blog.csdn.net/lin375691011/article/details/40679137
https://blog.csdn.net/intelligentgirl/article/details/81875334

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值