博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #427 (Div. 2)
阅读量:6037 次
发布时间:2019-06-20

本文共 8316 字,大约阅读时间需要 27 分钟。

B. The number on the board
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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的关系,问你要改几位,改成9就好了啊

#include 
using namespace std;char s[100005];int main() { int k; scanf("%d",&k); scanf("%s",s); sort(s,s+strlen(s)); int i=0,sum=0; for(int i=0;s[i];i++) sum+=s[i]-'0'; while(sum
A. Key races
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of scharacters. 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:

  1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
  2. Right after that he starts to type it.
  3. 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 sv1, 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 14milliseconds. 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 5milliseconds. 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 22milliseconds. So, it is be a draw.

 

 

水题+1

#include
using namespace std;typedef long long ll;int main() { ll s,v1,v2,t1,t2; cin>>s>>v1>>v2>>t1>>t2; ll q1=2*t1+s*v1; ll q2=2*t2+s*v2; if(q1
q2) cout<<"Second"; else cout<<"Friendship"; return 0;}

 

C. Star sky
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xiyi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).

Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and 0, otherwise.

You want to look at the sky q times. In the i-th time you will look at the moment ti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1iy1i) and the upper right — (x2iy2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.

A star lies in a rectangle if it lies on its border or lies strictly inside it.

Input

The first line contains three integers nqc (1 ≤ n, q ≤ 105, 1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.

The next n lines contain the stars description. The i-th from these lines contains three integers xiyisi (1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ c ≤ 10) — the coordinates of i-th star and its initial brightness.

The next q lines contain the views description. The i-th from these lines contains five integers tix1iy1ix2iy2i (0 ≤ ti ≤ 109, 1 ≤ x1i < x2i ≤ 100, 1 ≤ y1i < y2i ≤ 100) — the moment of the i-th view and the coordinates of the viewed rectangle.

Output

For each view print the total brightness of the viewed stars.

Examples
input
2 3 3 1 1 1 3 2 0 2 1 1 2 2 0 2 1 4 5 5 1 1 5 5
output
3 0 3
input
3 4 5 1 1 2 2 3 0 3 3 1 0 1 1 100 100 1 2 2 4 4 2 2 1 4 7 1 50 50 51 51
output
3 3 5 0
Note

Let's consider the first example.

At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.

At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.

At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.

 

 暴力前缀和的,就是这个星星是会重复的

#include 
using namespace std;typedef long long ll;const int N=105;int a[N][N][12];int main() { int n,q,c; scanf("%d%d%d",&n,&q,&c); memset(a,0,sizeof(a)); int x,y,xx,yy,t,k; for(int i=0; i

 

D. Palindromic characteristics
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.

A string is 1-palindrome if and only if it reads the same backward as forward.

A string is k-palindrome (k > 1) if and only if:

  1. Its left half equals to its right half.
  2. Its left and right halfs are non-empty (k - 1)-palindromes.

The left half of string t is its prefix of length ⌊|t| / 2⌋, and right half — the suffix of the same length. ⌊|t| / 2⌋ denotes the length of string tdivided by 2, rounded down.

Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.

Input

The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.

Output

Print |s| integers — palindromic characteristics of string s.

Examples
input
abba
output
6 1 0 0
input
abacaba
output
12 4 1 0 0 0 0
Note

In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.

k是,那么k-1也是,预处理(好复杂的预处理)

#include
using namespace std;const int N=5005;string str;int dp[N][N];bool p[N][N];bool seen[N][N];int c[N];int n;bool palindrome(int l,int r) { if(l==r) return p[l][r]=1; if(l+1==r)return p[l][r]=(str[l]==str[r]); if(seen[l][r]) return p[l][r]; seen[l][r]=1; if(str[l]==str[r]) return p[l][r]=palindrome(l+1,r-1); return p[l][r]=0;}int solve(int l,int r) { if(l==r) return dp[l][r]=1; if(dp[l][r]!=-1)return dp[l][r]; if(palindrome(l,r)) { int m=(l+r)/2; return dp[l][r]=1+solve(m+1,r); } return dp[l][r]=0;}int main() { ios::sync_with_stdio(0); cin>>str; n=(int)str.size(); memset(dp,-1,sizeof(dp)); for(int i=0; i
=1; i--) c[i]+=c[i+1]; for(int i=1; i

 

 

转载于:https://www.cnblogs.com/BobHuang/p/7266951.html

你可能感兴趣的文章
模式识别(第四版)上机实验 【2.2~2.5】
查看>>
ACM-ICPC 2018 焦作赛区网络预赛 A Magic Mirror(签到)
查看>>
iOS 7 新特性:视图控制器切换API
查看>>
pyspider爬取数据导入mysql--1.安装驱动
查看>>
2)队列
查看>>
vc枚举本机端口信息
查看>>
MySQL Profiling 的使用
查看>>
internet笔记
查看>>
【CSS】之hack
查看>>
C# 后台获取前台交互判断
查看>>
适合办公室里做的拉腿运动
查看>>
[Azure][PowerShell][ASM][06]VM Linux
查看>>
今天总算弄明白了JsonResult怎么跟数据库数据进行交互
查看>>
[NOI2005]月下柠檬树[计算几何(simpson)]
查看>>
1164 统计数字
查看>>
时间处理的一些代码片段
查看>>
SQL Server编程(06)触发器
查看>>
vue.js学习 自定义过滤器使用(1)
查看>>
Select Year,Month,Day date from DropDownList control in ASP.NET
查看>>
微软职位内部推荐-SDEII for Windows Phone Apps
查看>>