2021cspj省选

1.在这里插入图片描述
在这里插入图片描述

#include<bits/stdc++.h>

using namespace std;

vector<string> split(string s,char ch){
    int start=0;
    int len=0;
    vector<string> ret;
    for(int i=0;i<s.length();i++){
        if(s[i]==ch){
            ret.push_back(s.substr(start,len));
            start=i+1;
            len=0;
        }
        else{
            len++;
        }
    }
    if(start<s.length())
        ret.push_back(s.substr(start,len));
    return ret;
}

struct myTime
{
	int hour;
	int minute;
	int seconds;
	myTime(string s){
		vector<string> v = split(s,':');
		this->hour = atoi(v[0].c_str());
		this->minute = atoi(v[1].c_str());
		this->seconds = atoi(v[2].c_str());
	}
	int count(){
		return this->hour*3600+this->minute*60+this->seconds;
	}
};

int main()
{
	string s,mins = "",maxs = "";
	cin>>s;
	for(int i = 0;i<s.size();++i){
		if(s[i]=='?'){
			mins+="0";
			maxs+="9";
		}
		else{
			mins+=s[i];
			maxs+=s[i];
		}
	}
	myTime mint = myTime(mins);
	myTime maxt = myTime(maxs);
	cout<<maxt.count()-mint.count();
	return 0;
}

2.在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include <iostream>
#include<cstdio>
#include<cstring>
#include <string>
#include<algorithm>
using namespace std;

int main()
{
    int i,n,a[500005],max=0,t=0,flag=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n-1;i++){
        if(a[i]<=a[i+1]&&flag==0){
            t++;
            flag=1;//开始上升
        }
        if(a[i]>a[i+1]&&flag==0){//不符合
            continue;
        }
        if(flag==1&&a[i]>a[i+1]){
            t++;
            flag=2;//开始下降
        }
        if(flag==1&&a[i]<=a[i+1]){//继续上升
            t++;
        }
        if(flag==2&&a[i]>a[i+1]){//继续下降
            t++;
        }
        if(flag==2&&a[i]<=a[i+1]){//终止
            if(t>max)
                max=t;
            t=0;
            flag=0;
            i=i-t+1;
        }
    }
    cout<<max;
    return 0;
}
/*12
1 3 4 8 6 5 6 8 7 6 5 4*/

3.送外卖

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct wm
{
    int w,t,v;

};
bool cmp(wm x,wm y)
{
    return x.t<y.t;
}
int main()
{
    wm a[5005];
    int n,T,i,j,time=0,max=0,temp=0;
    cin>>n>>T;
    for(i=0;i<n;i++)
    {
        cin>>a[i].w;cin>>a[i].t;cin>>a[i].v;
    }
    sort(a,a+n,cmp);
    /*for(i=0;i<n;i++)
    {
        cout<<a[i].w<<" "<<a[i].t<<" "<<a[i].v<<endl;
    }*/
    for(i=0;i<n;i++)
    {
        temp=0;
        time=0;
        for(j=i;j<n;j++)
        {
            if(time+a[j].w<=a[j].t){//能在单个规定时间送到
                if(time+a[j].w<=T){//能在总规定时间送到
                    temp+=a[j].v;
                    time+=a[j].w;
                }
            }

        }
        if(temp>max)
            max=temp;
    }
    cout<<max;

}
/*5 12
4 9 9
3 4 7
5 2 12
3 12 2
5 7 8

3 10
5 10 7
4 10 8
7 10 11*/

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白驹_过隙

听说打赏的都进了福布斯排行榜

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值