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. SGU-169 Numbers(找规律)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=169 解题报告: P(n)定义为n的所有位数的乘积,例如P(1243)=1*2*3* ...

  2. 【分布式存储】GlusterFS failing to mount at boot with Ubuntu 14.04

    GlusterFS failing to mount at boot with Ubuntu 14.04   Previously I asked about mounting GlusterFS a ...

  3. Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. Notice The minimu ...

  4. Eclipse 一直提示 loading descriptor for 的解决方法(转)

    启动eclipse之后,进行相关操作时,弹出界面,提示:loading descriptor for xxx 解决方法: 在Eclipse左侧的Project Explorer 最右上角有一个小钮,鼠 ...

  5. 简单的2d图形变换--仿设变换AffineTransform

    在ios中常常遇到些小的动画效果,比如点击一个按钮后,按钮上的三角形图片就旋转了.这种简单的小动画,常常通过更改view的transform属性来实现.这个transform属性,就是一个仿射变化矩阵 ...

  6. iOS 中的Certificate,Provisioning Profile 等在code singing中用到的信息

    注册apple id 有1年多了,这些概念还是模模糊糊的,决定在这里总结一下. 请参阅官方文档 App Distribution Guide code singing的作用如下: Code signi ...

  7. Java中必须了解的常用类

    1.Java的包装类 基本数据类型我们都很熟悉,例如:int.float.double.boolean.char等,基本数据类型不具备对象的特征,不能调用方法,一般能实现的功能比较简单,为了让基本数据 ...

  8. Enum:Smallest Difference(POJ 2718)

    最小的差别 题目大意:输入一串数字,问你数字的组合方式,你可以随意用这些数字组合(无重复)来组合成一些整数(第一位不能为0),然后问你组合出来的整数的差最小是多少? 这一题可以用枚举的方法去做,这里我 ...

  9. js: this,call,apply,bind 总结

    对js中的一些基本的很重要的概念做一些总结,对进一步学习js很重. 一.this JavaScript 中的 this 总是指向一个对象,而具体指向那个对象是在运行时基于函数的执行环境动态绑定的,而非 ...

  10. HDU 5512 Pagodas (gcd)

    题目:传送门. 题意:t组数据,每组数据给定n,a,b,a!=b,在[1,n]的这些点中,每次选取a+b或a-b或b-a点,选取过的点在下次选取的时候可以当做ab来用继续选取,谁不能继续选取谁就输,问 ...