wang6w6 @ 2024-11-17 20:39:51
一直80分
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a[5000003],f,p[19]={0,31,28,31,30,31,30,31,31,30,31,30,31};
string x,y;
ll dy,dm,dd,dh,dmi;
ll year,month,day,hour,mi;
ll t,ans;
void solve(){
while(year<dy){
f=0;
if(year%400==0||(year%4==0&&year%100!=0)){
f=1;
}
t+=(365+f)*24*60;
year++;
}
if(month>dm){
while(month<12){
f=0;
if(year%400==0||(year%4==0&&year%100!=0)){
if(month==2) f=1;
}
t+=(p[month]+f)*24*60;
month++;
}
month=1;
while(month<dm){
f=0;
if(year%400==0||(year%4==0&&year%100!=0)){
if(month==2) f=1;
}
t+=(p[month]+f)*24*60;
month++;
}
}else{
while(month<dm){
f=0;
if(year%400==0||(year%4==0&&year%100!=0)){
if(month==2) f=1;
}
t+=(p[month]+f)*24*60;
month++;
}
}
if(day>dd){
t+=(p[month]-day)*24*60;
t+=dd*24*60;
}else{
t+=(dd-day)*24*60;
}
if(hour>dh){
t+=(24-hour)*60;
t+=dh*60;
}else{
t+=(dh-hour)*60;
}
t+=dmi;
t-=mi;
// cout<<t<<"\n";
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(ll i=1;i<=n;i++){
cin>>a[i];
}
cin>>x>>y;
// scanf("%d-%d-%d-%d:%d",&year,&month,&day,&hour,&mi);
// scanf("%d-%d-%d-%d:%d",&dy,&dm,&dd,&dh,&dmi);
sort(a+1,a+1+n);
// for(ll i=1;i<=n;i++){
// cout<<a[i]<<"\n";
// }
// cout<<'\n';
//year
for(ll i=0;i<4;i++){
year+=(x[i]-'0')*(ll)pow(10,3-i);
dy+=(y[i]-'0')*(ll)pow(10,3-i);
}
//month
for(ll i=5;i<7;i++){
month+=(x[i]-'0')*(ll)pow(10,6-i);
dm+=(y[i]-'0')*(ll)pow(10,6-i);
}
//day
for(ll i=8;i<10;i++){
day+=(x[i]-'0')*(ll)pow(10,9-i);
dd+=(y[i]-'0')*(ll)pow(10,9-i);
}
//hour
for(ll i=11;i<13;i++){
hour+=(x[i]-'0')*(ll)pow(10,12-i);
dh+=(y[i]-'0')*(ll)pow(10,12-i);
}
//minute
for(ll i=14;i<16;i++){
mi+=(x[i]-'0')*(ll)pow(10,15-i);
dmi+=(y[i]-'0')*(ll)pow(10,15-i);
}
// cout<<year<<" "<<dy<<" "<<month<<" "<<dm<<" "<<day<<" "<<dd<<" "<<hour<<" "<<dh<<" "<<mi<<" "<<dmi<<"\n";
solve();
for(ll i=1;i<=n;i++){
if(t-a[i]>=0){
t-=a[i];
ans++;
}else{
break;
}
}
cout<<ans;
return 0;
}
by wang6w6 @ 2024-11-17 20:41:02
悬赏⑩个关注
by Jadonyzx @ 2024-11-17 20:55:33
@wang6w6
solve里可能先加了year再加了month,那不就多算一年了吗?(不一定说得对但可能是这样的
by wang6w6 @ 2024-11-17 20:58:29
@Jadonyzx 我是想先加year再加month的
by Jadonyzx @ 2024-11-17 20:59:08
比如2024-11-4到2025-2-5 那不就先加到2025-11-4了吗?
by Jadonyzx @ 2024-11-17 21:17:37
@wang6w6
先加year可能会出错,你可以试试这个方法:直接模拟每次刷题的时间,判断是否超时即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int n,a[5005];
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
int nowy,nowm,nowd,nowh,nowmin,toy,tom,tod,toh,tomin;
int pm[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int rm[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
bool run(int y){
if(y%400==0)return 1;
if(y%100==0)return 0;
if(y%4==0)return 1;
return 0;
}
bool safe(){
if(nowy<toy)return 1;
if(nowy>toy)return 0;
if(nowm<tom)return 1;
if(nowm>tom)return 0;
if(nowd<tod)return 1;
if(nowd>tod)return 0;
if(nowh<toh)return 1;
if(nowh>toh)return 0;
if(nowmin<=tomin)return 1;
return 0;
}
void update(int dtmin){
nowmin+=dtmin;
if(nowmin>=60){
nowh+=nowmin/60;
nowmin%=60;
if(nowh>=24){
nowd+=nowh/24;
nowh%=24;
int czr;
if(run(nowy))czr=rm[nowm];
else czr=pm[nowm];
while(nowd>czr){
nowd-=czr;nowm++;
if(nowm>12){
nowm=1;
nowy++;
}
if(run(nowy))czr=rm[nowm];
else czr=pm[nowm];
}
}
}
return;
}
signed main(){
n=read();for(int i=1;i<=n;++i)a[i]=read();
sort(a+1,a+1+n);
nowy=read();nowm=read();nowd=read();nowh=read();nowmin=read();
toy=read();tom=read();tod=read();toh=read();tomin=read();
for(int i=1;i<=n;++i){
update(a[i]);
if(!safe()){
cout<<i-1;
return 0;
}
}
cout<<n;
return 0;
}
by Jadonyzx @ 2024-11-17 21:29:14
@wang6w6
hack
5000 5000个10000 2024-11-04-12:00 2025-02-05-12:00
by wang6w6 @ 2024-11-21 14:22:13
@Jadonyzx感谢