前言:
这周真的有点懒,打完比赛基本没补题,最近聚会有点多,希望下周能调整好时间
1第三场比赛
1.CodeForces - 1791C
0和1作为字符使用时要加单引号
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int cnt = n;
string s;
cin >> s;
if(s.empty()){
cout << 0 << endl;
}
while(s.size() > 1){
if((s[0] == '0' && s[s.size()-1] == '1') || (s[0] == '1' && s[s.size()-1] == '0')){
s.erase(s.size()-1,1);//这里的0和1没写单引号
s.erase(0,1);
cnt -= 2;
}else{
break;
}
}
cout << cnt << endl;
}
return 0;
}
2.CodeForces - 1791A
暴力即可
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int main() {
int t;
cin >> t;
string s = "codeforces";
for(int i = 0; i < t; i ++){
char a;
cin >> a;
bool b = false;
for(int i = 0; i < s.size(); i ++){
if(a == s[i]){
b = true;
break;
}
}
if(b){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}
3.CodeForces - 1807C
只有相同的两个字符中间必须间隔为奇数才能输出yes
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
string s;
cin >> s;
bool res = false;
for(int i = 0; i < n; i ++){
bool ok = false;
for(int j = i + 1; j < n; j ++){
if(s[i] == s[j]){
int temp = j - i;
if(temp % 2 != 0){
ok = true;
break;
}
}
}
if(ok){
res = true;
break;
}
}
if(res){
cout << "NO" << endl;
}else{
cout << "YES" << endl;
}
}
return 0;
}
4.CodeForces - 1807B
直接比较奇数个数和偶数个数
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int s = 0;
int r = 0;
for(int i = 0; i < n; i ++){
int b;
cin >> b;
if(b % 2 == 0){
s += b;
}else{
r += b;
}
}
if(s > r){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}
2.第四场比赛
1.CodeForces - 1873C
只要把所有范围框定起来即可
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int main() {
int t;
cin >> t;
char a[110][110];
while(t--){
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int cnt4 = 0;
int cnt5 = 0;
for(int i = 1; i <= 10; i ++){
for(int j = 1; j <= 10; j ++){
char b;
cin >> b;
a[i][j] = b;
if(a[i][j] == 'X'){
if(i == 1 || j == 1 || i == 10 || j == 10){
cnt1 ++;
}
if((i == 2 && j > 1 && j < 10) || (i == 9 && j > 1 && j < 10) ||
(j == 2 && i > 1 && i < 10) || (j == 9 && i > 1 && i < 10)){
cnt2 ++;
}
if((i == 3 && j > 2 && j < 9) || (i == 8 && j > 2 && j < 9) ||
(j == 3 && i > 2 && i < 9) || (j == 8 && i > 2 && i < 9)){
cnt3 ++;
}
if((i == 4 && j > 3 && j < 8) || (i == 7 && j > 3 && j < 8) ||
(j == 4 && i > 3 && i < 8) || (j == 7 && i > 3 && i < 8)){
cnt4 ++;
}
if((i == 5 && j > 4 && j < 7) || (i == 6 && j > 4 && j < 7) ||
(j == 5 && i > 4 && i < 7) || (j == 6 && i > 4 && i < 7)){
cnt5 ++;
}
}
}
}
int res = cnt1 * 1 + cnt2 * 2 + cnt3 * 3 + cnt4 * 4 + cnt5 * 5;
cout << res << endl;
}
return 0;
}
2. CodeForces - 1873D
一开始以为时双指针,后面发现其实一个就行
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n,k;
cin >> n >> k;
string s;
cin >> s;
int cnt = 0;
for(int i = 0; i < n; i ++){
if(s[i] == 'B'){
cnt ++;
i = i + (k - 1);
}
}
cout << cnt << endl;
}
return 0;
}
3.CodeForces - 1873B
数据范围较小,直接暴力
#include<bits/stdc++.h>
#define ll long long
const long long N = 1e9 + 10;
using namespace std;
int max1(vector<ll> &s,int n){
ll r = 1;
for(int i = 0; i < n; i ++){
r *= s[i];
}
return r;
}
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<ll>s;
for(int i = 0; i < n; i ++){
int a;
cin >> a;
s.push_back(a);
}
vector<ll>b;
for(int i = 0; i < n; i ++){
b.push_back(s[i]);
}
ll max = 0;
for(int i = 0; i < n; i ++){
s[i] = s[i] + 1;
ll res = max1(s,n);
if(res > max){
max = res;
}
s[i] = b[i];
//cout << res << ' ';
}
cout << max << endl;
}
return 0;
}
706

被折叠的 条评论
为什么被折叠?



