首页 > 其他分享 >Educational Codeforces Round 147 (Rated for Div. 2)

Educational Codeforces Round 147 (Rated for Div. 2)

时间:2023-04-21 22:22:25浏览次数:52  
标签:147 Educational Rated int Codeforces -- include

Educational Codeforces Round 147 (Rated for Div. 2)

链接

Educational Codeforces Round 147 (Rated for Div. 2)

A题

  1. 如果第一位数是0,直接打印0

  2. 如果第一位数是'?',有9个数可以选择,如果其他位数是'?',有10中情况选择,相乘就可以了

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 100008;

void solve() {

	string s;
	cin >> s;
	if (s[0] == '0') {//第1位是0直接打印0
		cout << 0 << '\n';
		return;
	}
	int sum = 1;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == '?') {//如果第一位是?,有9中情况可以选择
			if (i == 0) {
				sum = sum * 9;
			} else {
				sum = sum * 10;//其他如果是?,有10中情况选择
			}
		}
	}
	cout << sum << '\n';//打印






}
signed main () {
	std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
	int t;
	cin >> t;
	while (t) {
		solve();
		t--;
	}


	return 0;
}

B题

  1. 先找到两个数组第一个不同的数为l,然后找到两个数组最后一个不同的数为r.
  2. 然后判断l,和r能不能继续扩展,如果可以把l 和 r都扩展到最大
  3. 打印l和r
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 200008;
int a[N];
int b[N];
void solve() {
//	int ans = 0;
	int n;
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);

	}
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &b[i]);
	}
	int l = 0, r = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] != b[i]) {
			l = i;//找到l
			break;
		}
	}
	for (int i = n; i >= 1; i--) {
		if (a[i] != b[i]) {
			r = i;//找到r
			break;
		}
	}
	int mmin = min(a[l], b[l]);//取a[l]和b[l]的较小值
	int mmax = max(a[r], b[r]);//取a[l]和b[l]的较大值
	a[l] = mmin;
	b[l] = mmin;//对两个数组赋值
	for (int i = l; i >= 2; i--) {//如果前一个数小于当前的数,就可以向前扩展
		if (a[i] >= a[i - 1]) {
			l--;
		} else {
			break;//不满足直接跳出
		}
	}
	a[r] = mmax;
	b[r] = mmax;
	for (int i = r; i <= n - 1; i++) {//如果后一个数大于当前的数,就可以向后扩展
		if (a[i] <= a[i + 1]) {
			r++;
		} else {
			break;//不满足直接跳出
		}
	}

	cout << l << ' ' << r << '\n';//打印l和r




}
signed main () {
//	std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
	int t;
	cin >> t;
	while (t) {
		solve();
		t--;
	}


	return 0;
}


标签:147,Educational,Rated,int,Codeforces,--,include
From: https://www.cnblogs.com/harper886/p/17342037.html

相关文章

  • Educational Codeforces Round 113 (Rated for Div. 2)
    题目链接B核心思路这个题目我觉得很好。首先分析下吧,如果有人需要执行操作二那么我们肯定就是给他们都打上平局是最优的。那么如果有人需要执行操作一呢,那么我们就可以把这些需要执行操作1的都搞一起。然后是他们成一个环。这样肯定就保证了每个人都会赢上一次。C核心思路......
  • [Educational Codeforces Round 118 (Rated for Div. 2)]题解
    A题意:给定两个数,每一个数有两个属性,第一个属性是p1,第二个属性是p2.表示这个数有p2个后缀0.这个数本身等于p1后面加p2个0.问给你两个这种数,判断大小。思路:赛场上想到的:如果最终的长度不一样,可以直接根据长度判断。如果相等,就把后缀0加上直接比较大小就可以(比较字典序的大小),但......
  • Educational Codeforces Round 110 (Rated for Div. 2) C. Unstable String(状态机)
    https://codeforces.com/contest/1535/problem/C题目大意:给定一个字符串s,由10?组成:?每次都可以任意替换成0或者1问我们这个子字符串中,能够组成010101这样两两互不相等的字符串的数量最大是多少?input30?10????10??1100output8625#include<bits/stdc++.h>usin......
  • Educational Codeforces Round 120 (Rated for Div. 2)
    题目链接C核心思路这是一个很好的二分的题目,首先我们判断题目可不可二分,很显然是可以的把。因为假设我们x是可以的话,x+1...肯定也是可以的,但是x-1,x-2....这些又是不可以的。好,接下来思考二分刚开始的左右边界,左边届很好想,关键是右边界。这个其实也不难。因为我们最坏肯定是全......
  • CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound2(Div.1+Div.2,Rated,Prizes!)A.Two0-1Sequencesvoidsolve(){intn=read(),m=read(),ans=1;strings,t;cin>>s>>t;//cout<<s<<t<<endl;for(inti=t.size()-1,j=s.size()-1;i>=1&......
  • Educational Codeforces Round 146 (Rated for Div. 2)
    Preface补题ing值得一提的时补这场的时候先是遇上了CF的12小时大维护,后面又遇到了评测机崩了测不了也是有点有意思的说A.Coins傻逼题,首先考虑\(2|n\)时一定有解\(x=\frac{n}{2},y=0\),否则若\(2\nmidn\and2|k\)则由裴蜀定理知此时一定无解否则\(y\)必为奇数,我们令\(x=\fra......
  • CF1473D 题解
    题目传送门题目分析线段树、前缀和、\(\text{ST}\)表题解都有了,我补一发猫树题解吧。由于每次操作只能将大小改变成跟原来差\(1\),所以只需要知道这段操作中的最大值和最小值,最后所求的答案的范围就被卡住了。对于每一次操作,我们把操作序列拦腰斩断,那么分别求两边的范围,最后减......
  • [C++]LeetCode1147. 段式回文
    [C++]LeetCode1147.段式回文题目描述Difficulty:困难RelatedTopics:贪心,双指针,字符串,动态规划,哈希函数,滚动哈希你会得到一个字符串text。你应该把它分成k个子字符串(subtext1,subtext2,…,subtextk),要求满足:subtexti是非空字符串所有子字符串的连接......
  • Do you know the bitwise sum sample demonstrated in "Neural Networks and Deep Lea
    Doyouknowthebitwisesumsampledemonstratedin"NeuralNetworksandDeepLearning"byautor MichaelNielsen?Yes,Iamfamiliarwiththebitwisesumexampledemonstratedin"NeuralNetworksandDeepLearning"byMichaelNielsen......
  • Edu Round 板刷计划 4. Educational Codeforces Round 4 题解
    ChangeLog:2023.04.06开坑.A-TheTextSplitting弱智题.枚举分出来多少个长度为\(p\)的串,则能计算出长度为\(q\)的串有多少个,若合法则直接输出即可.无解输出-1.Samplesubmission.B-HDDisOutdatedTechnology比A还弱智.直接记录每个数的位置,然后模拟一......