zoukankan      html  css  js  c++  java
  • B. Yaroslav and Two Strings 夜

    http://codeforces.com/contest/296/problem/B

    读完题的第一感觉是 dp 后来想了一下dp太复杂了而且出现在div2的B题 说明是个水题

    仔细想了一下 计算相关情况的数量 最后该加的加 该减的减就可以了

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<set>
    #include<map>
    #include<vector>
    #include<queue>
    #include<stack>
    
    #define LL long long
    
    using namespace std;
    
    const long long MOD=1000000007;
    string a,b;
    long long K=55;
    int main()
    {
        //freopen("data.in","r",stdin);
        int n;
        while(cin>>n)
        {
            cin>>a>>b;
            bool abtb=false,bbta=false;//a中是否有比b大的 b中是否有比a大的 (在不讨论‘?’的情况下)
            long long A=1;//a大于等于b的情况
            long long B=1;//b大于等于a的情况
            long long C=1;//a等于b的情况
            long long total=1;//所有情况
            bool had=false;//问号是否出现
            for(int i=0;i<n;++i)
            {
                if(a[i]!='?'&&b[i]!='?')
                {
                    if(a[i]>b[i]) abtb=true;
                    if(b[i]>a[i]) bbta=true;
                }
                had=true;
                if(a[i]!='?'&&b[i]=='?')
                {
                    A=(A*(a[i]-'0'+1))%MOD;
                    B=(B*('9'-a[i]+1))%MOD;
                    total=(total*10)%MOD;
                }
                if(a[i]=='?'&&b[i]!='?')
                {
                    A=(A*('9'-b[i]+1))%MOD;
                    B=(B*(b[i]-'0'+1))%MOD;
                    total=(total*10)%MOD;
                }
                if(a[i]=='?'&&b[i]=='?')
                {
                    A=(A*K)%MOD;
                    B=(B*K)%MOD;
                    C=(C*10)%MOD;
                    total=(total*100)%MOD;
                }
    
            }
            if(had==false)
            {
                if(abtb==true&&bbta==true)
                cout<<"1"<<endl;
                else
                cout<<"0"<<endl;
                continue;
            }
            if(abtb==true&&bbta==true)
            cout<<total<<endl;
            else if(abtb==true&&bbta==false)
            cout<<((total-A+MOD)%MOD)<<endl;
            else if(abtb==false&&bbta==true)
            cout<<((total-B+MOD)%MOD)<<endl;
            else
            cout<<((total-A-B+C+MOD+MOD)%MOD)<<endl;
    
        }
        return 0;
    }
    

      

  • 相关阅读:
    bzoj1053(反素数)
    poj1442(对顶堆)
    poj2823(单调队列)
    poj3630(简单tire)
    poj1924(单调栈求最大矩阵)
    最大xor路径(poj3764)
    poj2689
    求n!末尾0的个数
    BigInteger和BigDecimal的基本用法
    大数乘法
  • 原文地址:https://www.cnblogs.com/liulangye/p/3024384.html
Copyright © 2011-2022 走看看