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 ...
随机推荐
- Bootstrap3基础 thumbnail 圆角类型的div块
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- Win32汇编学习(6):键盘输入消息
这次,我们将要学习WINDOWS程序是如何处理键盘消息的. 理论: 因为大多数的PC只有一个键盘,所以所有运行中的WINDOWS程序必须共用它.WINDOWS 将负责把击键消息送到具有输入焦点的那个应 ...
- (转载)Unity UGUI点击不同Button执行不同的方法(无参方法)
将脚本随意挂在任何位置 但是这个btnParent一定是 按钮的父节点 脚本很简单自己敲一遍就全都明白了 上脚本 OnClickTest using UnityEngine; using Un ...
- 详解java中的byte类型
Java也提供了一个byte数据类型,并且是基本类型.java byte是做为最小的数字来处理的,因此它的值域被定义为-128~127,也就是signed byte.下面这篇文章主要给大家介绍了关于j ...
- SpingBoot全局异常处理器被覆盖的解决办法
@controllerAdvice()注解 @ControllerAdvice()注解可以定义一个统一的异常处理类,我们可以定义多个统一异常处理类, 但这里我们需要注意一点,默认的@Controlle ...
- POJ 3984(DFS入门题 +stack储存路径)
POJ 3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, ...
- postman(二):使用postman发送get or post请求
总结一下如何使用postman发送get或post请求 请求 一.GET请求 通常用于请求服务器发送某个资源,请求的数据会附在URL之后,以?分割URL和传输数据,多个参数用&连接 1.请求方 ...
- obs studio 使用
专业,开源,无广告,免费,录屏/推流神器--obs studio 稍微简单的也有captura, 原理:调用本地API获取音频流,图像流(全屏幕,单个windows窗口的图像输出)->开源音视频 ...
- linux存储管理之磁盘配额
磁盘配额 1 相关命令:quota.quotacheck.edquota.quotaon.quotaoffquota要使用的命令有两种:一种用于查询功能,包括quota.quotacheck.quo ...
- CentOS安装glibc异常Protected multilib versions
安装失败 在执行yum install glibc.i686 libstdc++.i686 libcurl.i686安装命令时出现Protected multilib versions 解决方案 在命 ...