12.反异或01串 - 蓝桥云课 (lanqiao.cn)
#include "bits/stdc++.h"
#define int long long
using namespace std;
char c[10000000];
char s[10000000];
int cnt,Ans,mr,mid;
int maxi;
int p[10000000],pre[10000000];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
scanf("%s",c+1);
int n=strlen(c+1);
s[++cnt]='~';
s[++cnt]='#';
for(int i=1;i<=n;i++)
s[++cnt]=c[i],s[++cnt]='#';
s[++cnt]='!';
for(int i=1;i<=cnt;i++)
{
pre[i]=pre[i-1];
if(s[i]=='1')
pre[i]++;
if(i<=mr) p[i]=min(p[mid*2-i],mr-i+1);
else p[i]=1;
while(s[i+p[i]]==s[i-p[i]]) p[i]++;
if(i+p[i]>mr) mr=i+p[i]-1,mid=i;
if(s[i]!='1'&&pre[i]-pre[i-p[i]]>pre[maxi]-pre[maxi-p[maxi]])
maxi=i;
}
int k=pre[cnt]-(pre[maxi]-pre[maxi-p[maxi]]);
cout<<k;
}
0艺术与篮球 - 蓝桥云课 (lanqiao.cn)
#include <bits/stdc++.h>
#define int long long
using namespace std;
int cnt[12]={13,1,2,3,5,4,4,2,2,2};
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int check(int year)
{
if((year%4==0&&year%100!=0)||year%400==0)
return 1;
else
return 0;
}
int getd(int year,int month)
{
if(check(year)&&month==2)
return days[month]+1;
return days[month];
}
int getb(int date)
{
int sum=0;
while(date)
{
sum+=cnt[date%10];
date/=10;
}
return sum;
}
int cntt=0;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
for(int year=2000;year<=2024;year++)
{
for(int month=1;month<=12;month++)
{
for(int day=1;day<=getd(year,month);day++)
{
int date=year*10000+month*100+day;
if(getb(date)>50&&(date<=20240413))
cntt++;
}
}
}
cout<<cntt;
}
2.拉马车 - 蓝桥云课 (lanqiao.cn)
#include <bits/stdc++.h>
#define int long long
using namespace std;
queue<char>q1,q2;
void fun()
{
vector<char>v;
bool flag=true;
while(q1.size()!=0&&q2.size()!=0)
{
if(flag)
{
v.push_back(q1.front());
if(count(v.begin(),v.end(),q1.front())==2)
{
while(v.size()!=0)
{
q1.push(v.back());
v.pop_back();
if(count(v.begin(),v.end(),q1.front())==0)
break;
}
}
else
flag=false;
q1.pop();
if(q1.empty()) return;
}
if(!flag)
{
v.push_back(q2.front());
if(count(v.begin(),v.end(),q2.front())==2)
{
while(!v.empty())
{
q2.push(v.back());
v.pop_back();
if(count(v.begin(),v.end(),q2.front())==0) break;//拿走完结束
}
}
else flag=true;
q2.pop();
if(q2.empty()) return;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
string s1,s2;
cin>>s1>>s2;
for(int i=0;i<s1.length();i++)
{
q1.push(s1[i]);
q2.push(s2[i]);
}
fun();
while(!q1.empty()){
cout<<q1.front();
q1.pop();
}
while(!q2.empty()){
cout<<q2.front();
q2.pop();
}
}
4.区间移位 - 蓝桥云课 (lanqiao.cn)
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct node{
int a;
int b;
};
int n;
vector<node>nv;
bool ng(node a,node b)
{
return a.b<b.b;
}
bool check(int mid)
{
int mr=0;
vector<node>temp(nv);
while(true)
{
bool flag=false;
for(int i=0;i<temp.size();i++)
{
node nod=temp[i];
int na=nod.a;
int nb=nod.b;
int len=nb-na;
if(na-mid<=mr&&mr<=nb+mid)
{
flag=true;
if(na+mid>=mr)
mr+=len;
else
mr=nb+mid;
temp.erase(temp.begin()+i);
break;
}
}
if(mr>=20000||!flag) break;
}
return mr>=20000;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=0;i<n;i++)
{
int a,b;
cin>>a>>b;
nv.push_back({a*2,b*2});
}
int l=0,r=1000000;
sort(nv.begin(),nv.end(),ng);
while(l<r)
{
int mid=(l+r)/2;
if(check(mid)) r=mid;
else l=mid+1;
}
double m=(double)l/2;
cout<<m;
}
6.机器人塔 - 蓝桥云课 (lanqiao.cn)
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool check(int now,int num)
{
int num_a=0,num_b=0;
for(int i=num;i>=1;i--)
{
bitset<32>bs=now;
num_b+=bs.count();//1
num_a+=i-bs.count();//0
now^=now>>1;//自己异或
now&=(1<<(i-1))-1;//消除第一个
}
return num_a==m&&num_b==n;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>m>>n;
// int num = sqrt((n + m) * 2);
// cout<<num;
int num=0;
for(int i=1;i<=60;i++)
{
if(i*(i+1)/2.0==m+n)
{
num=i;
break;
}
}
int ans=0;
for(int i=0;i<(1<<num);i++)
{
if(check(i,num))
ans++;
}
cout<<ans;
}