Codeforces Round 863 (Div. 3)
链接
A题
遍历这个字符串,如果要插入的数第一次小于当前的数,就将数插入到这里,如果到最后都没有插入数,插入到最后
#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() {
int n, x;
scanf("%lld %lld", &n, &x);
string s;
cin >> s;
int flag = 0;
for (int i = 0; i < (int)s.size(); i++) {
if (x > (s[i] - '0') && flag == 0) {//如果从来没插入过,并且大于当前的数字
cout << x << s[i];//打印x和s[i]
flag++;
} else {
cout << s[i];//否则只打印当前的s[i]
}
}
if (flag == 0) {//没有打印过x
cout << x;//在最后打印
}
cout << '\n';
}
signed main () {
int t;
cin >> t;
while (t) {
solve();
t--;
}
return 0;
}
B题
比赛的时候看错题了,现在感觉好像看对也写不出来
这个题其实就是问两个点相距多少层,将两层相减取绝对值就可以.现在是怎么求出这个点所在的层数,可以发现点(x,y)和边界的距离最短的那个就是层数,就是min(x,y,n-x+1,n-y+1)的值.
#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() {
int n;
cin >> n;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int a = min(min(x1, y1), min(n - x1 + 1, n - y1 + 1));//求x1,y1的层数
int b = min(min(x2, y2), min(n - x2 + 1, n - y2 + 1));//求x2,y2的层数
printf("%lld\n", abs(a - b));//打印abs(a-b);
}
signed main () {
int t;
cin >> t;
while (t) {
solve();
t--;
}
return 0;
}
标签:y2,min,int,863,Codeforces,x2,Div,include,x1
From: https://www.cnblogs.com/harper886/p/17290877.html