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的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  5. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  6. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  7. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  8. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

  9. Codeforces Round #360 div2

    Problem_A(CodeForces 688A): 题意: 有d天, n个人.如果这n个人同时出现, 那么你就赢不了他们所有的人, 除此之外, 你可以赢他们所有到场的人. 到场人数为0也算赢. 现 ...

随机推荐

  1. [POJ1338]Ugly Numbers

    [POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...

  2. MYSQL注入天书之HTTP头部介绍

    Background-5 HTTP头部介绍 在利用抓包工具进行抓包的时候,我们能看到很多的项,下面详细讲解每一项. HTTP头部详解 1. Accept:告诉WEB服务器自己接受什么介质类型,*/* ...

  3. HDOJ 2066 floyed优化算法

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. encode与decode,unicode与中文乱码的问题

    encode是指将unicode字符编码成其他字符集的字符,如utf-8,ascii等: 而decode是指将其他字符编码,如utf-8转换成unicode编码. encode是指将人类用的语言(字符 ...

  5. hdparm测试硬盘性能

    <1>Centos安装hdparm测试硬盘性能 一.安装hdparm yum install hdparm -y Linux学习,http:// linux.it.net.cn 二.评估读 ...

  6. 【SpringMVC】SpringMVC系列1之HelloWorld

    SpringMVC之HelloWorld 概述 SpringMVC 是基于 MVC 设计理念的优秀Web 框架,是目前最主流的 MVC 框架之一.Spring3.0 后全面超越 Struts2,成为最 ...

  7. 2013 ACM/ICPC 长春网络赛F题

    题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...

  8. Android clickable 和 focusable

    setClickable(),好像是控制按钮是否可以被点击和点击之后触发监听器事件.setFocusable();控制键盘是否可以获得这个按钮的焦点.(我按实体键盘上方向键,button被选中) 今天 ...

  9. [Android Pro] 通过IMSI判断手机是移动、联通、电信

    TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); /** 获取 ...

  10. 组合数(codevs 1631)

    1631 组合数  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 组合数C(N, K)表示 ...