前言
直接放代码吧,这一场可以说打的充实 (累死了)
题解有缘在补,明天又是一堆课
A.
void solve()
{
int a,b;cin>>a>>b;
if(!a && !b){
cout<<1<<endl;
return;
}
if(!a){
cout<<1<<endl;
return;
}
if(!b){
cout<<a+1<<endl;
return;
}
cout<<(a+b*2)+1<<endl;
}
B.
const int N = 2e5+10;
int a[N];
void solve()
{
int n;cin>>n;
int maxn = 0 ;
for(int i=1;i<=n;i++){
cin>>a[i];
maxn = max(maxn,a[i]);
}
int cnt = 0 ;
for(int i=1;i<=n;i++){
if(a[i] == maxn-1){
cout<<"YES"<<endl;
return;
}
if(a[i] == maxn){
++cnt;
}
}
if(cnt >=2 || (n == 1 && a[1] == 1)){
cout<<"YES"<<endl;
return;
}
cout<<"NO"<<endl;
}
C.
const int N = 310;
string s;
int pre[N];
void solve()
{
memset(pre,0,sizeof pre);
cin>>s;
int ans = 0 ;
int len = s.size();
for(int i=0;i<len; i ++ ){
int t = i + 1;
if(!pre[s[i]]){
pre[s[i]] = 1;
}else{
ans --;
for(int i='a';i<='z';i++){
if(pre[i]){
pre[i] = 0 ;
++ans;
}
}
}
}
for(int i='a';i<='z';i++){
if(pre[i]){
pre[i] -- ;
++ans;
}
}
cout<<ans<<endl;
}
D.
int n;
vector<int> a,z;
int cal(vector<int>&a,int l,int r,int &tl,int &tr){
if(l>r) return 0;
int cnt = 0 , cnt2 =0 ;
for(int i=l;i<=r;i++){
if(a[i]<0)++cnt;
}
for(int i=l;i<=r;i++){
if(abs(a[i]) == 2) ++cnt2;
}
if(cnt%2 == 0){
tl = 0;
tr = 0 ;
return cnt2;
}
int sum1 =0 ;
int sum2 = 0;
int t1 = 0 ;
int t2 = 0 ;
for(int i=l;i<=r;i++){
if(abs(a[i]) == 2) sum1++;
if(a[i]<0){
t1 = i ;
break;
}
}
for(int i=r;i>=l;i -- ){
if(abs(a[i]) == 2) sum2++;
if(a[i]<0){
t2 = i;
break;
}
}
if(sum1 > sum2){
tl = 0 ;
tr = r-t2+1;
}else{
tl = t1 - l+1;
tr = 0 ;
}
return cnt2 - min(sum1,sum2);
}
void solve()
{
int n;cin>>n;
a.clear();
z.clear();
z.pb(-1);
for(int i=0;i<n;i++){
int x;cin>>x;
a.pb(x);
if(!x) z.pb(i);
}
z.pb(n);
//-1 xxxxxx n
int l = 0 , r = 0 ;
int flag = 0 ;
int len = z.size();
for(int i = 0;i < len; i ++ ){
if(i+1 < len){
int pre = z[i]+1;
int nxt = z[i+1]-1;
int tl = 0 , tr = 0 ;
int t = cal(a,pre,nxt,tl,tr);
if(t>flag){
flag = t;
l = pre+tl;
r = n-nxt-1+tr;
}
}
}
if(!flag) l = n , r = 0 ;
cout<<l<<" "<<r<<endl;
}
E.
const int N = 3000;
int g[N][N];
int t[N][N];
int n;
int cnt ;
int cal(int x,int y){
int res = 0 ;
while(1)
{
if(t[x][y])break;
t[x][y]=1;
if(g[x][y])res ++ ;
(x+=1)%=n;
(y+=1)%=n;
}
return res;
}
void solve()
{
cin>>n;
int maxn = 0 ;
cnt = 0 ;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
t[i][j] = 0 ;
scanf("%1d",&g[i][j]);
if(g[i][j]) ++cnt;
}
}
for(int i=0;i<n;i++){
maxn = max(maxn,cal(i,0));
}
cout<<cnt - maxn+(n-maxn)<<endl;
}
头文件
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false);
#define CIT cin.tie(0);
#define COT cout.tie(0);
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),x.end()
#define Fup(i,a,b) for(int i=a;i<=b;i++)
#define Fde(i,a,b) for(int i=a;i>=b;i--)
typedef priority_queue<int,vector<int>,greater<int>> Pri_m;
typedef pair<int,int> pii;
typedef vector<int> VI;
map<int,int> mp;