B - Pyramid of Glasses

n层杯子,问k分钟能流满多少个杯子?和到香槟一样的过程?

思路:应为水的流速为每分钟一立方体(YY),可以做个转化,把最上层的杯子最原始的容积看成K,每个杯子的满的状态为体积为1,那么只要判断所有杯子体积是否大于1就可以。

 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
typedef long long LL;
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
const LL MOD = 1e9+;
// const LL p = 1e9+7;
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
double v[][]; int main(){
int n;
double t;
scanf("%d%lf",&n,&t);
clc(v,0.0);
v[][]=t;
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
if(v[i][j]>=){
v[i+][j]+=(v[i][j]-)/;
v[i+][j+]+=(v[i][j]-)/;
ans++;
}
}
}
printf("%d\n",ans);
return ;
}

C - Vasya and String

有一个长度为n的字符串,你可以改变最多k次,问你最长的全是一样字符的串是多长,这个字符串只含有a和b字符

两种解法:都要设置两个指针枚举符合的区间长度

1:首先改变的字符一定要“相邻”,枚举改变了的个数,保持枚举的区间范围内都含有k个改变值

 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
const LL MOD = 1e9+;
// const LL p = 1e9+7;
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
int n,k;
char s[];
int work(char c){
int l,len;
int ans;
ans=;
l=len=;
for(int r=;r<n;r++){
if(s[r]==c)
len++;
while(len>k){
if(s[l]==c)
len--;
l++;
}
ans=max(ans,r-l+);
}
return ans;
} int main(){ scanf("%d%d",&n,&k);
cin>>s;
int ans1=work('a');
int ans2=work('b');
printf("%d\n",max(ans1,ans2));
return ;
}

2:预处理前缀和,再二分区间长度

codeforces 354 DIV2的更多相关文章

  1. codeforces 354 div2 C Vasya and String 前缀和

    C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  3. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  4. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  5. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  6. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  7. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

随机推荐

  1. The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemE:Easy Task

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2969 全场第一水题.我不知道怎么解释,看代码就好了... #include ...

  2. 通过web代理进行跨域访问,http请求返回超时的问题定位

    [现象] 在ajax通过web代理跨域访问时,http第一次登陆时正常,但是第二次再下发其他命令的时候总是返回 java.net.SocketTimeoutException: Read timed ...

  3. Git教程之分支管理之二

    分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息.如果要强制禁用Fast forward模式,Git就会在merge时生成一个 ...

  4. POJ1573——Robot Motion

    Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...

  5. svn的merge使用例子

    先说说什么是branch.按照Subversion的说法,一个branch是某个development line(通常是主线也即trunk)的一个拷贝,见下图: branch存在的意义在于,在不干扰t ...

  6. caffe简易上手指南(二)—— 训练我们自己的数据

    训练我们自己的数据 本篇继续之前的教程,下面我们尝试使用别人定义好的网络,来训练我们自己的网络. 1.准备数据 首先很重要的一点,我们需要准备若干种不同类型的图片进行分类.这里我选择从ImageNet ...

  7. tcp断开的4次挥手

    http://blog.csdn.net/fw0124/article/details/7452695 由于TCP连 接是全双工的,因此每个方向都必须单独进行关闭.这原则是当一方完成它的数据发送任务后 ...

  8. notepad++ 编辑器链接地址可点击

    很久没用notepad++编辑器,最近因为 sublime 的编码问题,因此用了下 notepad++ .结果发现里面的链接都可以点击,一点都不要编辑,如下图: 那如何把这个功能去掉呢? 我们选择 菜 ...

  9. 宏FSP_SEG_INODES_PER_PAGE

    #define FSP_SEG_INODES_PER_PAGE(zip_size) \ (((zip_size ? zip_size : UNIV_PAGE_SIZE) \ - FSEG_ARR_OF ...

  10. Java [Leetcode 226]Invert Binary Tree

    题目描述: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 解题思路: 我只想说递归大法好. ...