zoukankan      html  css  js  c++  java
  • 10.10T3 栈哈希

    这题强行搜过20分,太垃圾了。。。。

    实际上我的代码不知道为什么有个点超时严重,不管了

    code:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string>
     4 #include<map>
     5 using namespace std;
     6 string k;
     7 char a[2000006];
     8 int top;
     9 map<string,long long>check;
    10 int main(){
    11     getline(cin,k);
    12     string temp="";
    13     long long ans=0;
    14     check[temp]++;
    15     for(long long i=0;i<k.size();i++){
    16         if(!top){
    17             a[++top]=k[i];
    18             temp+=k[i];
    19             check[temp]++;
    20             ans+=check[temp]-1;
    21         }
    22         else if(a[top]==k[i]){
    23             top--;
    24             temp.erase(temp.end()-1);
    25             check[temp]++;
    26             ans+=check[temp]-1;
    27         }
    28         else{
    29             a[++top]=k[i];
    30             temp+=k[i];
    31             check[temp]++;
    32             ans+=check[temp]-1;
    33         }
    34     }
    35     cout<<ans;
    36     return 0;
    37 }

    over

  • 相关阅读:
    Constructor构造方法
    overload重载
    static关键字
    this关键字
    继承
    ORACLE数据库 常用命令和Sql常用语句
    常见单词
    L贪心基础
    J贪心
    K贪心
  • 原文地址:https://www.cnblogs.com/saionjisekai/p/9768239.html
Copyright © 2011-2022 走看看