2017-2018 ACM-ICPC, NEERC A题Automatic Door 挺棘手的模拟
题目链接: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 挺棘手的模拟的更多相关文章
- 2018 ACM/ICPC 南京 I题 Magic Potion
题解:最大流板题:增加两个源点,一个汇点.第一个源点到第二个源点连边,权为K,然后第一个源点再连其他点(英雄点)边权各为1,然后英雄和怪物之间按照所给连边(边权为1). 每个怪物连终点,边权为1: 参 ...
- 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 ...
- 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 ...
- 2017 ACM/ICPC 沈阳 I题 Little Boxes
Little boxes on the hillside. Little boxes made of ticky-tacky. Little boxes. Little boxes. Little b ...
- 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 ...
- 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 ...
- 2018 ACM ICPC 南京赛区 酱油记
Day 1: 早上6点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...
- Irrelevant Elements, ACM/ICPC NEERC 2004, UVa1635
这种题目最重要的是思路了清晰 #include <cstdio> #include <cstring> ;//sqrt(n)+1 is enough ][]; ]; int a ...
- 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)
题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...
随机推荐
- Docker Swarm 创建服务
Docker Swarm 创建服务 环境: 系统:Centos 7.4 x64 应用版本:Docker 18.09.0 管理节点:192.168.1.79 工作节点:192.168.1.78 工作节点 ...
- Python Redis list
List操作,redis中的List在在内存中按照一个name对应一个List来存储. 注:列表存入 从右到左 如图: lpush(name,values) # 在name对应的list中添加元素,每 ...
- Linux rsync同步
rsync介绍 rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文 ...
- P1903 [国家集训队]数颜色 / 维护队列
思路 带修莫队的板子 带修莫队只需要多维护一个时间的指针即可,记录一下每个询问在第几次修改之后,再回退或者前进几个修改操作 排序的时候如果a.l和b.l在一个块里,就看r,如果a.r和b.r在一个块里 ...
- Lintcode105 Copy List with Random Pointer solution 题解
[题目描述] A linked list is given such that each node contains an additional random pointer which could ...
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
Qt 程序获取程序所在路径.用户目录路径.临时文件夹等特殊路径的方法 经常我们的程序中需要访问一些特殊的路径,比如程序所在的路径.用户目录路径.临时文件夹等.在 Qt 中实现这几个功能所用的方法虽然都 ...
- HTML5的十大新特性
为了更好地处理今天的互联网应用,HTML5添加了很多新元素及功能,比如: 图形的绘制,多媒体内容,更好的页面结构,更好的形式 处理,和几个api拖放元素,定位,包括网页 应用程序缓存,存储,网络工作者 ...
- P1340 兽径管理
传送门 思路: 题目要求每次连边都要输出最小生成树的边权和.如果在线直接套用最小生成树模板肯定会超时,考虑离线处理.记录每一插入边的时间,在所有边都插入完成后排序一遍就可以求最小生成树(按照插入时间的 ...
- vue extend 的基本使用
vue.extend 局部注册 的应用2 请注意,extend创建的是一个组件构造器,而不是一个具体的组件实例.所以他不能直接在new Vue中这样使用: new Vue({components: f ...
- scala操作HBase2.0
在前面: scala:2.12 hbase:2.0.2 开发工具:IDEA 准备工作: 1.将生产上的hbase中的conf/hbase-site.xml文件拷贝到idea中的src/resource ...