zoukankan      html  css  js  c++  java
  • 51Nod——T 1631 小鲨鱼在51nod小学

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1631

    基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题
     收藏
     关注
    鲨鱼巨巨2.0(以下简称小鲨鱼)以优异的成绩考入了51nod小学。并依靠算法方面的特长,在班里担任了许多职务。
     
    每一个职务都有一个起始时间A和结束时间B,意为小鲨鱼在[A, B]时间内,担任了某职务(inclusively)。
     
    现在给定小鲨鱼的职务履历表,你可以高效的给出小鲨鱼在某天担任了哪些职务吗?
     
    p.s. 由于小鲨鱼担任的职务太多,所有任期小于一个自然月的职务都忽略不计。(如1月1日~2月1日为一个自然月,即月份加1)
     
    p.p.s. 输入数据保证小鲨鱼同时不担任超过200种职务。(牛!)
     
    p.p.p.s 输入的日期均为合法日期,范围在2000年01月01日~2999年12月31日。
     
    p.p.p.p.s巨大的输入输出,推荐使用scanf/printf,编译器推荐使用Virtual C++
    Input
    第一行为一个整数n,代表小鲨鱼担任过N种职务。(1 <= n <= 10^5)
    接下来的n行,每一行为七个整数,y0, m0, d0, y1, m1, d1, x。意为在<y0, m0, d0>到<y1, m1, d1>时间内,小鲨鱼担任了职务x。(1 <= x <= 10^9)
    给定的时间皆合法,且起始日期小于或等于截止日期。职务x是唯一的。
    
    接下来是一个整数q,代表q次查询。(1 <= q <= 10^4)
    接下来的q行,每一行为三个整数<y, m, d>,代表查询的日期。时间皆合法。
    Output
    每一次查询输出一行结果。
    首先输出一个整数n,代表此时小鲨鱼担任的职务数。(n可以为0)
    接下来是n个整数,代表小鲨鱼担任的职务。职务列表保持升序。
    Input示例
    4
    2000 01 01    2000 01 01    111
    2000 01 02    2001 02 02    222
    2000 01 28    2000 02 29    333
    2000 01 29    2000 02 28    444
    4
    2000 01 01
    2000 01 02
    2000 01 28
    2000 02 29
    Output示例
    0
    1 222
    2 222 333
    2 222 333



    贪心+模拟
    只忽略小于一个自然月、然后。。等于的也忽略了WA半天、
     1 #include <algorithm>
     2 #include <cstdio>
     3 
     4 inline void read(int &x)
     5 {
     6     x=0; register char ch=getchar();
     7     for(; ch>'9'||ch<'0'; ) ch=getchar();
     8     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
     9 }
    10 const int N(1e5+5);
    11 int y0,m0,d0,y1,m1,d1,k;
    12 int cnt,tmp,ans[N];
    13 struct Work {
    14     int ly,lm,ld,ry,rm,rd,kind;
    15     Work(int ly=0,int lm=0,int ld=0,int ry=0,int rm=0,int rd=0,int kind=0):
    16         ly(ly),lm(lm),ld(ld),ry(ry),rm(rm),rd(rd),kind(kind){}
    17     bool operator < (const Work &x)const
    18     {
    19         if(ly!=x.ly) return ly<x.ly;
    20         else if(lm!=x.lm) return lm<x.lm;
    21         else if(ld!=x.ld) return ld<x.ld;
    22         else if(ry!=x.ry) return ry<x.ry;
    23         else if(rm!=x.rm) return rm<x.rm;
    24         else if(rd!=x.rd) return rd<x.rd;
    25     }
    26 }job[N<<1];
    27 
    28 inline bool check()
    29 {
    30     if(y0==y1) return (m0+1==m1&&d0>d1)||m0==m1;
    31     else return (y0+1==y1&&m0==12&&m1==1&&d0>d1);
    32 }
    33 inline bool if_break(Work x)
    34 {
    35     if(x.ly>y0) return 1;
    36     else if(x.ly==y0&&x.lm>m0) return 1;
    37     else if(x.ly==y0&&x.lm==m0&&x.ld>d0) return 1;
    38     return 0;
    39 }
    40 inline bool judge(Work x)
    41 {
    42     if(x.ry<y0) return 0;
    43     else if(x.ry==y0)
    44            if(x.rm<m0) return 0;
    45            else if(x.rm==m0)
    46                      if(x.rd<d0) return 0;
    47     return 1;
    48 }
    49 
    50 int Presist()
    51 {
    52     int n,q; read(n);
    53     for(int i=1; i<=n; ++i)
    54     {
    55         read(y0),read(m0),read(d0);
    56         read(y1),read(m1),read(d1); read(k);
    57         if(!check()) job[++cnt]=Work(y0,m0,d0,y1,m1,d1,k);
    58     }
    59     std::sort(job+1,job+cnt+1);
    60     for(read(q); q--; tmp=0)
    61     {
    62         read(y0),read(m0),read(d0);
    63         for(int i=1; i<=cnt; ++i)
    64         {
    65             if(if_break(job[i])) break;
    66             if(judge(job[i])) ans[++tmp]=job[i].kind;
    67         }
    68         if(!tmp) puts("0");
    69         else
    70         {
    71             printf("%d ",tmp); std::sort(ans+1,ans+tmp+1);
    72             for(int i=1; i<tmp; ++i) printf("%d ",ans[i]);
    73             printf("%d
    ",ans[tmp]);
    74         }
    75     }
    76     return 0;
    77 }
    78 
    79 int Aptal=Presist();
    80 int main(int argc,char*argv[]){;}
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    从Kratos设计看Go微服务工程实践
    京东到家安全测试实践
    浅谈 Protobuf 编码 原创 gsonli 腾讯技术工程 2021-07-14
    API Design Guide
    The power of two choices in randomized load balancing
    NGINX and the "Power of Two Choices" Load-Balancing Algorithm
    SRE 崩溃
    DDoS木马
    String.fromCharCode(88,83,83) 方法返回由指定的 UTF-16 代码单元序列创建的字符串
    汇编语言的AX,BX,CX,DX,分别表示什么
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7607066.html
Copyright © 2011-2022 走看看