CodeForces - 1567C Carrying Conundrum(思维/状压)
生活随笔
收集整理的這篇文章主要介紹了
CodeForces - 1567C Carrying Conundrum(思维/状压)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:規定加法中使用隔項進位,問給定的 nnn 有多少種方案可以通過 “隔項進位加法” 得到
題目分析:隔項進位意味著奇偶位置的數字互不影響,所以將奇偶位置的兩個數字拿出來,設為 aaa 和 bbb。不難看出組合出某個數字 xxx 的方案為 x+1x+1x+1,即 {0+(x),1+(x?1),?,x+(0)}\{0+(x),1+(x-1),\cdots,x+(0)\}{0+(x),1+(x?1),?,x+(0)}。所以總方案數為 (a+1)?(b+1)(a+1)*(b+1)(a+1)?(b+1),最終答案需要減去二,因為組合出來的數必須非零。
因為時間限制比較寬裕,所以本題可以直接狀壓枚舉哪些位置是進位的,然后統計就好了
代碼:
// Problem: C. Carrying Conundrum // Contest: Codeforces - Codeforces Round #742 (Div. 2) // URL: https://codeforces.com/contest/1567/problem/C // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)// #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e6+100; int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);int w;cin>>w;while(w--) {string s;cin>>s;int ans1=0,ans2=0;for(int i=0;i<(int)s.size();i++) {if(i&1) {ans1=ans1*10+s[i]-'0';} else {ans2=ans2*10+s[i]-'0';}}cout<<1LL*(ans1+1)*(ans2+1)-2<<endl;}return 0; } // Problem: C. Carrying Conundrum // Contest: Codeforces - Codeforces Round #742 (Div. 2) // URL: https://codeforces.com/contest/1567/problem/C // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)// #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e6+100; int sum[N]; void init() {for(int i=0;i<10;i++) {for(int j=0;j<10;j++) {sum[i+j]++;}} } int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);init();int w;cin>>w;while(w--) {int n;read(n);LL ans=-2;for(int i=0;i<1<<8;i++) {int res=1,nn=n;for(int j=0;j<10;j++,nn/=10) {int cur=nn%10;if(i>>j&1) {cur+=10;}if(j>=2&&((i>>(j-2))&1)) {cur--;}if(cur<0) {res=0;break;}res*=sum[cur];}ans+=res;}cout<<ans<<endl;}return 0; }總結
以上是生活随笔為你收集整理的CodeForces - 1567C Carrying Conundrum(思维/状压)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CodeForces - 287C Lu
- 下一篇: 2021-2022年度第三届全国大学生算