Educational Codeforces Round 147 (Rated for Div. 2)
链接
Educational Codeforces Round 147 (Rated for Div. 2)
A题
-
如果第一位数是0,直接打印0
-
如果第一位数是'?',有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题
- 先找到两个数组第一个不同的数为l,然后找到两个数组最后一个不同的数为r.
- 然后判断l,和r能不能继续扩展,如果可以把l 和 r都扩展到最大
- 打印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