這次做了ABCD,今天下午就要上學(xué)去了溜了溜了,早上起來補的題解。
A - String Similarity
分析可知可構(gòu)造w[i]=s[2*i]即可滿足題意
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std
;
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
;cin
>>n
;string s
;cin
>>s
;string w
;for(int i
=0;i
<n
;i
++) w
+=s
[2*i
];cout
<<w
<<endl
;}return 0;
}
B - RPG Protagonist
枚舉+貪心
這題很有意思,昨天做的時候群友許多都說C比B簡單,不過我B是1A,而Cwa2次
剛開始想了很久確實沒啥思路,但是一看數(shù)據(jù)范圍2?1052·10^52?105好像直接可以枚舉數(shù)量。對于題目不妨設(shè)s≥ws \ge ws≥w,如果s<ws<ws<w可以交換一下,從集合角度考慮,最優(yōu)解一定是一個人拿了aaa個sss,bbb個www,另一個人拿了ccc個sss,ddd個www,因此可以考慮枚舉第一個人拿sss的數(shù)目,然后b,c,db,c,db,c,d貪心可以算出來。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std
;
typedef long long ll
;
ll p
,f
;
ll cntw
,cnts
;
ll s
,w
;
int main()
{IO
;int T
;cin
>>T
;while(T
--){cin
>>p
>>f
;cin
>>cnts
>>cntw
;cin
>>s
>>w
;if(s
<w
) swap(s
,w
),swap(cnts
,cntw
);ll maxs
=p
/s
;ll res
=0;for(int i
=0;i
<=min(maxs
,cnts
);i
++){ll a
=i
,b
=min(cntw
,(p
-i
*s
)/w
);ll d
=min(f
/w
,cntw
-b
);ll c
=min((f
-d
*w
)/s
,cnts
-i
);res
=max(res
,a
+b
+c
+d
);}cout
<<res
<<endl
;}return 0;
}
C - Binary String Reconstruction
這題看錯題了我暈😵
題目規(guī)則給你www可以構(gòu)造出sss,然后給你sss讓你給出個www結(jié)果看反了
注意字符串下標(biāo)從1開始
然后就成了個分類討論的模擬題。
如果s[i]=='1'說明w[i-x]=='1'||w[i+x]=='1'
如果s[i]=='0'說明w[i-x]=='0'&&w[i+x]=='0'
然后細節(jié)討論一下即可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std
;
typedef long long ll
;
typedef pair
<int,int> pii
;
int w
[100010];
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
,x
;string s
;cin
>>s
;n
=s
.size();cin
>>x
;s
='0'+s
;for(int i
=0;i
<=n
+1;i
++) w
[i
]=-1;bool ok
=1;for(int i
=1;i
<=n
;i
++){if(!ok
) break;if(s
[i
]=='1'){if(i
>x
) {if(w
[i
-x
]==0){if(x
+i
<=n
&&w
[i
+x
]!=0) w
[i
+x
]=1;else ok
=0;}else w
[i
-x
]=1;}else if(x
+i
<=n
) {if(w
[i
+x
]==0) ok
=0;else w
[x
+i
]=1;}else ok
=0;}else{if(i
>x
) {if(w
[i
-x
]==1) ok
=0;else w
[i
-x
]=0;}if(x
+i
<=n
){if(w
[i
+x
]==1) ok
=0;else w
[x
+i
]=0;}}}if(!ok
) cout
<<-1<<endl
;else{for(int i
=1;i
<=n
;i
++){if(w
[i
]!=-1) cout
<<w
[i
];else cout
<<0;}cout
<<endl
;}}return 0;
}
D - Zigzags
數(shù)據(jù)范圍n≤3000n\leq 3000n≤3000那么n2n^2n2就可以解決
枚舉j,lj,lj,l維護a[i]a[i]a[i]出現(xiàn)的次數(shù),i<ji<ji<j掃一遍即可。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std
;
const int N
=3010;
int a
[N
],cnt
[N
];
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
;cin
>>n
;for(int i
=1;i
<=n
;i
++){cin
>>a
[i
];cnt
[i
]=0;}ll res
=0;for(int j
=1;j
<=n
;j
++) {ll s
=0;for(int l
=j
+1;l
<=n
;l
++){if(a
[l
]==a
[j
]) res
+=s
;s
+=cnt
[a
[l
]];}cnt
[a
[j
]]++;}cout
<<res
<<endl
;}return 0;
}
E - Clear the Multiset
CF原題不過雖然題目是原題但是人是新人啊hhh
對于操作2除非將某一堆歸零,否則即為無效操作
因此考慮對[l,r][l,r][l,r]序列使用操作2直接讓將某一個數(shù)清空,然后遞歸處理子問題即可詳細可以參考知乎大佬講解
鋪設(shè)道路這題同樣可以使用分治方法,之前用的是貪心。
該題前置題?積木大賽
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std
;
const int N
=5010;
int n
;
int a
[N
];
int solve(int l
,int r
)
{if(l
>r
) return 0;if(l
==r
) return a
[l
]==0?0:1;int now
=1e9+1;int k
;for(int i
=l
;i
<=r
;i
++)if(a
[i
]<now
){now
=a
[i
];k
=i
;}for(int i
=l
;i
<=r
;i
++) a
[i
]-=now
;return min(now
+solve(l
,k
-1)+solve(k
+1,r
),r
-l
+1);
}
int main()
{IO
;cin
>>n
;for(int i
=1;i
<=n
;i
++) cin
>>a
[i
];cout
<<solve(1,n
)<<endl
;return 0;
}
要加油哦~
總結(jié)
以上是生活随笔為你收集整理的Educational Codeforces Round 94 (Rated for Div. 2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。