Educational Codeforces Round 86 (Rated for Div. 2)部分题解
Problem A
不开ll见祖宗
Problem B
要求长度小于等于2n那么,我们贪心的情况下肯定选择最多的那个,然后直接补,这个长度一定不会超过2n,所以直接输出就好了,循环k值在不是一的情况下一定可以被补成2.
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=start;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef vector <int> VI;
typedef pair<int ,int> PII;
typedef pair<int ,PII> PIII;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
void check_max (int &a,int b) { a=max (a,b);}
void check_min (int &a,int b) { a=min (a,b);}
inline int read() {
char ch=getchar(); int x=0, f=1;
while(ch<'0'||ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
} while('0'<=ch&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
} return x*f;
}
const int maxn=1e3+10;
int t;
string str;
void solve () {
cin>>str;
map <int,int> mp;
for (auto it:str) mp[it-'0']++;
if (!mp[0]||!mp[1]||str.size ()==2) cout<<str<<endl;
else {
cout<<str[0];
rev (i,1,str.size ()) {
if (str[i]==str[i-1]) {
if (str[i]=='1') cout<<"0";
else cout<<"1";
}
cout<<str[i];
}
cout<<endl;
}
}
int main () {
ios::sync_with_stdio (false);
cin>>t;
while (t--) {
solve ();
}
return 0;
}
Problem C
出现了区间个数,那么c题的位置应该就是类似前缀和的操作,那么我们很容易可以猜到推出,这些个数是以ab为一个周期的,那么我们只需要对0-a b做一个完全剩余系的前缀和统计就好了。
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=start;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef vector <int> VI;
typedef pair<int ,int> PII;
typedef pair<int ,PII> PIII;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
void check_max (int &a,int b) { a=max (a,b);}
void check_min (int &a,int b) { a=min (a,b);}
inline int read() {
char ch=getchar(); int x=0, f=1;
while(ch<'0'||ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
} while('0'<=ch&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
} return x*f;
}
const int maxn=1e3+10;
int t,a,b,q;
vector <ll> pre;
ll calc (ll x) {
return x/(a*b)*pre[a*b]+pre[x%(a*b)];
}
void solve () {
scanf ("%d%d%d",&a,&b,&q);
pre.resize (a*b+1,0);
rev (i,0,a*b) pre[i+1]=pre[i]+(i%a%b!=i%b%a);
while (q--) {
ll l,r;
scanf ("%lld%lld",&l,&r);
printf ("%lld ",calc (r+1)-calc (l));
}
printf ("\n");
}
int main () {
scanf ("%d",&t);
while (t--) {
solve ();
}
return 0;
}
Problem D
这个题目,是类似一个模拟加贪心的思路,我们从后往前遍历,当c值小于前一个值的时候就去重新从0号集合开始放(c值允许放,重点是给出的c数组单调下降),因为从大的开始放,先开始哪个必然是最大的,以后放的话c值都会增大,然后模拟一个二维数组当作集合就好了。
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=start;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef vector <int> VI;
typedef pair<int ,int> PII;
typedef pair<int ,PII> PIII;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
void check_max (int &a,int b) { a=max (a,b);}
void check_min (int &a,int b) { a=min (a,b);}
inline int read() {
char ch=getchar(); int x=0, f=1;
while(ch<'0'||ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
} while('0'<=ch&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
} return x*f;
}
const int maxn=1e3+10;
int t;
void solve () {
int n,k;
scanf ("%d%d",&n,&k);
vector <int> cnt (k);
rep (i,1,n) {
int x;
scanf ("%d",&x);
++cnt[--x];
}
vector <int> c (k+1);
rep (i,0,k-1) scanf ("%d",&c[i]);
int j=0;
vector <vector <int>> v (1);
per (i,k-1,0) {
if (c[i]>c[i+1]) j=0;
while (cnt[i]--) {
if (int (v[j].size ()==c[i])) j++;
if (j==int (v.size ())) v.emplace_back ();
v[j].pb (i);
}
}
printf ("%d\n",v.size ());
for (auto it:v) {
printf("%d",it.size ());
for (auto i:it) printf (" %d",i+1);
printf ("\n");
}
}
int main () {
t=1;
while (t--) {
solve ();
}
return 0;
}
Problem E
首先要求每个都被一步攻击,那么需要每行或者每列都有一个车,然后刚好k对互相攻击,假设这个在每行放一个,那么这些车在列上面的分布一定是集中在n-k列之上,这样的话我们就得出答案,就是第二类斯特林数C(n,n-k)(n-k)!*2.
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=start;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef vector <int> VI;
typedef pair<int ,int> PII;
typedef pair<int ,PII> PIII;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
void check_max (int &a,int b) { a=max (a,b);}
void check_min (int &a,int b) { a=min (a,b);}
inline int read() {
char ch=getchar(); int x=0, f=1;
while(ch<'0'||ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
} while('0'<=ch&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
} return x*f;
}
const int mod=998244353;
const int maxn=2e5+10;
int t;
ll fac[maxn];
ll fast_pow (ll a,ll b) {
ll ans=1;
while (b) {
if (b&1) ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ans;
}
ll C (ll n,ll m) {
return fac[n]*fast_pow (fac[m]*fac[n-m]%mod,mod-2)%mod;
}
void solve () {
ll ans=0,n,k;
scanf ("%lld%lld",&n,&k);
if (k>n-1) {
printf ("0");
return ;
}
fac[0]=fac[1]=1;
ll m=n-k;
rev (i,2,maxn) fac[i]=(fac[i-1]*i)%mod;
rep (i,0,m) {
if (i%2==0) ans+=C (m,i)*fast_pow (m-i,n)%mod;
else ans=ans-C (m,i)*fast_pow (m-i,n)%mod+mod;
ans%=mod;
}
ans= (ans*C (n,m))%mod;
if (k) ans= (ans<<1)%mod;
printf ("%lld\n",ans);
}
int main () {
// scanf ("%d",&t);
t=1;
while (t--) {
solve ();
}
return 0;
}