Codeforces Round 981 (Div. 3)题解记录(A~F)
比赛链接:https://codeforces.com/contest/2033
A. Sakurako and Kosuke
直接模拟好吧(直接奇偶性就好了)
#include<iostream>
#include<queue>
#include<map>
#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>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll cnt=-1;
ll ans=1;
ll i=1;
ll gs=1;
while(cnt<=n&&cnt>=-n)
{
gs++;
if(i%2==1)
{
cnt+=(2*gs-1);
}
else
{
cnt-=(2*gs-1);
}
i++;
ans++;
}
if(ans%2==0)
{
cout<<"Kosuke"<<endl;
}
else
{
cout<<"Sakurako"<<endl;
}
}
}
B. Sakurako and Water
直接统计主对角线最大负数然后取正加起来就好
#include<iostream>
#include<queue>
#include<map>
#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>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[600][600];
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
map<ll,ll>q;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
{
cin>>a[i][j];
if(a[i][j]<0)
{
q[i-j]=min(q[i-j],a[i][j]);
}
}
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
{
if(q[i-j]<0)
{
ans+=abs(q[i-j]);
q[i-j]=0;
}
}
}
cout<<ans<<endl;
}
}
C. Sakurako's Field Trip
从中心进行扩散,然后考虑影响即可
#include<iostream>
#include<queue>
#include<map>
#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>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[250000];
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)cin>>a[i];
ll l=(n+1)/2;
ll r=(n+2)/2;
while(l>=1)
{
ll k=l;
ll u=r;
l--;
r++;
if(l==0)
break;
if(a[l]==a[k]&&a[r]==a[u]&&a[l]!=a[r])
{
swap(a[l],a[r]);
}
else if(a[l]==a[k]&&a[r]!=a[u])
{
swap(a[l],a[r]);
}
else if(a[r]==a[u]&&a[l]!=a[k])
{
swap(a[l],a[r]);
}
}
ll ans=0;
for(ll i=1;i<=n-1;i++)
{
if(a[i]==a[i+1])ans++;
}
cout<<ans<<endl;
}
}
D. Kousuke's Assignment
从左边起,如果每次能凑一对就直接拿,然后清空map
#include<iostream>
#include<queue>
#include<map>
#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>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[250000];
int main()
{
fio();
ll t;
cin>>t;
map<ll,ll>q;
while(t--)
{
q.clear();
ll n;
cin>>n;
ll ans=0;
q[0]++;
ll l=0;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
if(q[a[i]-a[l]]>0)
{
q.clear();
q[0]++;
ans++;
l=i;
continue;
}
q[a[i]-a[l]]++;
}
cout<<ans<<endl;
}
}
E. Sakurako, Kosuke, and the Permutation
仔细想想只要不符合的凑一下就好了,这种凑得是第二种,然后模拟一遍即可
#include<iostream>
#include<queue>
#include<map>
#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>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[2500000];
bool vis[2500000];
ll b[2500000];
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)
{
cin>>a[i],vis[i]=0;
b[a[i]]=i;
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
if(vis[i])continue;
if(a[a[i]]==i)
{
vis[i]=1;
vis[a[i]]=1;
}
else if(a[i]==i)
{
vis[i]=1;
}
else
{
// 3 1
ll u=a[a[i]],j=a[b[i]];
swap(a[a[i]],a[b[i]]);//
//cout<<a[a[i]]<<" "<<a[b[i]]<<endl;
swap(b[u],b[j]);
vis[i]=1;
vis[a[i]]=1;
ans++;
}
}
cout<<ans<<endl;
}
}
F. Kosuke's Sloth
模
皮萨诺周期总是不超过
加上打表得出现次数即周期性倍数,于是在线求解即可
#include<iostream>
#include<queue>
#include<map>
#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>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[6002000];
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
if(k==1)
cout<<n%mod<<endl;
else
{
ll i=3;
a[1]=1,a[2]=1;
ll f;
while(1)
{
a[i]=(a[i-1]%k+a[i-2]%k)%k;
if(a[i]%k==0)
{
f=i;
break;
}
i++;
}
cout<<((f%mod)*(n%mod))%mod%mod%mod<<endl;
}
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~