特别鸣谢,呜呜呜不厌其烦,不嫌我笨,一点一点给我讲题,呜呜呜哭死。
这是算真正意义上的复健之后第一次打,所以打的不怎么样也认了把,这一把掉了分,我也不说什么了,好好补题吧。
先来贴个链接。
Dashboard - Codeforces Round 910 (Div. 2) - Codeforces
然后。
分析
:的话,很显然的思路就是,我们去统计一下原给的字符串里面的数量。然后倒过来走就行了,很显然,无论是大于还是小于,我们通过一步操作就可以实现,等于的话,我们肯定是步操作,然后如果已有数量大于,我们就要从后往前遍历,到到为止,之前的全部变成,如果这个,那么我们就要就特判把所有变成。反之,同理吧,但是也要特判,我就因为这个麻了。
:题是个很好的思维题,逆向思维题,我开始时候一直正着想,一直想不出来,后来多亏了/拜谢/给我一点拨,我瞬间就发现了,倒推的话就是贪心模拟了,就是我们考虑最大值,初始化,这个值肯定最后一个数,倒数第二个数如果比后面一个数小或者等于,那么我们就略过,并且更新最大值为这个数。否则,我们就要分解了,那么怎么分解最好呢,肯定是分成两个最接近的数,也就是下去整,那么我们需要分解的次数就是(当前数/最大值)上取整,然后把最大值更新成下取整。很有趣的一道题。
:是一个思维题吧,也是很有耐心地讲给我听,不然我这个笨比根本不可能会的。迟来的一篇更文,现在已经是凌晨了,我还在码着这个题,bcjjj的思路喂给我了属于是,这还是第一次我贴个这么丑的图。 然后也贴个教我的截图吧,我觉得我的这个代码完全就是按照她的来的。
我只做了一点的变化,就是我分了三种情况,因为显然我那个图上不存在这一种情况。然后就是令人吐血的细节实现,我真想骂人了,开始交了了,我都要崩溃了,后来发现其实是图画的太片面了,下面那种情况的属性取决于前一种情况。
:其实是一个偏数学的题,看似简单,其实也有很多玄机,这个思路就是考虑当然也有可能是区间,长度是,然后我们可以通过基本的画图数学性质发现如果要使得我们答案增加,就要找到最小的右端点和最大的左端点之间的距离,如果这个值是正数,我们就加到答案上去,否则,答案不变。(一切皆通过画图发现,)。
代码
:
//写的雪薇有点丑。
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
int t;
void solve(){
int n,k;
string s;
cin>>n>>k>>s;
int ans=0;
for(int i=0;i<s.size();i++){
if(s[i]=='B') ans++;
}
if(ans==k){
cout<<0<<"\n";
return;
}
if(k==n){
int len=s.size();
cout<<1<<"\n";
cout<<len<<" B\n";
return;
}
int res=0;
if(ans<k){
cout<<1<<"\n";
for(int i=s.size()-1;i>=0;i--){
if(s[i]=='B') res++;
if(res+i==k){
cout<<i<<" "<<"B\n";
return;
}
}
}
else{
res=0;
cout<<1<<"\n";
for(int i=s.size()-1;i>=0;i--){
if(res==k){
cout<<i+1<<" "<<"A\n";
return;
}
if(s[i]=='B') res++;
}
}
}
int main(){
IOS;
cin>>t;
while(t--) solve();
}
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
int t;
const int N=200010;
int a[N],n;
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
reverse(a+1,a+n+1);
int maxn=a[1];
ll ans=0;
for(int i=2;i<=n;i++){
if(maxn>=a[i]){
maxn=a[i];
continue;
}
int c=(a[i]+maxn-1)/maxn-1;
ans+=c;
//if(a[i]%maxn){//这里可以不需要。
maxn=a[i]/(c+1);
// }
//maxn=a[i]/c;
}
cout<<ans<<endl;
}
int main(){
IOS;
cin>>t;
while(t--) solve();
}
:
//也雪薇有那么一点点丑()
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
int n,m,k,t;
char a1[20][20],a2[20][20];
void solve(){
cin>>n>>m>>k;
for(int i=1;i<20;i++){
for(int j=1;j<20;j++){
a1[i][j]='.';
}
}
for(int i=1;i<20;i++){
for(int j=1;j<20;j++){
a2[i][j]='.';
}
}
if(k<n+m-2 || (k%2)!=(n+m-2)%2){
cout<<"NO\n";
return;
}
cout<<"YES\n";
int t=k-(n+m-2);
for(int i=1;i<=m-1;i++){
if(i==1){
if(n%2==0) a1[n][i]='B';
else a1[n][i]='R';
}
else{
if(a1[n][i-1]=='B') a1[n][i]='R';
else a1[n][i]='B';
}
}
for(int i=1;i<=n-1;i++){
if(i==1) a2[i][1]='R';
else{
if(a2[i-1][1]=='B') a2[i][1]='R';
else a2[i][1]='B';
}
}
if(t==0){}
else if(t%4==2){
a1[1][1]=a1[2][1]='R';
a2[1][1]=a2[1][2]='B';
}
else{
a1[1][1]=a1[2][1]='R';
a2[1][1]=a2[1][2]='B';
if(a1[n][m-2]=='B'){
a1[n][m-1]=a1[n-1][m-1]='B';
a2[n-1][m-1]=a2[n-1][m]='R';
}
else{
a1[n][m-1]=a1[n-1][m-1]='R';
a2[n-1][m-1]=a2[n-1][m]='B';
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m-1;j++){
if(a1[i][j]=='.') cout<<"B ";
else cout<<a1[i][j]<<" ";
}
cout<<endl;
}
for(int i=1;i<=n-1;i++){
for(int j=1;j<=m;j++){
if(a2[i][j]=='.') cout<<"B ";
else cout<<a2[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
IOS;
cin>>t;
while(t--) solve();
}
:
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
const int N=300010,M=2*N;
int t;
int a[N],n,b[N];
void solve(){
cin>>n;
int maxn=0,minn=0x3f3f3f3f;
ll ans=0;
int ansm1=0,ansm2=0,id1=0,id2=0;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
ans+=abs(a[i]-b[i]);
if(a[i]<=b[i]){
maxn=max(a[i],maxn);
minn=min(minn,b[i]);
}
else{
maxn=max(b[i],maxn);
minn=min(minn,a[i]);
}
}
if(maxn-minn>0) ans+=2*maxn-2*minn;
cout<<ans<<endl;
}
int main(){
IOS;
cin>>t;
while(t--) solve();
}
总结
浅浅总结一下吧,打了很久的算法竞赛,也名义上很努力地打了很多次和,但是第一次这么认真的补题还没有过,说来真的挺遗憾的,这应该也就是我一直迟迟不能变强的原因吧,昨天和聊天的时候略带自嘲地说出我去年五月第一次打当时开出了,超级超级开心,然后现在也就是昨天(准确来说应该是呃前天),我还是只开出了,哈哈哈,嘴上笑嘻嘻,心理也知道,我之前光顾着水群,写简单题,吐槽啥的,留下了很多的遗憾,希望下个赛季能慢慢弥补吧!