zoukankan      html  css  js  c++  java
  • CF-296B-Yaroslav and Two Strings(容斥)

    题意:http://codeforces.com/problemset/problem/296/B

    有一个位置ai<bi,有一个位置ai>bi的串的数量。

    思路:

    总数-全小于等于-全大于等于+全相等

      1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
      2 #include <cstdio>//sprintf islower isupper
      3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
      4 #include <iostream>//pair
      5 #include <fstream>//freopen("C:\Users\13606\Desktop\Input.txt","r",stdin);
      6 #include <bitset>
      7 //#include <map>
      8 //#include<unordered_map>
      9 #include <vector>
     10 #include <stack>
     11 #include <set>
     12 #include <string.h>//strstr substr strcat
     13 #include <string>
     14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
     15 #include <cmath>
     16 #include <deque>
     17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
     18 #include <vector>//emplace_back
     19 //#include <math.h>
     20 #include <cassert>
     21 #include <iomanip>
     22 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
     23 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
     24 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
     25 //******************
     26 clock_t __START,__END;
     27 double __TOTALTIME;
     28 void _MS(){__START=clock();}
     29 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
     30 //***********************
     31 #define rint register int
     32 #define fo(a,b,c) for(rint a=b;a<=c;++a)
     33 #define fr(a,b,c) for(rint a=b;a>=c;--a)
     34 #define mem(a,b) memset(a,b,sizeof(a))
     35 #define pr printf
     36 #define sc scanf
     37 #define ls rt<<1
     38 #define rs rt<<1|1
     39 typedef pair<int,int> PII;
     40 typedef vector<int> VI;
     41 typedef unsigned long long ull;
     42 typedef long long ll;
     43 typedef double db;
     44 const db E=2.718281828;
     45 const db PI=acos(-1.0);
     46 const ll INF=(1LL<<60);
     47 const int inf=(1<<30);
     48 const db ESP=1e-9;
     49 const int mod=(int)1e9+7;
     50 const int N=(int)1e5+10;
     51 
     52 char s[N],ss[N];
     53 ll dp[N][4];
     54 int a[20]={1,2,3,4,5,6,7,8,9,10};
     55 int aa[20]={10,9,8,7,6,5,4,3,2,1};
     56 
     57 int main()
     58 {
     59     int n;
     60     sc("%d",&n);
     61     sc("%s%s",s+1,ss+1);
     62     for(int i=1;i<=n;++i)
     63     {
     64         if(s[i]=='?'&&ss[i]=='?')
     65             dp[i][0]=dp[i][1]=55,dp[i][3]=10;
     66         else if(s[i]=='?')
     67         {
     68             dp[i][0]=a[ss[i]-'0'];
     69             dp[i][1]=aa[ss[i]-'0'];
     70             dp[i][3]=1;
     71         }
     72         else if(ss[i]=='?')
     73         {
     74             dp[i][0]=aa[s[i]-'0'];
     75             dp[i][1]=a[s[i]-'0'];
     76             dp[i][3]=1;
     77         }
     78         else
     79         {
     80             if(s[i]<=ss[i])
     81                 dp[i][0]=1;
     82             if(s[i]>=ss[i])
     83                 dp[i][1]=1;
     84             if(s[i]==ss[i])
     85                 dp[i][3]=1;
     86         }
     87     }
     88     ll ansmin=1,ansmax=1,ansmix=1,anseq=1;
     89     for(int i=1;i<=n;++i)
     90     {
     91         ansmin*=dp[i][0];
     92         ansmax*=dp[i][1];
     93         anseq*=dp[i][3];
     94         if(s[i]=='?'&&ss[i]=='?')
     95             ansmix*=100;
     96         else if(s[i]=='?'||ss[i]=='?')
     97             ansmix*=10;
     98         ansmin%=mod;
     99         ansmax%=mod;
    100         ansmix%=mod;
    101         anseq%=mod;
    102     }
    103     pr("%lld
    ",((ansmix-ansmin-ansmax+anseq)%mod+mod)%mod);
    104     return 0;
    105 }
    106 
    107 /**************************************************************************************/
  • 相关阅读:
    语言:障碍与桥梁(探索语言的本质、如何避免语言上的误解)
    知觉:看到什么就是什么(怎么避免误解别人的行为)
    沟通和认同:自我的塑造与展现(如何认识自我,如何袒露自我,如何回应尴尬问题)
    人际沟通入门(认清沟通高手的特质)
    人际沟通与社交媒体(媒介沟通的优缺点)
    javascript中的this值
    Javascript 模块化编程 --RequireJs
    datetime与int 转换通用函数
    c# 读写cookie 通用函数
    分类组件
  • 原文地址:https://www.cnblogs.com/--HPY-7m/p/12594461.html
Copyright © 2011-2022 走看看