A:先手那个人涂颜色肯定是从1到m一直重复,计算出需要的最小次数即可
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=2*N,mod=998244353;
#define int long long
typedef pair<int,int> PII;
typedef long long LL;
using node=tuple<int,int,int>;
const long long inf=1e18;
int n,m,k;
int a[N];
int qmi(int a, int k, int p) // 求a^k mod p
{
int res = 1 % p;
while (k)
{
if (k & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
void solve()
{
cin>>n>>m>>k;
int x=n/m;
int need=n-(x+(n%m>0));
//coout<<x*m-x<<"\n";
//cout<<need<<"\n";
if(k>=need)
{
cout<<"NO\n";
}else cout<<"YES\n";
}
signed main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--) solve();
}
B:
手玩一下发现符合要求的数组最后一定是
X y X z X a X
即X的数相隔,所以直接把不是X的数位置拿出来,最少次数就是删掉两个位置中的 X
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,M=2*N,mod=998244353;
#define int long long
typedef pair<int,int> PII;
typedef long long LL;
using node=tuple<int,int,int>;
const long long inf=1e18;
int n,m,k;
int a[N];
int qmi(int a, int k, int p) // 求a^k mod p
{
int res = 1 % p;
while (k)
{
if (k & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int x=a[1];
if(a[1]!=a[n]){
cout<<"0\n";return ;
}
int res=inf;
vector<int> pos;
for(int i=1;i<=n;i++){
if(a[i]!=x) pos.push_back(i);
}
if(pos.empty()){
cout<<"-1\n";return ;
}
pos.insert(pos.begin(),0);
pos.push_back(n+1);
for(int i=1;i<pos.size();i++)
{
res=min(res,pos[i]-pos[i-1]-1);
}
cout<<res<<"\n";
}
signed main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--) solve();
}
C:贪心,让两个数尽可能接近,所以第一位比某个数大的时候,后面要保证另一个数最大
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=2*N,mod=998244353;
#define int long long
typedef pair<int,int> PII;
typedef long long LL;
using node=tuple<int,int,int>;
const long long inf=1e18;
int n,m,k;
int a[N];
int qmi(int a, int k, int p) // 求a^k mod p
{
int res = 1 % p;
while (k)
{
if (k & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
void solve()
{
string a,b;cin>>a>>b;
int belong=-1;
int n=a.size();
for(int i=0;i<n;i++){
if(a[i]==b[i]) continue;
if(belong==-1){
if(a[i]>b[i]) belong=0;
else belong=1;
continue;
}
if(belong==0&&a[i]>b[i]){
swap(a[i],b[i]);
}
if(belong==1&&a[i]<b[i]) swap(a[i],b[i]);
}
cout<<a<<"\n";
cout<<b<<"\n";
}
signed main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--) solve();
}
D:
根据鸽子原理?
mx=众数个数,s=总和
mx<=(s+1)/2 的时候肯定能分成(s+1)/2组,否则需要分mx组
然后思考怎么计算贡献不重不漏,我的思路是每次强制一定要选第i种颜色,求[1,i-1]的子序列的所有方案数,再根据背包的体积分别计算贡献
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=2*N,mod=998244353;
#define int long long
typedef pair<int,int> PII;
typedef long long LL;
using node=tuple<int,int,int>;
const long long inf=1e18;
int n,m,k;
int a[N];
int qmi(int a, int k, int p) // 求a^k mod p
{
int res = 1 % p;
while (k)
{
if (k & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
void solve()
{
//跟众数有关吧
//众数<=s/2=(s+1)/2
//else =mx
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int res=a[0];
vector<int> f(5010); f[0]=1;
for(int i=1;i<n;i++)
{
for(int k=5000;k>=a[i-1];k--)
{
f[k]+=f[k-a[i-1]];
f[k]%=mod;
}
for(int j=0;j<=5000;j++)
{
if(j+a[i]>5000) break;
res+=f[j]*max(a[i],(j+a[i]+1)/2)%mod;
res%=mod;
}
}
cout<<res<<"\n";
}
signed main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
// cin>>t;
while(t--) solve();
}
E;
因为他攻击的时候就算当前死了,也会扩展,所以等于每次选一段数,里面数不能为0,里面所有的数都要减掉x
然后求相邻两个数的值对哪些数做贡献,整除分块即可
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,M=2*N,mod=998244353;
#define int long long
typedef pair<int,int> PII;
typedef long long LL;
using node=tuple<int,int,int>;
const long long inf=1e18;
int n,m,k;
int a[N];
int qmi(int a, int k, int p) // 求a^k mod p
{
int res = 1 % p;
while (k)
{
if (k & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
int d[N];
void solve()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int mx=*max_element(a+1,a+1+n);
for(int i=2;i<=n;i++)
{
int w1=a[i]-1,w2=a[i-1]-1;
for(int l=1,r;l<=mx;l=r+1)
{
r=min(w1/l==0?mx:w1/(w1/l),
w2/l==0?mx:w2/(w2/l));
if(w1/l+1>w2/l+1)
{
int cnt=w1/l-w2/l;
d[l]+=cnt;
d[r+1]-=cnt;
}
}
}
for(int i=1;i<=mx;i++){
d[i]+=d[i-1];
cout<<d[i]+(a[1]+i-1)/i<<" ";
}
// for(int k=1;k<=mx;k++){
// int cnt=0;
// for(int i=1;i<=n;i++)
// {
// int x=(a[i]+k-1)/k;
// int y=(a[i-1]+k-1)/k;
// if(x>y){
// cnt+=(x-y);
// }
// }
// cout<<cnt<<" ";
// }
}
signed main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
//cin>>t;
while(t--) solve();
}