2023年码蹄杯决赛A题 小码哥和假期堵车 题型:签到题

59 阅读1分钟

码题集OJ-小码哥和假期堵车 (matiji.net)

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, pass;
const int daytime=1440;
const int N=110;
int a[N];
signed main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>pass;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	for(int i=1;i<=n;i++)
	{
	    int t=daytime-a[i];
	    if(t>=60)
	    {
	       if(pass-t<=0)
		   {
		   	cout<<i;
		   	break;
		   }
		   else
		   {
		   	pass-=t;
		   	if(pass<=0)
		   	{
		   	  cout<<i<<endl;
			  break;	
			}
		   }
		}
		
	}
	
return 0;	
} 

image.png

二刷


#include<bits/stdc++.h>

#define int long long
using namespace std;
int n,t,cnt=1,temp,temp2;
const int DAY=1440;
const int N=1e2+10;
int a[N];
signed main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    
    
    int n,t;cin>>n>>t;
    for(int i=0;i<n;i++)cin>>a[i];
    
    
	for(int i=0;i<n;i++)
	{
		int T=DAY-a[i];  //判断一下当天是否可以玩游戏

		if(T>=60)        //如果可以玩
		{
                     //判断一次玩游戏是否通关,通过就输出所用的天数,结束程序
			temp=T-t; 
			if(temp>=0)
			{
			cout<<cnt<<endl;
			break;
			}
            else  //如果一次不能通过,那么通过总需时长-已经玩了时间,继续去判断下一次是否可以通关
            {
              temp2=t-T;
              t=temp2;
            }
		}

		cnt++;  //不管能玩还是不能玩都需要花费1天的贡献
	} 
return 0;	
} 

image.png