A
Problem - A - Codeforces
若要经过大写字母一定得先经过小写字母否则无法通过
AC代码:
/*
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)
*/
// #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 namespace std;
// using i64 = long long;
#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>
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 double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
void solve() {
string s;
cin >> s;
bool ok = true, ok1 = false, ok2 = false, ok3 = false;
int len = s.size();
for (int i = 0; i < len; i++) {
if (s[i] == 'r') {
ok1 = true;
}
else if (s[i] == 'b') {
ok2 = true;
}
else if (s[i] == 'g') {
ok3 = true;
}
else if (s[i] == 'R') {
if (!ok1) {
ok = false;
break;
}
}
else if (s[i] == 'B') {
if (!ok2) {
ok = false;
break;
}
}
else if (s[i] == 'G') {
if (!ok3) {
ok = false;
break;
}
}
}
cout << (ok ? "YES" : "NO") << endl;
return;
}
int main() {
IOS1;
//IOS2;
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/
B
Problem - B - Codeforces
要求输出不满足斐波那契数列的全排列,那第一个从1到n,后面的从n逐渐递减(不包括第一个),要求输出n行,因此不必考虑其他情况
AC代码:
/*
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)
*/
// #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 namespace std;
// using i64 = long long;
#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>
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 double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cout << i;
for (int j = n; j >= 1; j--) {
if (i != j) {
cout << " " << j;
}
}
cout << endl;
}
return;
}
int main() {
IOS1;
//IOS2;
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/
C
Problem - C - Codeforces
求最大子段和,前缀和
对数组a做前缀和
状态表示:
f [ i ? j + 1 ]:子段长度为i - j + 1的最大子段和
状态转移:
f [ i ? j + 1 ] = m a x ( f [ i ? j + 1 ] , s [ i ] ? s [ j ? 1 ] )?
假设增强了j次,统计最大子段的长度为i,那么最多增强m i n ( i , j ) 次,在所有的情况中取最大
AC代码:
/*
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)
*/
// #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 namespace std;
// using i64 = long long;
#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>
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 double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
return x < -eps ? -1 : x > eps;
}
void solve() {
int n, x;
cin >> n >> x;
vector<int> a(n + 5), sum(n + 5);
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
vector<int> f(n + 5, -INF);
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
f[i - j + 1] = max(f[i - j + 1], sum[i] - sum[j - 1]);
}
}
for (int i = 0; i <= n; i++) {
int res = 0;
for (int j = 0; j <= n; j++) {
res = max(res, f[j] + min(i, j) * x);
}
cout << res << " \n"[i == n];
}
return;
}
int main() {
IOS1;
//IOS2;
int __t = 1;
cin >> __t;
for (int _t = 1; _t <= __t; _t++) {
solve();
}
return 0;
}
/*
*/