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 ...
随机推荐
- Linux firewalld 防火墙
Linux firewalld 防火墙 简介 RHEL 7 系统中集成了多款防火墙管理工具,其中 firewalld(Dynamic Firewall Manager of Linux system ...
- MYSQL 修改表结构基本操作一览
查看表的字段信息:desc 表名; 查看表的所有信息:show create table 表名; 添加主键约束:alter table 表名 add constraint 主键 (形如:PK_表名) ...
- 使用python玩跳一跳亲测使用步骤详解
玩微信跳一跳,测测python跳一跳,顺便蹭一蹭热度: 参考博文 使用python玩跳一跳超详细使用教程 WIN10系统,安卓用户请直入此: python辅助作者github账号为:wangshub. ...
- 关于 使用python向qq好友发送消息(对爬虫的作用----当程序执行完毕或者报错无限给自己qq发送消息,直到关闭)
以前看到网上一些小程序,在处理完事物后会自动发送qq消息,但是一直搞不懂是说明原理.也在网上找过一些python登陆qq发送消息的文字,但是都太复杂了.今天偶然看到一篇文章,是用python调用win ...
- Python3 tkinter基础 OptionMenu 点击按钮,出现单选的下拉列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- asp.net mvc session锁问题
一.会话状态Session Session用于服务器端状态管理,使用Session之后,每个客户端都可以将实际的数据保存在服务器上,对于每个客户端的数据,将会生成一个对应的唯一的key(保存在客户端) ...
- Eclispe创建maven工程缺失web.xml报web.xml is missing and <failOnMissingWebXml> is set to true的错误
Eclispe创建maven工程缺失web.xml报web.xml is missing and <failOnMissingWebXml> is set to true的错误,一看,还缺 ...
- 20175317 《Java程序设计》第二周学习总结
20175317 <Java程序设计>第二周学习总结 教材学习内容总结 第二周我学习了教材三四章的内容,了解了Java与C语言的相似与不同之处. 其中第二章学到了标识符与关键字.基本数据类 ...
- Http头:Expires,Cache-Control,Last-Modified,ETag
Expires:过期时间 el:Expirse:Fri,30 Oct 1998 14:19:41 Cache-Control:缓存控制 el:Cache-Contro ...
- EL条件判断用法<c:choose>
EL表达式一般不直接用==,!=,>,<,>=,<=之类的表示相等.不等于.大于.小于.大于等于以及小于等于,而是使用字母表示,如下: == eq 等于 != ...