HShiDianLu @ 2023-08-28 18:27:40
贪心求解
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
string fill(int s, int k) {
string str = to_string(s);
for (int i = 0; i < k - to_string(s).size(); i++) {
str = "0" + str;
}
return str;
}
int main() {
int n;
cin >> n;
int ques[5001];
for (int i = 0; i < n; i++) {
cin >> ques[i];
}
string start, end;
cin >> start >> end;
int sy = stoi(start.substr(0, 4)), sm = stoi(start.substr(5, 2)), sd = stoi(start.substr(8, 2)), sh = stoi(
start.substr(11, 2)), smin = stoi(start.substr(14, 2));
int lastMin = 0;
while (fill(sy, 4) + "-" + fill(sm, 2) + "-" + fill(sd, 2) + "-" + fill(sh, 2) + ":" + fill(smin, 2) != end) {
smin++;
lastMin++;
if (smin >= 60) {
sh++;
smin = 0;
}
if (sh >= 24) {
sd++;
sh = 0;
}
if ((sm == 1 || sm == 3 || sm == 5 || sm == 7 || sm == 8 || sm == 10 || sm == 12) && sd >= 31) { // 大月
sm++;
sd = 0;
} else if (sm == 2) { // 二月
if (((sy % 4 == 0 && sy % 100 != 0) || sy % 400 == 0) && sd >= 29) { // 闰年
sm++;
sd = 0;
} else if (sd >= 28) { // 平年
sm++;
sd = 0;
}
} else if (sd >= 31) { // 小月
sm++;
sd = 0;
}
if (sm >= 12) {
sy++;
sm = 0;
}
}
sort(ques, ques + n);
int sum = 0;
int num = 0;
for (int i = 0; i < n; i++) {
if (sum + ques[i] <= lastMin) {
sum += ques[i];
num++;
} else {
break;
}
}
cout << num << endl;
return 0;
}
by misaka_HYR @ 2023-10-10 22:12:26
不嫌弃的话蒟蒻给你一点小小的屎山震撼?(笑)
#include<bits/stdc++.h>
using namespace std;
const int sis=1e6+7;
int n,ans,year,mon,day,hour,minn;
int year1,mon1,day1,hour1,minn1;
int st,en,ex,cha;
int work[sis];
signed main()
{
ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&work[i]);
scanf("%d-%d-%d-%d:%d",&year,&mon,&day,&hour,&minn);
scanf("%d-%d-%d-%d:%d",&year1,&mon1,&day1,&hour1,&minn1);
int q;
if(((year%4==0&&year%100!=0)||(year%400==0))&&mon>2) q=1;
else q=0;
if(mon==1) mon=0;
if(mon==2) mon=31;
if(mon==3) mon=59;
if(mon==4) mon=90;
if(mon==5) mon=120;
if(mon==6) mon=151;
if(mon==7) mon=181;
if(mon==8) mon=212;
if(mon==9) mon=243;
if(mon==10) mon=273;
if(mon==11) mon=304;
if(mon==12) mon=334;
mon+=q;
st=minn+60*hour+1440*day+1440*mon;
if(((year%4==0&&year%100!=0)||(year%400==0))&&mon>2) q=1;
else q=0;
if(mon1==1) mon1=0;
if(mon1==2) mon1=31;
if(mon1==3) mon1=59;
if(mon1==4) mon1=90;
if(mon1==5) mon1=120;
if(mon1==6) mon1=151;
if(mon1==7) mon1=181;
if(mon1==8) mon1=212;
if(mon1==9) mon1=243;
if(mon1==10) mon1=273;
if(mon1==11) mon1=304;
if(mon1==12) mon1=334;
mon1+=q;
en=minn1+60*hour1+1440*day1+1440*mon1;
cha=(year1-year)*365;
for(int i=year+1;i<year1;i++)
{
if((i%4==0&&i%100!=0)||(i%400==0)) cha+=1;
}
cha=cha*1440;
cha=cha+en-st;
sort(work+1,work+n+1);
ans=0;
for(int i=1;i<=n;i++)
{
cha-=work[i];
if(cha>=0) ans=i;
else continue;
}
printf("%d\n",ans);
return 0;
}
)