codeforces 354 DIV2
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 ;
}
有一个长度为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的更多相关文章
- 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 ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
随机推荐
- httpmime-session 会话保持
sesion在浏览器和web服务器直接是通过一个叫做name为sessionid的cookie来传递的,所以只要在每次数据请求时保持sessionid是同一个不变就可以用到web的session了,做 ...
- Extjs4.2——Panel
一.Panel的border属性: 示例: Ext.create('Ext.panel.Panel', { title: 'Hello', width: 200, height:100, border ...
- Mybatis 示例之 SelectKey(转)
参考:http://blog.csdn.net/isea533/article/details/21153791 SelectKey在Mybatis中是为了解决Insert数据时不支持主键自动生成的问 ...
- js key事件 keyCode大全
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 ...
- 关于hibernate中双向外键关联one-to-one的property-ref=的问题(转)
大家都知道hibernate中的one-to-one映射主要有两种策略,(1)一对一主键关联(单向和双向).(2)一对一外键映射(单项和双向).本文主要讲解一下,一对一外键映射中的双向问题,在此前先通 ...
- android 在一个scrollView里面嵌套一个需要滑动的控件(listView、gridView)
package cn.via.dageeeOrderFood.widget; import android.content.Context; import android.graphics.Point ...
- linux 配置java环境变量
修改/etc/profile文件 如果你的计算机仅仅作为开发使用时推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,可能会给系统带来安全性问题. ·用文本编辑器打开/etc/profi ...
- IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set
在file-setting里面,找到maven的设置: 先加入一个环境变量 然后配置一个JVM的参数: -Dmaven.multiModuleProjectDirectory=$M2_HOME OK ...
- (原创)CityEngine 2014和ArcGIS 10.3冲突问题的解决
先卸载ArcGIS License Manager 10.3 安装ArcGIS License Manager 10.2.2 用keygen算出ArcGIS 10.3的许可,似乎本许可在ArcGI ...
- C#.Net 如何动态加载与卸载程序集(.dll或者.exe)1----C#中动态加载和卸载DLL
我们知道在C++中加载和卸载DLL是一件很容易的事,LoadLibrary和FreeLibrary让你能够轻易的在程序中加载DLL,然后在任何地方卸载. 在C#中我们也能使用Assembly.Load ...