B. Yaroslav and Two Strings
2013-04-16 17:48
253 查看
http://codeforces.com/contest/296/problem/B
读完题的第一感觉是 dp 后来想了一下dp太复杂了而且出现在div2的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; }
相关文章推荐
- CodeForces Round #179 (296B) - Yaroslav and Two Strings
- CodeForces 296 B.Yaroslav and Two Strings(dp)
- Codeforces Round #179 (Div. 2) B.Yaroslav and Two Strings(容斥原理)
- 4000 codeforces 296B - Yaroslav and Two Strings (DP+容斥)
- 情况动态规划CodeForces Round #179 (296B) - Yaroslav and Two Strings
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings (容斥原理)
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- Codeforces Round #179 (Div. 2) B (codeforces 296b) Yaroslav and Two Strings
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings 【组合数学】
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings(容斥原理)
- Given two strings s and t, write a function to determine if t is an anagram of s.
- Given two strings s and t, write a function to determine if t is an anagram of s.
- [python]leetcode(72). Edit Distance AND (583). Delete Operation for Two Strings
- Codeforces Round #358 (Div. 2) D. Alyona and Strings
- 712. Minimum ASCII Delete Sum for Two Strings
- objc[2213]: Class _NSZombie_BSXPCMessage is implemented in both ?? and ??. One of the two will be us
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots
- A. Polo the Penguin and Strings
- 【RAC搭建报错】You need disks from at least two different failure groups, excluding quorum disks and quorum failure groups, to create a Disk Group with normal redundancy