【队内胡策 11.3】 T1 T2

再次把两个题写在一个博客里的原因是,这两道题简单。。
这里写图片描述

T1

这里写图片描述
这里写图片描述

暴力暴力暴力,不能再暴力的暴力,但是考试的时候打了很久,因为很多细节要处理

最后还是wa了一个点qwq,原因见代码44、45行少了一个特判,意思是,第二个日期的月份为2时,如果不是2月29,那么特判的闰年是不应该加上的qwq

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;

char Day1[15],Day2[15],Co1[15],Co2[15];
ll dd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
ll n1,y1,d1,h1,m1,s1,n2,y2,d2,h2,m2,s2;
ll cntn,cnty,cnts1,ans,cnts;

int main()
{
    scanf("%s %s%s %s",Day1+1,Co1+1,Day2+1,Co2+1);
    for(ll i=1;i<=4;++i) n1=n1*10+(ll)(Day1[i]-'0'),n2=n2*10+(ll)(Day2[i]-'0');
    y1=(Day1[6]-'0')*10+Day1[7]-'0';
    y2=(Day2[6]-'0')*10+Day2[7]-'0';
    d1=(Day1[9]-'0')*10+Day1[10]-'0';
    d2=(Day2[9]-'0')*10+Day2[10]-'0';
    h1=(Co1[1]-'0')*10+Co1[2]-'0';
    h2=(Co2[1]-'0')*10+Co2[2]-'0';
    m1=(Co1[4]-'0')*10+Co1[5]-'0';
    m2=(Co2[4]-'0')*10+Co2[5]-'0';
    s1=(Co1[7]-'0')*10+Co1[8]-'0';
    s2=(Co2[7]-'0')*10+Co2[8]-'0';
    for(ll i=n1+1;i<n2;++i) 
    {
        cntn+=365;
        if(i%4==0) cntn++;
    }
    if(n1!=n2)
    {
        for(ll i=y1;i<=12;++i) 
        {
            cnty+=dd[i];
            if(i==y1) cnty-=d1;
            if(i==2&&n1%4==0) cnty++;
        }
        for(ll i=1;i<=y2;++i)
        {
            cnty+=dd[i];
            if(i==y2) cnty-=dd[i]-d2;
            else if(i==2&&n2%4==0) cnty++;
            if(y2==2&&d2==29) cnty++;
            //44 45-->if(i==2&&n2%4==0) cnty++;
        }
        if(cnty) 
        {
            cnty--;
            if(h1==h2&&m1==m2&&s1==s2) cnty++;
        }
        if(h1==h2&&m1==m2&&s1==s2) cnts=0;
        else
        {
            cnts1=h1*60*60+m1*60+s1;
            cnts=24*60*60-cnts1+h2*60*60+m2*60+s2;
        }
    }
    else
    {
        for(int i=y1+1;i<y2;++i)
        {
            cnty+=dd[i];
            if(i==2&&n1%4==0) cnty++;
        }
        if(y1!=y2) 
        {
            if(h1==h2&&m1==m2&&s1==s2) cnts=0;
            else
            {
                cnts1=h1*60*60+m1*60+s1;
                cnts=24*60*60-cnts1+h2*60*60+m2*60+s2;
            }
            cnty+=dd[y1]-d1+d2;
            if(n1%4==0&&y1==2) cnty++;
        }
        else 
        {
            if(d1==d2) cnts=(h2-h1)*60*60-(m1-m2)*60-(s1-s2);
            else 
            {
                if(h1==h2&&m1==m2&&s1==s2) cnts=0;
                else
                {
                    cnts1=h1*60*60+m1*60+s1;
                    cnts=24*60*60-cnts1+h2*60*60+m2*60+s2;
                }
            }
            cnty+=d2-d1;
        }
        if(cnty) 
        {
            cnty--;
            if(h1==h2&&m1==m2&&s1==s2) cnty++;
        }
    }
    ans=(cntn+cnty)*24*60*60+cnts;
    ans*=1000;
    cout<<ans;
    return 0;
}

T2

这里写图片描述

第一眼看是以前做的接水问题,仔细看不一样。考场上打完T1就没时间了,T2就没仔细想打了个60分的暴力qwq,其实这道题特别简单

小根堆里放每一个水龙头已经用过的时间,每次取出最小的,把下一个人加上

代码:

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

const int maxn=100000+10;
int n,m,ans;
int t[maxn];
priority_queue<int,vector<int>,greater<int> >q;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d",&t[i]);
    for(int i=1;i<=m;++i) q.push(t[i]);
    int i=m+1;
    for(;i<=n;++i)
    {
        int x=q.top();
        q.pop();
        q.push(t[i]+x);
    }
    ans=q.top();
    printf("%d",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值