题目链接:http://codeforces.com/contest/883/problem/A

题意大致就是有一个门,有n个人有规律的来,时刻分别是a,2a,3a.....na。有m个人无规律的来,时刻分别为t1,t2,t3...tm.

每当有人来了门就会立刻打开并持续开d个时间单位,在闭门的那一个时刻可以有人进入并不会触发门的再次打开。

数据范围:

a<=10^9,m<=10^5,d<=10^18

ti<=10^18

思路比较简单,枚举考虑m个无规律的来的人,推一下从第i个无规律来的人到第i+1个无规律来的人之间开门次数的公式。

然后实现。。我WA了好多好多次。

AC代码:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int MAXN=;
long long n,a,m,d;
long long t[MAXN];
int main()
{
// freopen("in.txt","r",stdin);
long long ans=,now=;
scanf("%lld%lld%lld%lld",&n,&m,&a,&d);
// printf("%lld %lld %lld %lld\n",n,m,a,d);
long long x=d/a+;
//printf("x=%lld\n",x);
long long ma=;
rep(i,,m)
{
scanf("%lld",&t[i]);
if(t[i]>ma) ma=t[i];
// printf("t[i]=%lld\n",t[i]);
}
t[m+]=max(n*a+d+d,ma+d+d);
sort(t+,t+m+);
if(t[]<a)
{
ans++;
now=t[]+d;
}
else
{
ans++;
now=a+d;
}
long long tmp=now/a+;
long long temp;
bool flag=;long long cnt;
rep(i,,m+)
{
// printf("t[%d]=%lld tmp=%lld now=%lld ans=%lld\n",i,t[i],tmp,now,ans);
if(tmp>n)
{
cnt=i;
flag=;
break;
}
if(t[i]<=now) continue;
if(t[i]<=tmp*a)
{
ans++;
now=t[i]+d;
tmp=now/a+;
}
else
{
temp=min(t[i]/a,n);
temp=temp-tmp;
ans+=temp/x+;
now=(tmp+(temp/x+)*x)*a-a+d%a;
tmp=tmp+(temp/x+)*x;
// printf(" warn t[%d]=%lld tmp=%lld now=%lld ans=%lld\n",i,t[i],tmp,now,ans);
if(t[i]<=now) continue;
else
{
ans++;
now=t[i]+d;
tmp=now/a+;
}
}
}
if(flag)
{
rep(i,cnt,m+)
{
if(t[i]<=now) continue;
else
{
// printf("why now=%lld i=%d ans=%lld cnt=%d\n",now,i,ans,cnt);
ans++;
now=t[i]+d;
}
}
}
printf("%lld\n",ans-);
return ;
}

2017-2018 ACM-ICPC, NEERC A题Automatic Door 挺棘手的模拟的更多相关文章

  1. 2018 ACM/ICPC 南京 I题 Magic Potion

    题解:最大流板题:增加两个源点,一个汇点.第一个源点到第二个源点连边,权为K,然后第一个源点再连其他点(英雄点)边权各为1,然后英雄和怪物之间按照所给连边(边权为1). 每个怪物连终点,边权为1: 参 ...

  2. 2017 ACM/ICPC 沈阳 K题 Rabbits

    Here N (N ≥ 3) rabbits are playing by the river. They are playing on a number line, each occupying a ...

  3. 2017 ACM/ICPC 沈阳 L题 Tree

    Consider a un-rooted tree T which is not the biological significance of tree or plant, but a tree as ...

  4. 2017 ACM/ICPC 沈阳 I题 Little Boxes

    Little boxes on the hillside. Little boxes made of ticky-tacky. Little boxes. Little boxes. Little b ...

  5. 2017 ACM/ICPC 沈阳 G题 Infinite Fraction Path

    The ant Welly now dedicates himself to urban infrastructure. He came to the kingdom of numbers and s ...

  6. 2017 ACM/ICPC 沈阳 F题 Heron and his triangle

    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...

  7. 2018 ACM ICPC 南京赛区 酱油记

    Day 1: 早上6点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...

  8. Irrelevant Elements, ACM/ICPC NEERC 2004, UVa1635

    这种题目最重要的是思路了清晰 #include <cstdio> #include <cstring> ;//sqrt(n)+1 is enough ][]; ]; int a ...

  9. 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)

    题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...

随机推荐

  1. python 基础知识点二

    深浅copy 1对于赋值运算来说,l1与l2指向的是同一个内存地址,所以他们是完全一样的. l1 = [1,2,3,['barry','alex']] l2 = l1 l1[0] = 111 prin ...

  2. DAY9 函数

    一.脚本文件的执行 1.存放当前文件作为脚本文件执行的参数们:[‘当前文件的绝对路径’,手动传入的参数们] 2.脚本文件执行:直接用python解释器运行该文件  print(sys.argv) # ...

  3. Axure 交互样式和选项组的设置

    1.点击元件,点击属性,点击选中,点击图片,选择相应的图片,选中功能是当点击这个元件的时候,元件的变成相应的图片,然后再设置鼠标单击时的动作是选中,就可以实现选中某个元件的时候,元件会变成其他的图片. ...

  4. iSCSI网络协议.学习笔记

    Internet SCSI(iSCSI)是一种网络协议,使用TCP/IP网络来传输SCSI协议.它是代替FC(Fibre Channel-based,光纤通道) SAN的很好选择.你可以在Linux下 ...

  5. querySelector() 方法

    返回文档中匹配指定 CSS 选择器的一个元素. 虽然IE8中没有getElementsByClassName()但可以用querySelector()代替 注意: querySelector() 方法 ...

  6. ZCRM_AU_MAIL

    FUNCTION ZCRM_AU_MAIL. *"---------------------------------------------------------------------- ...

  7. 一个简单CI/CD流程的思考

    因为公司有两地研发团队,在统一CI/CD上难度不亚于两家公司合并后的新流程建立,并非不可攻克,简单描述下心得. 首先,代码管理使用gerrit -> 因其强大的 codereview 功能被选中 ...

  8. Container&injection

    容器(Container)就是组件和底层服务细节之间的接口.在web组件.企业级Bean等能够执行之前,它必须被装配为一个JavaEE模块,并部署在容器上. 在JavaEE5时代通过注解的方式注入(i ...

  9. 解决import caffe 时no module named protobuf的报错

    ProtoBuf是Google开发的可以实现内存与非易失存储介质(硬盘文件等等)交换时的协议接口.Caffe源码中大量使用了ProtoBuf作为权值和模型参数的载体. 在Anaconda下打开Anac ...

  10. jQuery获取包括当前元素的HTML

    1.获取当前元素内的HTML (1)方法一 $("#current").html(); (2)方法二 document.getElementById("current&q ...