首页 > 其他分享 >2021cspj省选

2021cspj省选

时间:2023-02-27 17:31:32浏览次数:39  
标签:省选 2021cspj cin myTime int flag max include


1.

2021cspj省选_算法


2021cspj省选_#include_02

#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.

2021cspj省选_算法_03


2021cspj省选_算法_04


2021cspj省选_i++_05

#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*/


标签:省选,2021cspj,cin,myTime,int,flag,max,include
From: https://blog.51cto.com/u_15983387/6088768

相关文章

  • 省选联测37-40
    省选联测40后浪总结:典中典之注意到只有一个段会有\(0\)也有\(1\)的贡献即可脑力不错的题,当时整个人状态非常玄妙,灵机一动就切了考虑trie树上dp不好,但是子集d......
  • 省选联测 40
    今天题很不错啊!就是我T1写挂了)后浪痛苦面具。#include<algorithm>#include<iostream>#include<cstdio>#include<vector>#include<cstring>usingnamespace......
  • 省选联测39
    直接粘题解tmdA.伯爵我们发现一对排列不一定对应一种方案,一种方案也不一定对应一对排列。考虑如何不算重。首先确定的是归并方式:每个排列对应一些划分,相当于把每个划分......
  • 省选联测 38
    挂分大场。光光要杀我。今天的四个题题目名称都是Arcaea的梯子名字。放个参考。LostWorld 失落的世界(主线第一章背景)OuterReaches 谜域的界外(MemoryForest&......
  • 省选联测 37
    现在每天的考试策略就是优先切掉所有一眼题然后暴力打满然后摆。为了查证T3题目背景的真实性,我看了看nflsoj。结果:6。感觉不如原神。玩水一场考试不能没有一道签到......
  • P8292 [省选联考 2022] 卡牌
    我决定不整什么写过的题的集合了,写不过来。想到啥题好就写啥。这题是个很好的套路。考虑到值域不怎么大,想到根号分治。也就是小于根号的质数不超过\(14\)个,大于根号的......
  • [省选联考 2022] 填树 题解
    神奇dp。发现我看到dp大多数时候只会暴力。那我约等于退役了啊。题意:自己看。首先有一个显然的暴力。枚举一个最小值\(L\),然后区间就限定在了\([L,L+K]\)。那么普及......
  • 省选联测32
    nnd考不动了,脑子不转了已经A.光明正解做法是\(O(n)\)的,长剖一下,在链上差分贡献,但是貌似常数极大,不知道为啥开六秒。赛时写的是两个log的二分加启发式,实际表现和\(O(n)\)......
  • 「考试总结」2023-02-13 联合省选模拟赛 – Day1
    爆搜$\texttt{(dfs)}$$\texttt{Statement}$给定一个$n$个点$m$条边的简单无向图,你需要对所有匹配$S$,把$c^{|S|}$求和,其中$|S|$是匹配......
  • 省选联测31
    A.西克赛时冲了四个小时,在下行部分假了无数个做法。暴力两个log的话就倍增走一条重链,然后切重链,来回操作就行了。题解点击查看代码//ubsan:undefined//accod......