zoukankan      html  css  js  c++  java
  • codeforces 354 DIV2

    B - Pyramid of Glasses

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

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

     1 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <iostream>
     6 #include <queue>
     7 #include <stack>
     8 #include <cmath>
     9 #include <set>
    10 #include <algorithm>
    11 #include <vector>
    12 // #include<malloc.h>
    13 using namespace std;
    14 #define clc(a,b) memset(a,b,sizeof(a))
    15 typedef long long LL;
    16 const int inf = 0x3f3f3f3f;
    17 const double eps = 1e-5;
    18 const double pi = acos(-1);
    19 const LL MOD = 1e9+7;
    20 // const LL p = 1e9+7;
    21 // inline int r(){
    22 //     int x=0,f=1;char ch=getchar();
    23 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
    24 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    25 //     return x*f;
    26 // }
    27 double v[15][15];
    28 
    29 int main(){
    30     int n;
    31     double t;
    32     scanf("%d%lf",&n,&t);
    33     clc(v,0.0);
    34     v[1][1]=t;
    35     int ans=0;
    36     for(int i=1;i<=n;i++){
    37         for(int j=1;j<=i;j++){
    38             if(v[i][j]>=1){
    39                 v[i+1][j]+=(v[i][j]-1)/2;
    40                 v[i+1][j+1]+=(v[i][j]-1)/2;
    41                 ans++;
    42             }
    43         }
    44     }
    45     printf("%d
    ",ans);
    46     return 0;
    47 }

    C - Vasya and String

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

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

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

     1 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <iostream>
     6 #include <queue>
     7 #include <stack>
     8 #include <cmath>
     9 #include <set>
    10 #include <algorithm>
    11 #include <vector>
    12 // #include<malloc.h>
    13 using namespace std;
    14 #define clc(a,b) memset(a,b,sizeof(a))
    15 #define LL long long
    16 const int inf = 0x3f3f3f3f;
    17 const double eps = 1e-5;
    18 const double pi = acos(-1);
    19 const LL MOD = 1e9+7;
    20 // const LL p = 1e9+7;
    21 // inline int r(){
    22 //     int x=0,f=1;char ch=getchar();
    23 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
    24 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    25 //     return x*f;
    26 // }
    27 int n,k;
    28 char s[100010];
    29 int work(char c){
    30     int l,len;
    31     int ans;
    32     ans=0;
    33     l=len=0;
    34     for(int r=0;r<n;r++){
    35        if(s[r]==c)
    36           len++;
    37         while(len>k){
    38             if(s[l]==c)
    39                len--;
    40             l++;
    41         }       
    42         ans=max(ans,r-l+1);
    43     }
    44     return ans;
    45 }
    46 
    47 
    48 int main(){
    49     
    50     scanf("%d%d",&n,&k);
    51     cin>>s;
    52     int ans1=work('a');
    53     int ans2=work('b');
    54     printf("%d
    ",max(ans1,ans2));
    55     return 0;
    56 }

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

  • 相关阅读:
    linux JAVA JDK环境配置
    逍遥语录
    php常用函数集
    使用uGUI系统玩转标准俄罗斯方块
    Unity3D中uGUI事件系统简述及使用方法总结
    JAVA笔记-如何将百万级数据高效的导出到Excel表单
    简单的异步Socket实现——SimpleSocket_V1.1
    Netty4.x中文教程系列(六) 从头开始Bootstrap
    Unity3D中简单的C#异步Socket实现
    基于Spring框架的简单多数据源切换解决办法
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5532788.html
Copyright © 2011-2022 走看看