Educational Codeforces Round 181 (Rated for Div. 2)(A~D)
比赛链接:https://codeforces.com/contest/2125
最近再打航电多校和牛客多校,有点小累,随缘更新啦
A.Difficult Contest
思路:“NTT”or"FFT"都要求T在后面,那么我们先遍历一遍不含F和N的字符,后面补上F和N即可
#include<iostream>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#include<functional>
#define ll int
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
// ll mod=99;
const ll maxn=1e6+5;
ll ksm(ll x, ll y)
{
ll ans = 1;
x%=mod;
while (y)
{
if (y & 1)
{
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans % mod;
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct s{
ll id,t,wa;
friend bool operator<(const s&a,const s&b){
return a.t>b.t;
}
};
int main(){
fio();
ll t;
cin>>t;
while(t--){
string f;
cin>>f;
for(ll i=0;i<f.size();i++){
if(f[i]!='F'&&f[i]!='N')cout<<f[i];
}
for(ll i=0;i<f.size();i++){
if(f[i]=='F'||f[i]=='N')cout<<f[i];
}
cout<<endl;
}
return 0;
}
B. Left and Down
思路:如果a和b构成的最简比,如果均小于等于k那么肯定只要一个花费,否则我就先选(1,0)再选个(0,1)就行了,花费最大为2.
吐槽:默认用long long再思考要不要改int是个好习惯
#include<iostream>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#include<functional>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
// ll mod=99;
const ll maxn=1e6+5;
ll ksm(ll x, ll y)
{
ll ans = 1;
x%=mod;
while (y)
{
if (y & 1)
{
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans % mod;
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct s{
ll id,t,wa;
friend bool operator<(const s&a,const s&b){
return a.t>b.t;
}
};
int main(){
fio();
ll t;
cin>>t;
while(t--){
ll a,b,k;
cin>>a>>b>>k;
if(a==b)cout<<1<<endl;
else {
if(a>b)swap(a,b);
ll kk=__gcd(a,b);
if(a/kk<=k&&b/kk<=k)cout<<1<<endl;
else cout<<2<<endl;
}
}
return 0;
}
C. Count Good Numbers
思路:显然位数小于2的质数只有2,3,5,7.那么枚举子集容斥就行啦
#include<iostream>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#include<functional>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
// ll mod=99;
const ll maxn=1e6+5;
ll ksm(ll x, ll y)
{
ll ans = 1;
x%=mod;
while (y)
{
if (y & 1)
{
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans % mod;
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct s{
ll id,t,wa;
friend bool operator<(const s&a,const s&b){
return a.t>b.t;
}
};
int main(){
fio();
ll t;
cin>>t;
while(t--){
ll l,r;
cin>>l>>r;
function<ll(ll)>ck=[&](ll x){
vector<ll>a;
a.push_back(2);
a.push_back(3);
a.push_back(5);
a.push_back(7);
ll ans=0;
for(ll i=0;i<(1ll<<4);i++){
ll cnt=0;
ll d=1;
for(ll j=0;j<4;j++){
if((1ll<<j)&i){
cnt++;
d*=a[j];
}
}
if(cnt&1){
ans-=x/d;
}
else ans+=x/d;
}
return ans;
};
cout<<ck(r)-ck(l-1)<<endl;
}
return 0;
}
D. Segments Covering
思路:线性dp+前缀积。显然我们可以把每个片段用vector存在r上,存储l,p,q三个信息。然后再做一个前缀积(是(1-p/q)再mod意义下的前缀积)。然后从左往右遍历,显然一个点vector大于0,那么就有(先算好概率,设为gl)dp[i]+=dp[l-1] * pre[i] * ksm(pre[l-1],mod-2) * ksm(1-gl,mod-2) * gl(假设被每个段覆盖,且片段内没出现其他片段),自己注意取模
#include<iostream>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#include<functional>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
// ll mod=99;
const ll maxn=1e6+5;
ll ksm(ll x, ll y)
{
ll ans = 1;
x%=mod;
while (y)
{
if (y & 1)
{
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans % mod;
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct s{
ll id,t,wa;
friend bool operator<(const s&a,const s&b){
return a.t>b.t;
}
};
int main(){
fio();
ll t=1;
// cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
vector<s>g[m+2];
for(ll i=1;i<=n;i++){
ll l,r,p,q;
cin>>l>>r>>p>>q;
g[r].push_back({l,p,q});
}
vector<ll>dp(m+2,0);
vector<ll>pre(m+2,0);
pre[0]=1;
for(ll i=1;i<=m;i++){
pre[i]=pre[i-1];
for(auto [l,p,q]:g[i]){
ll gl=p*ksm(q,mod-2)%mod;
(pre[i]*=(1-gl))%=mod;
}
}
// cout<<pre[n]<<endl;
dp[0]=1;
for(ll i=1;i<=m;i++){
for(auto [l,p,q]:g[i]){
ll d=pre[i]*ksm(pre[l-1],mod-2)%mod;
ll gl=p*ksm(q,mod-2)%mod;
ll re=d*ksm(1-gl+mod,mod-2)%mod;
(dp[i]+=dp[l-1]*re%mod*gl%mod)%=mod;
}
}
cout<<(dp[m]%mod+100*mod)%mod<<endl;
}
return 0;
}

浙公网安备 33010602011771号