zoukankan      html  css  js  c++  java
  • ZeptoLab Code Rush 2015

    A

    题意:给出一串由.*组成的字符串,如果有等间距的五个及五个以上的*存在,则输出yes

    直接枚举就可以了

    看题一定要仔细啊,做的时候看成必须有五个等间距的".*"才可以跳跃= =

    然后就这样写居然过了预测= =后来果然被hack了

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 #define mod=1e9+7;
    12 using namespace std;
    13 
    14 typedef long long LL;
    15 const int INF = 0x7fffffff;
    16 
    17 int main(){
    18     char s[10005];
    19     int n,i,j;
    20     scanf("%d",&n);
    21     scanf("%s",s);
    22     for(i=0;i<n;i++){
    23         for(j=1;j<n;j++){
    24             if(s[i]=='*'&&s[i+j]=='*'&&s[i+2*j]=='*'&&s[i+3*j]=='*'&&s[i+4*j]=='*'){
    25                 printf("yes
    ");
    26                 return 0;
    27             }
    28         }
    29     }
    30     printf("no
    ");
    31     return 0;
    32 }
    View Code

    B

    题意:如图所示,需要从根节点到最下面一层得叶子节点的灯的数量相等,问最少需要添加多少盏灯

    因为需要每一条支路的灯的数量相等,所以从最下面一层开始处理((因为到分叉之前的灯都是共用的),不同的话加灯,相同的话继续往上一层处理

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 #define mod=1e9+7;
    12 using namespace std;
    13 
    14 typedef long long LL;
    15 const int INF = 0x7fffffff;
    16 int a[10005];
    17 
    18 int mi(int x){
    19     int ans=1;
    20     for(int i=1;i<=x;i++) ans*=2;
    21     return ans;
    22 }
    23 
    24 int main(){
    25    int n,i,j,ans,k;
    26    cin>>n;
    27    int idx=mi(n+1)-1;
    28    for(i=2;i<=idx;i++) scanf("%d",&a[i]);
    29    
    30    ans=0;
    31    for(i=n;i>=1;i--){
    32        for(j=mi(i);j<=mi(i+1)-1;j=j+2){
    33            if(a[j]!=a[j+1]) {
    34                int tmp=a[j]-a[j+1];
    35                if(tmp<0) tmp=-tmp;
    36                ans+=tmp;
    37            //    printf("ans=%d
    ",ans);
    38               }
    39               
    40               int cc=max(a[j],a[j+1]);
    41               a[j/2]+=cc;
    42           }
    43    }
    44    
    45    printf("%d
    ",ans);
    46    return 0;
    47 }
    View Code

    C

    题意:给出容量c,蓝色的糖和红色的糖分别的快乐值v1,v2,分别的重量w1,w2 求最大的快乐值

    做的时候想成背包,想到这么大的容量数组怎么开得下= =

    后来暴力,枚举买蓝色糖的数目从1到100000000,超时

    后来搜了题解= = 发下枚举到100000就可以了,另外要从0开始枚举,因为可能不吃这种糖果

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 #define mod=1e9+7;
    12 using namespace std;
    13 
    14 typedef long long LL;
    15 const int INF = 0x7fffffff;
    16 
    17 int main(){
    18     LL c,v1,v2,w1,w2,i;
    19     cin>>c>>v1>>v2>>w1>>w2;
    20     LL ans=-1;
    21     for(i=0;i<=100000;i++){
    22         LL y=(c-i*w1)/w2;
    23         LL tmp=v2*y+i*v1;
    24         if((c-i*w1)<=0) break;
    25         ans=max(ans,tmp);        
    26     }
    27     
    28     for( i=0;i<=1000000;i++){
    29         LL     y=(c-i*w2)/w1;
    30         LL tmp=v2*i+v1*y;
    31         if((c-i*w2)<=0) break;
    32         ans=max(ans,tmp);
    33     }
    34     if(ans<0) printf("0
    ");
    35     else printf("%I64d
    ",ans);
    36     return 0;
    37 }
    View Code

    这个周六先做bc被虐成狗= =做cf被虐成狗---555555

    加油啊---go--go--go--go--go--go

  • 相关阅读:
    【转】软链接和硬链接到底有啥作用和区别
    useradd命令详解
    【转】Linux下MySQL数据库安装及配置方法
    【转】MySQL的安装与配置——详细教程-window系统下
    mysql服务器常用命令
    【转】DDL/DML/DCL区别概述
    tmux终端工具的简单使用
    linux go环境安装和基本项目结构
    ClickHouse高可用集群的配置
    centos7下使用rpm包安装clickhouse
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4396483.html
Copyright © 2011-2022 走看看