b:直接模拟从左到右这个过程即可.空格操作和不进行空格操作进行一次比较.

#include <bits/stdc++.h>
using namespace std;
vector<int>ans1,ans2;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ans1.clear(),ans2.clear();
        string s1,s2;int num1=0,num2=0;
        cin>>s1>>s2;
        //不清0.
        for(int i=0;i<s1.size();i++)
        {
            if(num1&1)
            {
                if(s1[i]=='1')  s1[i]='0';
                else            s1[i]='1';
            }
            if(s1[i]!=s2[i])
            {
                num1++;
                ans1.push_back(i+1);
            }
        }
        //清0.
        ans2.push_back(0);
        for(int i=0;i<s2.size();i++)
        {
            if(s2[i]!=('0'+(num2%2)))
            {
                num2++;
                ans2.push_back(i+1);
            }
        }
        if(ans2.size()<=ans1.size())//输出ans2.
        {
            for(int i=0;i<ans2.size();i++)
            {
                printf("%d ",ans2[i]);
            }puts("");
        }
        else
        {
            for(int i=0;i<ans1.size();i++)
            {
                printf("%d ",ans1[i]);
            }puts("");
        }
    }
    return 0;
}

c:移动最小次数即可,这样一定最优.但是记得pos的初始化.

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int main()
{
    int T;long long pos=0;long long ans=0;
    scanf("%d",&T);
    while(T--)
    {
        long long n;pos=0;
        scanf("%lld",&n);
        ans=n;
        for(int i=1;i<=n;i++)
        {
            long long l,r;
            scanf("%lld%lld",&l,&r);
            if(pos>=l&&pos<=r)    continue;
            if(pos>r)   ans+=(pos-r),pos=r;
            else        ans+=(l-pos),pos=l;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

f:abcde猜四次即可.

#include <bits/stdc++.h>
using namespace std;
int main()
{
    printf("e\n");
    return 0;
}

h:删除即使区间-inf即可,用线段树维护区间max

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e6 + 10;
struct node {
    ll l, r, val, add;
}t[maxn];
int a[maxn];
//维护最大值
void build(int p,int l,int r){//区间编号p
    t[p].l = l; t[p].r = r;
    t[p].add = 0;
    if(l==r){//叶子结点直接赋值
        t[p].val = a[l];
        return ;
    }
    int mid = l+r >>1;
    build(2*p,l,mid);
    build(2*p+1,mid+1,r);
    t[p].val = max(t[p*2].val,t[p*2+1].val);//维护区间和
}
void spread(int x)
{
    if(t[x].add){
        t[2*x].val=0;
        t[2*x+1].val=0;
        t[2*x].add=1;
        t[2*x+1].add=1;
        t[x].add=0;
    }
}
void update(int x,int l,int r)
{
    if(l>r) return;
    if(t[x].l>=l&&t[x].r<=r){
        t[x].val=0;
        t[x].add=1;
        return;
    }
    spread(x);
    int mid=(t[x].l+t[x].r)>>1;
    if(l<=mid) update(2*x,l,r);
    if(r>mid) update(2*x+1,l,r);
    t[x].val=max(t[2*x].val,t[2*x+1].val);
}
ll query(int p,int l,int r){
    if(l<=t[p].l&&r>=t[p].r){//被覆盖 返回值
        return t[p].val;
    }
    spread(p);
    ll ans = 0;
    int mid = t[p].r+t[p].l>>1;
    if(l<=mid)ans=max(ans,query(p*2,l,r));
    if(r>mid)ans=max(ans,query(p*2+1,l,r));
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    int _;
    cin >> _;
    while (_--) {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        build(1, 1, n);
        while (m--) {
            int l, r;
            cin >> l >> r;
            update(1, l, r);
            cout << t[1].val << '\n';
        }
    }
    return 0;
}

k:直接模拟,注意闰年以及月份判断.

#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstring>
#include<set>
#include<stack>
using namespace std;

const int maxn = 4e6 + 10;
char s[maxn];
int d[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int l,int r){
    int year = 0;
    for(int i = l,j = r;i <= j; i++,j--){
        year = year * 10 + (s[i] - '0');
        if(s[i] != s[j])return false;
    }
    int month = ((s[l + 4] - '0') * 10) + (s[l + 5] - '0');
    int day = ((s[l + 6] - '0') * 10) + (s[l + 7] - '0');
    if(year < 1 || year > 9999)return false;
    if(month < 0 || month > 12)return false;
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
        if(month == 2){
            return day >= 1 && day <= 29;
        }else{
            return day >= 1 && day <= d[month];
        }
    }
    return day >= 1 && day <= d[month];
    return true;
}
void solved(){
    int n = strlen(s + 1); 
    int ans = 0;
    for(int i = 1; i + 7 <= n; i++){
        int l = i;
        int r = i + 7;
        if(check(l,r)){
            ans++;
        }
    }
    printf("%d\n",ans);
}
int main(){
    while(gets(s + 1)){
        if(s[1] == '#')break; 
        solved();
    }
    return 0;
}