Codeforces Round #427 (Div. 2) A—D题
来源:互联网 发布:手机qq聊天监控软件 编辑:程序博客网 时间:2024/06/14 07:00
传送门:点击打开链接
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:
- 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.
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.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
5 1 2 1 2
First
3 3 1 1 1
Second
4 5 3 1 5
Friendship
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.
#include<iostream>#include<algorithm>using namespace std;int main(){long long s,v1,v2,t1,t2,sum1,sum2;while(cin>>s>>v1>>v2>>t1>>t2){sum1=s*v1+2*t1;sum2=s*v2+2*t2;if(sum1<sum2)cout<<"First"<<endl;else if(sum1>sum2)cout<<"Second"<<endl;elsecout<<"Friendship"<<endl;}return 0;}
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.
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.
Print the minimum number of digits in which the initial number and n can differ.
311
1
399
0
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.
#include<iostream>#include<algorithm>#include<cstring>using namespace std;int main(){char map[1000005];int k,i;while(cin>>k){memset(map,'\0',sizeof(map));cin>>map;int len=strlen(map);long long ans=0;for(i=0;i<len;i++)ans+=map[i]-'0';if(ans>k){cout<<"0"<<endl;continue;}sort(map,map+len);int count=0;i=0;while(ans<k){ans+=9-(map[i]-'0');count++;i++;}cout<<count<<endl;}return 0;}
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), 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 (x1i, y1i) and the upper right — (x2i, y2i). 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.
The first line contains three integers n, q, c (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 xi, yi, si (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 ti, x1i, y1i, x2i, y2i (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.
For each view print the total brightness of the viewed stars.
2 3 31 1 13 2 02 1 1 2 20 2 1 4 55 1 1 5 5
303
3 4 51 1 22 3 03 3 10 1 1 100 1001 2 2 4 42 2 1 4 71 50 50 51 51
3350
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<iostream>#include<algorithm>#include<cstring>using namespace std;int main(){int dp[105][105][20],i,j,k,n,q,c,x,y,s,t,x1,y1,x2,y2;while(cin>>n>>q>>c){memset(dp,0,sizeof(dp)); //清空数组 for(i=0;i<n;i++){cin>>x>>y>>s;dp[x][y][s]++; //当前数加1 }for(i=1;i<105;i++){for(j=1;j<105;j++){for(k=0;k<=15;k++){dp[i][j][k]+=dp[i-1][j][k]+dp[i][j-1][k]-dp[i-1][j-1][k]; //前面两个的亮度和减去重合部分,容斥 }}}while(q--){cin>>t>>x1>>y1>>x2>>y2;long long ans=0;for(i=0;i<=c;i++){int light=(i+t)%(c+1); //时间为t时,灯光的亮度。 ans+=light*(dp[x2][y2][i]-dp[x2][y1-1][i]-dp[x1-1][y2][i]+dp[x1-1][y1-1][i]);}cout<<ans<<endl;}}return 0;}
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:
- Its left half equals to its right half.
- 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.
The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.
Print |s| integers — palindromic characteristics of string s.
abba
6 1 0 0
abacaba
12 4 1 0 0 0 0
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.
看note应该能读懂题意。
看到大神的做法是dp思想,dp【i】【j】表示字符串长度为j时,包括的i阶的字符串个数。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<cstdio> using namespace std;int dp[5005][5005];int main(){char map[5005];int ans[5005],i,j,k;while(~scanf("%s",map+1)){memset(dp,0,sizeof(dp));memset(ans,0,sizeof(ans));int len=strlen(map+1);for(i=1;i<=len;i++){dp[i][i]=1;ans[1]++;if(i<len&&map[i]==map[i+1]){ans[2]++;ans[1]++;dp[i][i+1]=2;}}for(i=3;i<=len;i++){for(j=1;j+i-1<=len;j++){if(dp[j+1][j+i-2]&&map[j]==map[i+j-1]) { dp[j][j+i-1]=dp[j][j+i/2-1]+1; for(k=1;k<=dp[j][j+i-1];k++)ans[k]++; }}}cout<<ans[1];for(i=2;i<=len;i++)cout<<' '<<ans[i];cout<<endl;}return 0;}
- Codeforces Round #427 (Div. 2) A—D题
- Codeforces Round #209 (Div. 2) <A-D>
- Codeforces Round #231 (Div. 2)A-D
- Codeforces Round #235 (Div. 2) A~D
- Codeforces Round #237 (Div. 2) A~D
- Codeforces Round #240 (Div. 2) A~D
- Codeforces Round #239 (Div. 2) A~D
- Codeforces Round #242 (Div. 2) <A-D>
- Codeforces Round #250 (Div. 2) A-D
- Codeforces Round #256 (Div. 2)A-D
- Codeforces Round #263 (Div. 2) A-D
- Codeforces Round #269 (Div. 2) A~D
- Codeforces Round #358 (Div. 2)A~D
- Codeforces Round #359 (Div. 2) A ~D
- Codeforces Round #364 (Div. 2)(A ~ D)
- Codeforces Round #368 (Div. 2) A~D
- Codeforces Round #369 (Div. 2) A~D
- Codeforces Round #369 (Div. 2) A~D
- 关于APP卡顿。在编写代码时需要注意的事情。
- 【每日一题-17】线索化二叉树与单例模式
- 设计模式2-工厂方法模式
- 【caffe源代码的梳理之一】数据结构Blob
- 二叉树各种遍历
- Codeforces Round #427 (Div. 2) A—D题
- Pandas入门学习总结
- 选项菜单与内容联动
- 使用js下载pdf文件
- 4、双向链表
- Python基础(2)——Python选择、循环结构
- Jmeter的分布式测试
- 自己的git简单拉与推的操作
- exit() _exit() pthread_exit()