生活随笔
收集整理的這篇文章主要介紹了
牛客练习赛 71 AC
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
A - 回文數(shù)
回文數(shù)條件:奇數(shù)個數(shù)的個數(shù)最多有一個
如果0的數(shù)量是0,那么直接先找到奇數(shù)個數(shù)的數(shù)是誰,然后正序輸出一半逆序輸出一半即可。
如果0的數(shù)量不是0,只需要找到一個偶數(shù)個個數(shù)的數(shù)放置第一個即可(只需要放一個最開頭一個末尾)
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std
;
typedef long long ll
;
typedef pair
<int,int> pii
;
const int N
=20;
int cnt
[N
];
int now
[N
];
int main()
{IO
;int T
=1;while(T
--){int odd
=0;for(int i
=0;i
<=9;i
++){cin
>>cnt
[i
];if(cnt
[i
]&1) odd
++;}if(odd
>1) {cout
<<-1;continue;}if(!cnt
[0]){int p
=-1;for(int i
=1;i
<=9;i
++)if(cnt
[i
]&1) p
=i
;for(int i
=1;i
<=9;i
++)for(int j
=1;j
<=cnt
[i
]/2;j
++) cout
<<i
;if(p
!=-1) cout
<<p
;for(int i
=9;i
>=1;i
--)for(int j
=1;j
<=cnt
[i
]/2;j
++) cout
<<i
;}else{int p
=-1;for(int i
=1;i
<=9;i
++)if(cnt
[i
]) if(p
==-1||cnt
[p
]==1)p
=i
;if(p
==-1){if(cnt
[0]==1) cout
<<0;else cout
<<-1;continue;}else{if(cnt
[p
]==1){cout
<<-1;continue;}int q
=-1;for(int i
=0;i
<=9;i
++)if(cnt
[i
]&1) q
=i
;cout
<<p
;cnt
[p
]-=2;for(int i
=0;i
<=9;i
++)for(int j
=1;j
<=cnt
[i
]/2;j
++) cout
<<i
;if(q
!=-1) cout
<<q
;for(int i
=9;i
>=0;i
--)for(int j
=1;j
<=cnt
[i
]/2;j
++) cout
<<i
;cout
<<p
;}}}return 0;
}
C - 數(shù)學(xué)考試
狀態(tài)表示:fif_ifi?表示1~pi1 \sim p_i1~pi?是pip_ipi?的排列,且1~pj1 \sim p_j1~pj?不是是pjp_jpj?的排列j<ij<ij<i情況下的方案數(shù)
狀態(tài)計(jì)算:fi=pi!?∑j=1i?1fj×(pi?pj)!f_i=p_i!-\sum_{j=1}^{i-1}f_j×(p_i-p_j)!fi?=pi?!?∑j=1i?1?fj?×(pi??pj?)!
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std
;
typedef long long ll
;
typedef pair
<int,int> pii
;
const int N
=2010;
const int mod
=20000311;
int n
,m
;
ll f
[N
],fact
[N
],p
[N
];
int main()
{IO
;int T
=1;while(T
--){cin
>>n
>>m
;for(int i
=1;i
<=m
;i
++) cin
>>p
[i
];fact
[0]=1;for(int i
=1;i
<=n
;i
++) fact
[i
]=fact
[i
-1]*i
%mod
;sort(p
+1,p
+1+m
);for(int i
=1;i
<=m
;i
++){f
[i
]=fact
[p
[i
]];for(int j
=1;j
<i
;j
++)f
[i
]=(f
[i
]-f
[j
]*fact
[p
[i
]-p
[j
]]%mod
)%mod
;}ll res
=fact
[n
];for(int i
=1;i
<=m
;i
++)res
=(res
-f
[i
]*fact
[n
-p
[i
]]%mod
)%mod
;cout
<<(res
%mod
+mod
)%mod
<<'\n';}return 0;
}
總結(jié)
以上是生活随笔為你收集整理的牛客练习赛 71 AC的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。