codeforces 354 DIV2

时间:2023-03-09 02:09:42
codeforces 354 DIV2

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:预处理前缀和,再二分区间长度