Codeforces Round 944 (Div. 4)
Codeforces Round 944 (Div. 4)
A. My First Sorting Problem
签到题
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define haha puts("")
#define ye puts("Yes")
#define no puts("No")
const int N = 1e6 + 10;
const int M = 10100;
const int mod = 998244353;
double pi = acos(-1);
int dx[10] = {-1, 0, 1, 0};
int dy[10] = {0, 1, 0, -1};
int n, m, k;
int cnt = 0;
int a[N];
set<int> se;
map<int, int> mp;
bool st[N];
vector<int> v[N];
void solve() {
int x, y;
cin >> x >> y;
if (x >= y) {
cout << y << ' ' << x << '\n';
} else {
cout << x << ' ' << y << '\n';
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// init();
cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/
B. Different String
一开始没看到要输出处理好的字符串,一下没想到最优的方法卡了一会
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define haha puts("")
#define ye puts("Yes")
#define no puts("No")
const int N = 1e6 + 10;
const int M = 10100;
const int mod = 998244353;
double pi = acos(-1);
int dx[10] = {-1, 0, 1, 0};
int dy[10] = {0, 1, 0, -1};
int n, m, k;
int cnt = 0;
int a[N];
set<int> se;
map<int, int> mp;
bool st[N];
vector<int> v[N];
void solve() {
string s;
cin >> s;
map<char, int> mp;
set<char> se;
string sr;
for (int i = 0; i < s.size(); i++) {
se.insert(s[i]);
mp[s[i]]++;
}
int f = 0;
if (se.size() == 1) {
no;
} else {
ye;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < s.size(); j++) {
if (s[i] != s[j]) {
swap(s[i], s[j]);
cout << s << '\n';
return;
}
}
}
}
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// init();
cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/
C. Clock and Strings
分类讨论
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define haha puts("")
#define ye puts("Yes")
#define no puts("No")
const int N = 1e6 + 10;
const int M = 10100;
const int mod = 998244353;
double pi = acos(-1);
int dx[10] = {-1, 0, 1, 0};
int dy[10] = {0, 1, 0, -1};
int n, m, k;
int cnt = 0;
int a[N];
set<int> se;
map<int, int> mp;
bool st[N];
vector<int> v[N];
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a > c) {
swap(a, c);
swap(b, d);
}
if (a > b) swap(a, b);
if (c > d) swap(c, d);
if (a == c || b == d || a == d || c == b) {
ye;
} else {
if (c > a && c < b) {
if (d > b || d < a)
ye;
else
no;
} else {
if (d > a && d < b)
ye;
else
no;
}
}
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// init();
cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/
D. Binary Cut
太草了,读假了。。。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define haha puts("")
#define ye puts("Yes")
#define no puts("No")
const int N = 1e6 + 10;
const int M = 10100;
const int mod = 998244353;
double pi = acos(-1);
int dx[10] = {-1, 0, 1, 0};
int dy[10] = {0, 1, 0, -1};
int n, m, k;
int cnt = 0;
int a[N];
set<int> se;
map<int, int> mp;
bool st[N];
vector<int> v[N];
void solve() {
string a;
cin >> a;
int ans = 1;
for (int i = 1; i < a.size(); i++)
if (a[i] != a[i - 1]) ans++;
if (ans == 1) {
cout << 1 << '\n';
return;
}
if (a[0] == '0' || ans > 2)
cout << ans - 1 << '\n';
else
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// init();
cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
6
11010
00000000
1
10
0001111
0110
3
1
1
2
1
2
*/
E. Find the Car
注意精度和二分,全用 \(int\) 就可以,一直用\(long double\)疯狂卡题,然后发现二分也错了一步。。。后来全改成\(int\),又改了二分才过。。。
毒瘤
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define haha puts("")
#define ye puts("Yes")
#define no puts("No")
const int N = 1e6 + 10;
const int M = 10100;
const int mod = 998244353;
double pi = acos(-1);
int dx[10] = {-1, 0, 1, 0};
int dy[10] = {0, 1, 0, -1};
int n, m, k;
int cnt = 0;
int a[N];
set<int> se;
map<int, int> mp;
bool st[N];
//vector<int> v[N];
int b[N];
int v[N];
void solve() {
int q;
cin >> n >> k >> q;
for (int i = 1; i <= k; i++) {
cin >> a[i];
}
for (int i = 1; i <= k; i++) {
cin >> b[i];
}
for (int i = 1; i <= k; i++) {
v[i] = (a[i] - a[i - 1]) / (b[i] - b[i - 1]);
}
while (q--) {
int d;
cin >> d;
if (d == n) {
cout << b[k] << ' ';
} else if (d == 0) {
cout << 0 << ' ';
} else {
int l = upper_bound(a + 1, a + 1 + k, d) - a;
cout << b[l - 1] + 1ll * (d - a[l - 1]) * (b[l] - b[l - 1]) / (a[l] - a[l - 1]) << ' ';
}
}
cout << '\n';
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// init();
cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/