题目链接: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. 剑指offer(37)数字在排序数组中出现的次数。

    题目描述 统计一个数字在排序数组中出现的次数. 题目分析 这题用暴力解也可以过,不过面试官肯定期待更好的解法. 查找我们最熟悉的就是二分查找了,不过二分查找查找的数在数组中只有一个,我们这里却有很多个 ...

  2. springboot配置cxf

    1.引入两个需要的jar <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf- ...

  3. Pandas 基础(11) - 用 melt 做格式转换

    melt 也可以用来做数据格式转换, 请看下图, 我们可以用 melt 把左表转成右表的格式: 首先引入文件(已上传): df = pd.read_csv('/Users/rachel/Sites/p ...

  4. _npc

    `entry`NPCid `id` 顺序id `action` enum('开始','说话','大喊','表情','移动','技能','结束'),NPC动作 `param1` 值1(说话 或者放技能) ...

  5. Sublime text3修改tab键为缩进为四个空格

    1.打开设置界面 2.设置属性 , "translate_tabs_to_spaces": true, "expand_tabs_on_save": true ...

  6. [python]PyPI使用国内源

    PyPI使用国内源 对于默认的pip源的速度太慢,一些国内的pip源,如下: 豆瓣(douban) https://pypi.douban.com/simple 阿里云 http://mirrors. ...

  7. 做h5动画会用到的一个很好的缓动算法库

    http://www.zhangxinxu.com/wordpress/2016/12/how-use-tween-js-animation-easing/

  8. ranch 源码分析(三)

    接上ranch 源码分析(二) 上次讲到了ranch_conns_sup和ranch_acceptors_sup这2个ranch的核心模块,我们接着分析 首先查看ranch_conns_sup.erl ...

  9. http与rfc

    超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTTP最初的目的是为了提供一种发布和接 ...

  10. yii中的restful方式输出并调用接口和判断用户是否登录状态

    //创建一个控制器接口 返回的是restful方式 <?php namespace frontend\controllers; use frontend\models\Fenlei; use f ...