[nhzxoi2017]noip2016pj

普及组

1.      pencil

三个if语句

2.      date

求出a到b有多少天用YYYYMMDD表示出来是回文的

用一个循环枚举再判一下闰年

(快解)其实可以直接枚举a所在的年份到b所在的年份对应的月份和天。因为年份只有4位。

const ri:array[1..12]oflongint=(31,28,31,30,31,30,31,31,30,31,30,31);

var s1,s2,s3:string;

   i,j,pd,x1,x2,x3,y1,y2,y3,ans:longint;

function run:boolean;

begin

  if (x2=2)and(x3=29)and(((x1mod 4=0)and(x1 mod 100>0))or(x1 mod 400=0)) then exit(false);

  exit(true);

end;

begin

 assign(input,'date.in');reset(input);

 assign(output,'date.out');rewrite(output);

  readln(s1);

  readln(s2);

  val(copy(s1,1,4),x1);val(copy(s1,5,2),x2); val(copy(s1,7,2),x3);

  val(copy(s2,1,4),y1);val(copy(s2,5,2),y2); val(copy(s2,7,2),y3);

  for i:=1 to 4 do ifs1[i]<>s1[9-i] then begin pd:=1; break; end;

  if pd=0 then inc(ans);

 while(x1<y1)or((x1=y1)and(x2<y2))or((x1=y1)and(x2=y2)and(x3<y3))do

  begin

    inc(x3);

    if x3>ri[x2] then

    begin

      if run then

      begin x3:=1; inc(x2); ifx2>12 then begin x2:=1; inc(x1); end; end;

    end;

    str(x1,s1);

    str(x2,s2);

    str(x3,s3);

    if x2>9 then s1:=s1+s2else s1:=s1+'0'+s2;

    if x3>9 then s1:=s1+s3else s1:=s1+'0'+s3;

    pd:=0;

    for i:=1 to 4 do ifs1[i]<>s1[9-i] then begin pd:=1; break; end;

    if pd=0 then inc(ans);

  end;

  writeln(ans);

  close(input);close(output);

end.

3.      海港

首先时间是单调递增的,我们可以记录艘船每个国家有几个人,再一边做一边删掉86400秒之前的。所以就要开二维数组按照题目记录每一艘船,但因1≤船数≤10^5,人的总数≤3×10^5,所以我们开的数组就要到10^10肯定会爆空间,只能用一维数组(也可以用滚动数组)。再用数组存这条船人的起点和重点。#include <iostream>

#include <stdio.h>

#include <math.h>

#include <algorithm>

using namespace std;

 

    intb[400005],n,t[400005],s[400005],e[400005],a[400005],tot=0,l=0,ans=0,j=0;

int main()

{

       freopen("port.in","r",stdin);

       freopen("port.out","w",stdout);

   scanf("%d",&n);

    for (int i=1;i<=n;i++)

    {

              scanf("%d%d",&t[i],&l);

        s[i]=tot+1;

        for (int k=1;k<=l;k++){scanf("%d",&a[++tot]);if(b[a[tot]]==0) ans++;b[a[tot]]++;}

        e[i]=tot;

       while(t[j+1]<=t[i]-86400)

        {

             j++;

             for(int k=s[j];k<=e[j]; k++) {b[a[k]]--;if(b[a[k]]==0) ans--;}

        }    

       cout<<ans<<endl;

    }

       fclose(stdin);fclose(stdout);

}

4.      magic

首先看到题目给出n的范围就想如何用n来做。发现

确定了abc就可以知道d的位置了,可以枚举魔法值。

又因为

所以枚举c是只要从6∗j+xb+1开始。

设a,b距离为L,则c,d距离为2L,bc>6L,ad>9L,我以我们就可以枚举L了。再在每一个L中枚举d的位置d的方案数就等于(前面所有a的方案)*(前面所有b的方案)*(当前c的方案数,我们就可以先预处理把该位置前的a方案总数放到一个数组……b,c,d也是同理。

#include <iostream>

#include <stdio.h>

#include <math.h>

#include <algorithm>

using namespace std;

inta[30005],b[30005],c[30005],d[30005],aa[30005],bb[30005],q,w,n,m;

int main()

{

       freopen("magic.in","r",stdin);

       freopen("magic.out","w",stdout);

       cin>>n>>m;

       for(int i=1;i<=m;i++)

       {

              cin>>aa[i];

              bb[aa[i]]++;

       }

       for(int i=1;i<=n/9;i++)

       {

              q=1+9*i;w=0;

              for(int j=2+9*i;j<=n;j++)

              {

                     w=w+bb[(j-q)]*bb[j-q+i+i];

                     d[j]=d[j]+w*bb[j-i];

                     c[j-i]=c[j-i]+w*bb[j];

              }

               q=8*i+1; w=0; 

              for(int j=n-9*i-1; j<=1;j--)

              {

                     w=w+bb[j+q]*bb[j+q+i];

                     a[j]=a[j]+w*bb[j+i+i];

                     b[j+i+i]=b[j+i+i]+w*bb[j]; 

              }

       }

       for(int i=1;i<=m;i++)cout<<a[aa[i]]<<b[aa[i]]<<c[aa[i]]<<d[aa[i]];

       fclose(stdin);fclose(stdout);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值