zoukankan      html  css  js  c++  java
  • 2016百度之星资格赛

    A.前缀hash+逆元

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <queue>
    #include <vector>
    #include <algorithm>
    
    const int inf = 0x3f3f3f;
    const int MAXN = 1e5+10;
    const int MOD = 9973;
    
    using namespace std;
    
    char ts[MAXN];
    int n;
    int a[MAXN],rev[MOD],b[MAXN];
    
    long long quickpow(long long base,long long n){
        long long ans = 1;
        while(n){
            if(n%2==1)ans = ans*base%MOD;
            n /= 2;
            base = base*base%MOD;
        }
        return ans;
    }
    
    int main()
    {
        for(int i=1;i<MOD;i++){
            rev[i] = quickpow(i,MOD-2);
        }
    
        while(scanf("%d",&n)!=EOF){
            scanf("%s",ts);
            int len = strlen(ts);
            a[0] = 1;
            b[0] = rev[1];
            for(int i=0;i<len;i++){
                a[i+1] = a[i]*(ts[i]-28)%MOD;
                b[i+1] = rev[a[i+1]];
            }
            int u,v;
            for(int i=0;i<n;i++){
                scanf("%d%d",&u,&v);
                printf("%d
    ",a[v]*b[u-1]%MOD);
            }
        }
        //cout << "Hello world!" << endl;
        return 0;
    }
    View Code

    D.sort+map

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <vector>
    #include <map>
    #include <algorithm>
    
    const int inf = 0x3f3f3f;
    const int MAXN = 1e7+10;
    
    using namespace std;
    
    
    int main()
    {
        int n;
        char ts[40];
        map<string,int>hash;
        map<string,int>::iterator li;
        while(scanf("%d",&n)!=EOF){
            hash.clear();
            for(int i=0;i<n;i++){
                scanf("%s",ts);
                int len = strlen(ts);
                sort(ts,ts+len);
                string tmp = (string)ts;
                    li = hash.find(tmp);
                    if(li==hash.end()){
                        cout<<0<<endl;
                        hash[tmp]++;
                    }else{
                        cout<<hash[tmp]<<endl;
                        hash[tmp]++;
                    }
                }
    
        }
        //cout << "Hello world!" << endl;
        return 0;
    }
    View Code
    在一个谎言的国度,沉默就是英雄
  • 相关阅读:
    jmeter脚本在非GUI模式下运行_增加请求和返回_记录
    scp从一台服务器复制文件到本台服务器
    crontab定时任务配置
    jmeter非GUI模式_单点运行
    jmeter非GUI模式_分布式运行
    Dede 查询附加表
    Dede 列表文章 自增
    dede密码忘记 的修改方法
    CSS 字体描边
    教你如何去掉点击链接时的虚线
  • 原文地址:https://www.cnblogs.com/EdsonLin/p/5493448.html
Copyright © 2011-2022 走看看