Codeforces Round 904 (Div. 2) (VP-3,寒假加训)

文章讲述了在Codeforces竞赛中两道问题(A.SimpleDesign和B.HauntedHouse)的解法,涉及暴力搜索、整除性质的利用、双指针技巧以及前缀和的计算,使用C++编程语言实现。

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;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值