Codeforces Round #427 (Div. 2)

本文介绍了Codeforces Round #427 (Div. 2)中的两道编程题目:A题Key Races涉及到两个选手的文字输入比赛,通过计算各自的完成时间和延迟来判断胜负;B题The Number on the Board要求找出改变数字使其数字和大于给定值k的最少操作次数。文章提供了题意解析和解题策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Key races
题目链接
Two boys decided to compete in text typing on the site “Key races”. During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.

If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:

Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
Right after that he starts to type it.
Exactly t milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.

Given the length of the text and the information about participants, determine the result of the game.

Input
The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.

Output
If the first participant wins, print “First”. If the second participant wins, print “Second”. In case of a draw print “Friendship”.

Examples
input
5 1 2 1 2
output
First
input
3 3 1 1 1
output
Second
input
4 5 3 1 5
output
Friendship
Note
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.

In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.

In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
const int MM=1e3+5;
int t;
int s,v1,v2,t1,t2;
int main()
{
    scanf("%d %d %d %d %d",&s,&v1,&v2,&t1,&t2);
    int sum1=t1+s*v1+t1;
    int sum2=t2+s*v2+t2;
    if(sum1==sum2)
        printf("Friendship\n");
    else if(sum1<sum2)
        printf("First\n");
    else if(sum1>sum2)
        printf("Second\n");
    return 0;
}

B. The number on the board
题目链接
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It’s known that the length of the number didn’t change.

You have to find the minimum number of digits in which these two numbers can differ.

Input
The first line contains integer k (1 ≤ k ≤ 109).
The second line contains integer n (1 ≤ n < 10100000).
There are no leading zeros in n. It’s guaranteed that this situation is possible.

Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
input
3
11
output
1
input
3
99
output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

**题意:**先给k一个常数;再给一个常数n,问题是算出n的位数的和sum 然后与k的值进行比较,如果小于k则需要改变n的位数的值 问你需要改多少次可以使得sum 大于k;
**解题思路:**很简单先把所以的位数求出,再贪心,贪心的策略是每一次改变位数我都用最大的(即9 来所以位数的最小的值,那么我就能用最少的次数使得sum大于k了;

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define ll long long
using namespace std;
const int MM=1e6+5;
int t;
char s[MM];
ll a[MM];
ll sum=0;
int main()
{
    scanf("%d",&t);
    getchar();
    scanf("%s",s);//数据很大用字符数组存
    int len=strlen(s);
    int l=0;
    for(int i=0;i<len;i++)
    {
        a[l++]=s[i]-'0';//记录每一个位数的值
        sum+=s[i]-'0';//位数之和;
    }
    sort(a,a+l);//排序一下
    if(sum<t)
    {
        int k=0;
        while(sum<t)
        {
            sum+=9;//贪心
            sum-=a[k];
            k++;
        }
        printf("%d\n",k);
    }
    else
        printf("0\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值