vp时间
A.chaifen每一位,暴力搜索.x-N(1e9)不会超时
1.ac
B.二进制整除
被2整除只需要是偶数就好也就是pow(2,0)*0, (10)2
被4整除只需要是 (xxx100)2,
遍历从后往前.
把1往左移动即可
双指针,l找到1,r去找0算ans+=r-l;
1.wa4(没开ll)
2.ac
C.留一个位置为0,其他都加,这样有最大的成本
拿一个数组模拟,前缀和,离散化(qs)
忘记了。。
开map貌似可以
不会map = =
题解
A.
// Problem: A. Simple Design
// Contest: Codeforces - Codeforces Round 904 (Div. 2)
// URL: https://codeforces.com/contest/1884/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 1e9+10;
int chaifen(int x){
int res=0;
while(x){
res+=x%10;
x/=10;
}
return res;
}
void solve() {
int x,k;
cin>>x>>k;
if(chaifen(x)%k==0){
cout<<x<<'\n';
}else{
for(int i=x;i<=N;i++){
if(chaifen(i)%k==0){
cout<<i<<'\n';
return;
}
}
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
B.
// Problem: B. Haunted House
// Contest: Codeforces - Codeforces Round 904 (Div. 2)
// URL: https://codeforces.com/contest/1884/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void solve() {
ll n;
cin>>n;
string s;
cin>>s;
ll l=n,r=n;
ll ans=0;
for(int i=0;i<n;i++){
if(ans!=-1){
if(l>n-i && s[n-i]=='0'){
l--;
}else{
while(l>0 && s[l-1]=='1'){
l--;
}
if(l==0){
ans=-1;
}else{
ans+=r-l;
}
l--;
}
r--;
}
cout<<ans<<" ";
}
cout<<'\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
文章讲述了在Codeforces竞赛中两道问题(A.SimpleDesign和B.HauntedHouse)的解法,涉及暴力搜索、整除性质的利用、双指针技巧以及前缀和的计算,使用C++编程语言实现。

被折叠的 条评论
为什么被折叠?



