CodeForces Round 193 Div2
I know,this is another failure.It seems like that failure is a habit with me.This time I solved two problems like last time,with a rank of 800+.
A. Down the Hatch!
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All n people who came to the barbecue sat in a circle (thus each person received a unique index bi from 0 to n-1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the j-th turn was made by the person with index bi, then this person acted like that:
he pointed at the person with index (bi+1) mod n either with an elbow or with a nod (x mod y is the remainder after dividing x by y);
if j≥4 and the players who had turns number j-1, j-2, j-3, made during their turns the same moves as player bi on the current turn, then he had drunk a glass of juice;
the turn went to person number (bi+1) mod n.
The person who was pointed on the last turn did not make any actions.
The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody.
Input
The first line contains a single integer n (4≤n≤2000) — the number of participants in the game. The second line describes the actual game: the i-th character of this line equals 'a', if the participant who moved i-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns.
Output
Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well.
Sample test(s)
Input
4
abbba
Output
1
Input
4
abbab
Output
0
Note
In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different.
This question is very simpily.We can just enumerate all the turns for Vasya and check if it meet the conidition.
#include<stdio.h>
#include<string.h>
int N;
char ch[2025];
bool judge(int x)
{
if (x<3) return false;
if (ch[x-1]==ch[x-2] && ch[x-2]==ch[x-3]) return true;
if (N==1) return true;
if (N==2 && ch[x-1]==ch[x-3]) return true;
if (N==3 && ch[x-1]==ch[x-2]) return true;
return false;
}
int main()
{
int i,Max=0;
scanf("%d",&N);
scanf("%s",ch);
for (i=N;i<strlen(ch);i+=N)
if (judge(i)) Max++;
printf("%d\n",Max);
return 0;
}
B. Maximum Absurdity
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1≤a≤b≤n-k+1,b-a≥k) and sign all laws with numbers lying in the segments [a; a+k-1] and [b; b+k-1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2≤n≤2·105, 0<2k≤n) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1,x2,...,xn — the absurdity of each law (1≤xi≤109).
Output
Print two integers a, b — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a+k-1] and [b; b+k-1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Sample test(s)
Input
5 23 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3+6+1+6=16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1+1+1+1=4.
Still easy.s[i] means the sum of the value from law i to law i+k-1.f[i] means the maximum value of s[j] between i and N.
#include<stdio.h>
#include<string.h>
__int64 w[200025],s[200025],f[200025];
int main()
{
int N,K,i;
scanf("%d%d",&N,&K);
for (i=1;i<=N;i++) scanf("%I64d",&w[i]);
s[1]=0;
for (i=1;i<=K;i++) s[1]+=w[i];
for (i=2;i+K-1<=N;i++) s[i]=s[i-1]-w[i-1]+w[i+K-1];
f[N-K+1]=s[N-K+1];
for (i=N-K;i>=1;i--)
if (s[i]>f[i+1]) f[i]=s[i];
else f[i]=f[i+1];
__int64 Max=0,tmp;
int a,b;
for (i=1;i+2*K-1<=N;i++)
if (s[i]+f[i+K]>Max) Max=s[i]+f[i+K];
for (i=1;i+2*K-1<=N;i++)
if (s[i]+f[i+K]==Max)
{
a=i;
Max-=s[i];
break;
}
for (i=a+K;i+K-1<=N;i++)
if (s[i]==Max)
{
b=i;
break;
}
printf("%d %d\n",a,b);
return 0;
}
CodeForces Round 193 Div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- Codeforces Round #360 div2
Problem_A(CodeForces 688A): 题意: 有d天, n个人.如果这n个人同时出现, 那么你就赢不了他们所有的人, 除此之外, 你可以赢他们所有到场的人. 到场人数为0也算赢. 现 ...
随机推荐
- windows下的文件到linux下乱码 iconv 修改文件编码
conv [选项...] [文件...] 有如下选项可用: 输入/输出格式规范:-f, --from-code=名称 原始文本编码-t, --to-code=名称 输出编码 信息:-l, --list ...
- 一起做RGB-D SLAM (1)
前言 2016.11 更新 增加了对16.04的支持. 整理了过时的代码. SLAM,即Simultaneous Localization and Mapping,中文译作同时定位与地图创建,是近几十 ...
- PE刷题记录
PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...
- 组合数学or not ---- n选k有重
模板问题: 1. 取物品 (comb.pas/c/cpp) [问题描述] 现在有n个物品(有可能相同),请您编程计算从中取k个有多少种不同的取法.[输入] 输入文件有两行,第一行包含两个整数n,k(2 ...
- linux下proc里关于磁盘性能的参数
我 们在磁盘写操作持续繁忙的服务器上曾经碰到一个特殊的性能问题.每隔 30 秒,服务器就会遇到磁盘写活动高峰,导致请求处理延迟非常大(超过3秒).后来上网查了一下资料,通过调整内核参数,将写活动的高峰 ...
- Java for LeetCode 169 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- elk平台分析nginx日志的基本搭建
一.elk套件介绍 ELK 由 ElasticSearch . Logstash 和 Kiabana 三个开源工具组成.官方网站: https://www.elastic.co/products El ...
- ext树表+ZeroClipboard复制链接功能
效果图:
- ubuntu下设置Android手机驱动
如果下面的文章不好使,建议读一这个文章:http://forum.xda-developers.com/xperia-u/general/howto-usb-connection-to-ubuntu- ...
- mysql 建表语句
修改id为自动增长: alter table book b_ISBN int(11) auto_increment; 自动增长要加的:auto_increment 基本的sql语句: 选择:sel ...