Problem - A - Codeforces
签到题,要剩下的字母必须在奇数位才可能不被删除
AC代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using i64 = long long;
using namespace std;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b >>= 1, a = a * a) {
if (b & 1) {
res = res * a;
}
}
return res;
}
template <typename T>
T Myabs(T a) {
return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
x = 0; int f = 1; char ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
/*
Tips:
1.int? long long?
2.don't submit wrong answer
3.figure out logic first, then start writing please
4.know about the range
5.check if you have to input t or not
6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
void solve() {
string s;
cin >> s;
char x;
cin >> x;
int len = s.size();
bool ok = false;
for (int i = 0; i < len; i++) {
if (s[i] == x && !(i & 1)) {
ok = true;
break;
}
}
cout << (ok ? "YES" : "NO") << endl;
return;
}
signed main() {
IOS1;
// IOS2;
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/
Problem - B - Codeforces
需要特判a=1的情况,其他情况分析能不能找到一个%后为a-1的情况,如果凑不出来,说明区间长度小于a,那么其实就需要判断左右端点套进f式中的值的大小,否则就是判断%后为a-1的那个点和右端点套进f式的大小
AC代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using i64 = long long;
using namespace std;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b >>= 1, a = a * a) {
if (b & 1) {
res = res * a;
}
}
return res;
}
template <typename T>
T Myabs(T a) {
return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
x = 0; int f = 1; char ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
/*
Tips:
1.int? long long?
2.don't submit wrong answer
3.figure out logic first, then start writing please
4.know about the range
5.check if you have to input t or not
6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
void solve() {
int l, r, a;
cin >> l >> r >> a;
if (a == 1) {
cout << r << endl;
}
else {
int x = r / a * a - 1;
if (x < l) {
x = l;
}
cout << max(x / a + x % a, r / a + r % a) << endl;
}
return;
}
signed main() {
IOS1;
// IOS2;
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/
Problem - C - Codeforces
C题很明显的贪心,先对权进行排序,然后得出答案的和,然后将这些边权对应的输入的顺序和在x轴上的位置存一下并按照在x轴上的位置进行排序,最后双指针一前一后输出就行了
AC代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using i64 = long long;
using namespace std;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b >>= 1, a = a * a) {
if (b & 1) {
res = res * a;
}
}
return res;
}
template <typename T>
T Myabs(T a) {
return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
x = 0; int f = 1; char ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
/*
Tips:
1.int? long long?
2.don't submit wrong answer
3.figure out logic first, then start writing please
4.know about the range
5.check if you have to input t or not
6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
struct node {
int x, w, id;
};
bool cmp1(node x, node y) {
if (x.w == y.w) {
return x.id < y.id;
}
return x.w < y.w;
}
void solve() {
int n, m;
cin >> n >> m;
vector<node> a(m);
vector<pair<int, int>> e;
for (int i = 0; i < m; i++) {
cin >> a[i].x >> a[i].w;
a[i].id = i + 1;
}
sort(a.begin(), a.end(), cmp1);
i64 ans = 0;
for (int i = 0; i < 2 * n; i++) {
ans += a[i].w;
e.emplace_back(a[i].x, a[i].id);
}
sort(e.begin(), e.end());
int len = e.size();
cout << ans << endl;
for (int i = 0, j = len - 1; i < j; i++, j--) {
cout << e[i].second << " " << e[j].second << endl;
}
return;
}
signed main() {
IOS1;
// IOS2;
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/
Problem - D - Codeforces
小模拟,对vector进行反转记得用rotate()函数,省的自己写了一大坨进行反转,题目意思就是转一下就把第i个数扔到最前面,然后给你扔完以后的让你数一数在第i个位置扔了多少次
AC代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using i64 = long long;
using namespace std;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b >>= 1, a = a * a) {
if (b & 1) {
res = res * a;
}
}
return res;
}
template <typename T>
T Myabs(T a) {
return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
x = 0; int f = 1; char ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
/*
Tips:
1.int? long long?
2.don't submit wrong answer
3.figure out logic first, then start writing please
4.know about the range
5.check if you have to input t or not
6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
vector<int> ans;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i > 0; i--) {
bool ok = true;
for (int j = n; j >= i; j--) {
if (a[j] != i) {
ok = false;
break;
}
}
if (ok) {
ans.emplace_back(0);
continue;
}
int cnt = 0;
int sign = 1;
for (int j = 1; j <= n; j++) {
if (a[j] == i) {
cnt = j;
sign = j;
if (j == i) {
cnt = 0;
}
break;
}
}
int c = i - sign;
vector<int> b(n + 1);
for (int k = 1, j = sign + 1; j <= i; j++, k++) {
b[k] = a[j];
}
for (int j = sign; j >= 1; j--) {
a[j + c] = a[j];
}
for (int k = 1; k <= i - sign; k++) {
a[k] = b[k];
}
ans.emplace_back(cnt);
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < n; i++) {
cout << ans[i] << " \n"[i == n - 1];
}
return;
}
signed main() {
IOS1;
// IOS2;
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/
jls代码,写的比我的模拟简洁多了QAQ:
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n;
std::cin >> n;
std::vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = n - 1; i >= 0; i--) {
int j = std::find(a.begin(), a.end(), i + 1) - a.begin();
b[i] = (j + 1) % (i + 1);
std::rotate(a.begin(), a.begin() + j + 1, a.begin() + i + 1);
}
for (int i = 0; i < n; i++) {
std::cout << b[i] << " \n"[i == n - 1];
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
rotate(1,2,3),将2到3之间的内容放在1的前面