前言:
记录一下自己昨天晚上打的div3吧,感觉自己好久没写博客,以后可能会更新一些其他内容,在这里先买个关子,我要现在今年沉淀几个月,所以这几天可能不会更新博客,今天先出来冒个泡先。
正文:
链接:https://codeforces.com/contest/2033
题目:
A. Sakurako and Kosuke:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){int n;cin>>n;int x=0,cnt=0;while(x<=n&&x>=-n){cnt++;if(cnt%2==1){x-=(cnt*2-1);}else x+=(cnt*2-1);}if(cnt%2==1){cout<<"Sakurako"<<endl;}else{cout<<"Kosuke"<<endl;}
}
int main(){int t = 1;cin>>t;while(t--){solve();}return 0;
}
B. Sakurako and Water:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000][1000];
void solve(){int n,ans=0;cin>>n;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){cin>>a[i][j];}}for(int j=1;j<=n;j++){int res=0;int i=1;int x=i,y=j;while(x>=1&&x<=n&&y>=1&&y<=n){res=min(res,a[x][y]);x++;y++;}ans+=res;//cout<<ans<<endl;}for(int i=2;i<=n;i++){int res=0;int j=1;int x=i,y=j;while(x>=1&&x<=n&&y>=1&&y<=n){res=min(res,a[x][y]);x++;y++;}ans+=res;//cout<<ans<<endl;}ans=-1*ans;cout<<ans<<endl;
}
int main(){int t = 1;cin>>t;while(t--){solve();}return 0;
}
C. Sakurako's Field Trip:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
void solve(){int n,ans=0;cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}int l=n/2;for(int i=2;i<=l;i++){if(a[i]==a[i-1]&&a[i]!=a[n-i+1]){swap(a[i],a[n-i+1]);}if(a[i]!=a[i-1]&&a[i]!=a[n-i+1]){if(a[n-i+1]==a[n-i+2]){swap(a[i],a[n-i+1]);}}}for(int i=2;i<=n;i++){if(a[i]==a[i-1])ans++;}cout<<ans<<endl;
}
int main(){int t = 1;cin>>t;while(t--){solve();}return 0;
}
D. Kousuke's Assignment:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
void solve(){ll n,ans=0;cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}int i=0;ll res=0;map<ll,bool> mp;mp[0]=1;while(i<n){i++;res+=a[i];if(mp[res]){ans++;//cout<<a[i]<<endl;mp.clear();mp[0]=1;res=0;continue;}mp[res]=1;}cout<<ans<<endl;
}
int main(){int t = 1;cin>>t;while(t--){solve();}return 0;
}
E. Sakurako, Kosuke, and the Permutation:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000005],b[1000005];
bool book[1000005];
void solve(){ll n,ans=0;cin>>n;for(int i=1;i<=n;i++){cin>>a[i];b[a[i]]=i;book[i]=0;}for(int i=1;i<=n;i++){if(book[i])continue;if(a[i]==i){book[i]==1;}else{if(a[a[i]]==i){book[i]=1;book[a[i]]=1;continue;}//int tmp =a[i];b[a[a[i]]]=b[i];swap(a[a[i]],a[b[i]]);//cout<<endl;ans++;//cout<<i<<endl;book[i]=1;book[a[i]]=1;//cout<<i<<" "<<a[i]<<endl;}}cout<<ans<<endl;
}
int main(){int t = 1;cin>>t;while(t--){solve();}return 0;
}
后记:
五道题都是一遍过,直接给我写爽了,看来可以上一波分了,希望今年济南站也能这么顺利吧。