zoukankan      html  css  js  c++  java
  • HZNU Training 21 for Zhejiang Provincial Competition 2020

    C - 展开字符串

     HDU - 1274 

    处理括号优先级:栈保存所有的字符,
    遇到 数字+字符,数字拿出来,for一遍,字符填到栈里,
    遇到 )一直把栈里元素拿出来,直到 ( 为止,然后把这中间的元素保存下来,因为括号前面有系数
    ,再for一遍,填到栈里,最后把栈清空,输出

    题目数据有问题:没有判数字大于10情况。

    #include<cstdio>
    #include<iostream>
    #include<stack>
    #include<cstring>
    using namespace std;
    typedef long long ll;
    const ll MOD=998244353;
    const int N=1e4+5;
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
    
        string s,ans;stack<char>stk;
    
        cin>>s;
        int len=s.size();
        for(int i=0;i<len;i++){
        
        if(s[i]=='('||s[i]>='0'&&s[i]<='9')stk.push(s[i]);
        
        else if(s[i]>='a'&&s[i]<='z'){
        
        if(stk.top()>='0'&stk.top()<='9'){
        int num=stk.top()-'0';stk.pop();
        while(num--){stk.push(s[i]);}
        
        }
        
        else stk.push(s[i]);
    
        }
    
        else if(s[i]==')'){
        string tmp;
        while(1){
        char ch=stk.top();stk.pop();
        if(ch=='(')break;
        tmp.insert(tmp.begin(),ch);
        }
        int num=0;
        if(stk.top()>='0'&&stk.top()<='9')num=stk.top()-'0',stk.pop();
        else num=1;
        while(num--){
          for(int j=0;j<tmp.size();j++){
            stk.push(tmp[j]);
          }
        }
        }
        }
        while(!stk.empty()){
          ans.insert(ans.begin(),stk.top());stk.pop();
        }
        cout<<ans<<endl;
    
    
        }
    
    
        // system("pause");
        return 0;
    }
    View Code

    J - Function and Function

     ZOJ - 4070 

    签到,漏了一个case,为0,没有特判,直接返回0了。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=6e3+5;
    #define pb push_back
    int  Std[]={1,0,0,0,1,0,1,0,2,1};
    int  f(int  x){
        int sum=0;
        do{
        int tmp=x%10;
        sum+=Std[tmp];
        x/=10;
        }while(x);
        return sum;
    }
    int  g(int x,int  k){
        // if(k==0)return x;
        int  cur=x;
        while(k--){
        cur=f(cur);
        if(cur==0&&k%2==0)return 0;
        else if(cur==0&&k%2==1)return 1;
        else if(cur==1&&k%2==0)return 1;
        else if(cur==1&&k%2==1)return 0;
        }
        return cur;
    }
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
        int  x,k;
        scanf("%d %d",&x,&k);
        int ans=g(x,k);
        printf("%d
    ",ans);
        }
        // system("pause");
        return 0;
    }
    View Code

    K - Plants vs. Zombies

     ZOJ - 4062 

    蛋疼题,

    最小值最大化,一般都是二分,

    二分出一个x,去check 一下 最小值为 x 能不能成立,但要注意memset会tle,而且无论当前状态如何,都要跳一步。

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    const int N=1e5+50;
    ll v[N],h[N];
    int n;ll M;
    bool check(ll x){
    
        for(int i=1;i<=n;i++)h[i]=0;
        ll step=0;
    
        for(int i=1;i<n;i++){
        
        if(h[i]<x)step++,h[i]+=v[i];
        
        if(h[i]<x){
        
        ll cur=(long long )ceil((x-h[i])*1.0/v[i]);
        step+=2*cur;
        h[i+1]+=cur*v[i+1];
        h[i]+=cur*v[i];
        
        }
        
        if(step>M)return 0;
        }
        if(h[n]<x){step++;h[n]+=v[n];}
        
        if(h[n]<x){
        ll cur=(long long )ceil((x-h[n])*1.0/v[n]);
        step+=2*cur;
    
        }
    
        if(step>M)return 0;
        else return 1;
    
    }
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
        scanf("%d %lld",&n,&M);
        for(int i=1;i<=n;i++)scanf("%lld",&v[i]);
        ll L=0,R=1e12;
        ll ans=0;
    
        if(M==0){puts("0");continue;}
        while(L<=R){
        ll  mid=(L+R)/2;
        if(check(mid))ans=mid,L=mid+1;
        else R=mid-1;
        }
    
        printf("%lld
    ",ans);
        }
        // system("pause");
        return 0;
    }
    
    // 用栈保存所有的字符,
    // 遇到 数字+字符,数字拿出来,for一遍,字符填到栈里,
    // 遇到 )一直把栈里元素拿出来,直到 ( 为止,然后把这中间的元素保存下来,因为括号前面有系数
    // ,再for一遍,填到栈里,最后把栈清空,输出,
    View Code
    想的太多,做的太少;
  • 相关阅读:
    maven 项目 spring mvc + jdbc 配置文件
    (BUG已修改,最优化)安卓ListView异步加载网络图片与缓存软引用图片,线程池,只加载当前屏之说明
    listview图片错位
    Android在线更新 远程安装程序
    Android中Socket大文件断点上传
    如何用JAVA生成注册序列号
    php学习随记3
    Chrome改动浏览器User Agent
    andoid电阻触摸移植
    【有奖征资源,分享有内涵】贡献你的CSDN博文和下载资源,不断更新中
  • 原文地址:https://www.cnblogs.com/littlerita/p/12687200.html
Copyright © 2011-2022 走看看