【Codeforces Round #427】A(模拟) B (贪心) C (DP)
来源:互联网 发布:淘宝账号贷款真的假的 编辑:程序博客网 时间:2024/06/01 21:01
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”.
Example
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<bits/stdc++.h>using namespace std;#define LL long long#define fread() freopen("in.txt","r",stdin)#define fwrite() freopen("out.txt","w",stdout)#define CLOSE() ios_base::sync_with_stdio(false)const int MAXN = 1e5;const int MAXM = 1e6;const int mod = 1e9+7;const int inf = 0x3f3f3f3f; int main(){ CLOSE();// fread();// fwrite(); int s,v1,v2,t1,t2; cin>>s>>v1>>v2>>t1>>t2; int time1=t1*2+v1*s; int time2=t2*2+v2*s; if(time1<time2) puts("First"); else if(time1>time2) puts("Second"); else puts("Friendship"); 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.
Example
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.
分析之后 题目意思为
给个字符串n,和整数k。问至少修改字符串中的几位才可以让各个位之和大于等于k。
贪心就好。
#include<bits/stdc++.h>using namespace std;#define LL long long#define fread() freopen("in.txt","r",stdin)#define fwrite() freopen("out.txt","w",stdout)#define CLOSE() ios_base::sync_with_stdio(false)const int MAXN = 1e5+10;const int MAXM = 1e6;const int mod = 1e9+7;const int inf = 0x3f3f3f3f;char n[MAXN];int cnt[MAXN];int main(){ CLOSE();// fread();// fwrite(); int k; scanf("%d",&k); scanf("%s",n); int sum=0; for(int i=0;n[i];i++) { sum+=n[i]-'0'; cnt[n[i]-'0']++; } if(sum>=k) puts("0"); else { int ans=0; int cha=k-sum; // printf("%d\n",cha); for(int i=0;i<9;i++){ while(cnt[i]){ cha-=9-i; cnt[i]--; ans++; if(cha<=0) { printf("%d\n",ans); return 0; } } } } return 0;}
C
C题的题解链接
- 【Codeforces Round #427】A(模拟) B (贪心) C (DP)
- Codeforces Round #392 (Div. 2) A(水)B(水、模拟) C(数学) D(贪心)
- Codeforces Beta Round #2 A map B dp C 模拟退火
- Educational Codeforces Round 27 A B 暴力+贪心 C 贪心+排序
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟
- Codeforces Round #277 (Div. 2) A (水题)B(水题) C(贪心)
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 贪心、实数字符串"a.b"处理
- Codeforces Round #390 (Div. 2)(A,B,C(记忆化搜索),D(贪心,优先队列))
- Educational Codeforces Round 30(补题) A B略 C(贪心)
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
- Codeforces Round #427 (Div. 2) A B C D
- Codeforces Round #439 (Div. 2)(补题) A模拟+set B 数学 C dp or 杨辉三角组合数
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #2 A B C
- Codeforces Round #231 A,B,C
- Codeforces Round #278(Div2) A B C
- Codeforces Round #300 A B C
- Unity Shaderlab: Object Outlines
- WebView 使用漏洞
- Linux常用超强命令组合
- leetcode 176. Second Highest Salary
- 使用三阶贝塞尔曲线实现直播中点赞效果
- 【Codeforces Round #427】A(模拟) B (贪心) C (DP)
- 牛顿法与拟牛顿法学习笔记(四)BFGS 算法
- android 热更新 下载dex文件
- 格雷码转换
- some useful links and articles
- 运行库:I/O初始化之“文件”句柄管理
- 第1075期AI100_机器学习日报(2017-08-28)
- java编程思想一到六章学习
- 第1076期AI100_机器学习日报(2017-08-29)