1003 Express Mail Taking
http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1003&cid=909
Express Mail Taking
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 10439 Accepted Submission(s): 2786
Usually express mails are stored in cabinets. In Baby Volcano's school,there are n cabinets in a row,numbered by 1 to n. The distance between two adjacent cabinets is 1, and the entrance is at the cabinet 1. Among all n cabinets,the one numbered k is special and it is used to enter the code and open the cabinet door.
Baby Volcano has m express mails to take,the i-th is in the cabinet ai.
Two express mails will not be stored in the same cabinet. Also there is no express mail in the cabinet k.
To prevent expresses from being stolen, Baby Volcano have to take these express mails one by one, starting at the entrance. Generally, if he wants to take the express mail i, he have to walk to cabinet k first to enter the code, and then walks to cabinet ai. After taking the last one,he walks to the entrance.
There are so many express mails to take, so Baby Volcano wants to find a taking order which minimize the distance he walks.
For each test cases,the first line contains three integer n,m,k(1≤k≤n≤109,1≤m<min(n,106))
The next line contains m integer,the i-th stand for ai(1≤ai≤n,ai≠k).
The input guarantees that ∑m≤2×106
**Note:Because of the large input,it is prefered to use scanf instead of cin.**
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7; int main()
{
int t = 0;
cin >> t;
ll m , n , k;
while(t--)
{
scanf("%lld%lld%lld",&n,&m,&k);
ll min = 1e9;
ll sum = k-1;
ll temp = 0;
for(ll i = 0;i<m;i++)
{
scanf("%lld",&temp);
sum += abs(temp-k)*2;
if(temp < min)min = temp;
}
if(min < k)
{
sum = sum - 2*(k-min) + k-1;
}
else
{
sum += k-1;
}
printf("%lld\n",sum);
}
return 0;
}
1003 Express Mail Taking的更多相关文章
- 2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛总结
1003 Express Mail Taking 题意:有n个柜子(编号1-n),m封信,k号位置有钥匙,现在需要取信封,并且每取一次信封都要从k号位置进行领取一次钥匙,再去有信封的位置领取信封,问最 ...
- [分享]关于windows下的小技巧
----1.首先,决定您要增加到菜单中的文件类型,以及启动这类文件的应用程序.如果是某些在启动时会自动打开的新文件或让您可以立即使用的应用程序,如记事本.写字板或画图等,就不需要特别的准备工作.但如果 ...
- HBase 伪分布式环境搭建及基础命令使用
一.前提条件: (1)文件存储在HDFS文件系统之上.因此必须启动hadoop服务.(namenode,datanode,resourcemanager,nodemanager,historyserv ...
- 绿卡基础知识:I-129
绿卡基础知识:I-129 标签: 绿卡基础知识 I-129 表格本不该你来填的.那是你老板的 business.在美国工作,除非是公民或有绿卡,都需要移民局的批准.如果你没有 EAD,I-129 就是 ...
- words2
餐具:coffee pot 咖啡壶coffee cup 咖啡杯paper towel 纸巾napkin 餐巾table cloth 桌布tea -pot 茶壶tea set 茶具tea tray 茶盘 ...
- node.js入门及express.js框架
node.js介绍 javascript原本只是用来处理前端,Node使得javascript编写服务端程序成为可能.于是前端开发者也可以借此轻松进入后端开发领域.Node是基于Google的V8引擎 ...
- IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol)。
IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol).IMA ...
- CMSIS Example - Mail and Message
/*---------------------------------------------------------------------------- * RL-ARM - RTX *----- ...
- CentOS 7 使用外部邮箱 发送邮件和附件—mail,mailx
1.查看软件包是否安装 [root@localhost ~]# rpm -qa|grep mail mailx-12.5-12.el7_0.x86_64 javamail-1.4.6-8.el7.no ...
- POJ2891——Strange Way to Express Integers(模线性方程组)
Strange Way to Express Integers DescriptionElina is reading a book written by Rujia Liu, which intro ...
随机推荐
- MySQL聚集索引与辅助索引的区别
聚集索引也称聚簇索引,英文为clustered index.从物理存储角度来分, 索引可以分为聚集索引和辅助索引(secondary index,也称作非聚簇索引),区别主要看叶子节点存了什么数 ...
- CC爬虫攻击测试与防护
CC爬虫攻击测试与防护 本文章旨在对最基本的CC攻击进行测试与防护,本次测试的所有站点均为本人自建,没有也不会去攻击其他站点.希望各位读者能够遵循当地法律法规,不要做危害他人计算机的行为 测试流程 裸 ...
- JDBC之查询
案例1:查询所有用户的信息,封装到一个List里面 1 String url="jdbc:mysql://localhost:3306/nz201"; 2 String user= ...
- 深入浅出容器学习--Docker网络
一.Docker的网络概念 容器网络模型主要包含了三个概念: network:网络,这里可以理解为一个Driver,是一个第三方网络栈,包含多种网络模式. 单主机网络模式(none.host.brid ...
- AI智能文案助手ChatMoney:一键打造抖音爆款视频,助你轻松吸引千万级流量!
本文由 ChatMoney团队出品 引言 看着抖音上别人的视频轻松破百万点赞,是不是心里痒痒的?想知道他们是怎么做到的?其实,他们可能只是比您先一步掌握了这个秘密武器--ChatMoney.这不仅仅是 ...
- 企业级LDAP-RADIUS深度集成高可用方案
一.环境规划总表 1. 节点规划与资源配置 节点类型 主机名 IP地址 VIP 角色 CPU/内存 存储 操作系统 LDAP节点 ldap01 10.0.0.11 10.0.0.10 OpenLDAP ...
- kards卡组推荐——苏美隐蔽
声明:此卡组抗快能力极差,害怕炮兵和小飞机为中后期 隐蔽核心思路: 在第一回合,尽量找杜斯团,找不到如果对方有单位,可以打一个镰刀 第二回合,①有杜斯团:打出隐蔽单位,按隐蔽顺序(附1)出,如果只有1 ...
- Java学习篇(二)—— C++和Java的区别之程序内存分布
上一篇介绍了C++和Java编译的区别和Java独有的网络编程,线程管理.这一篇主要介绍一下两者在程序运行时的内存空间. 内存分布 项目 C++ 程序 Java 程序(使用 JVM) 编译结果 直接生 ...
- Linux在线安装JDK1.8+
Linux在线安装JDK1.8+(默认已发布最新版) 命令在线下载jdk: wget --no-check-certificate --no-cookies --header "Cookie ...
- Coze工作流实战:一键生成鸡汤视频——厉害的人,早已戒掉情绪
导航 前言 工作流生成鸡汤视频的效果 操作步骤 调试 下载草稿 用剪映打开草稿 结语 参考 前言 也许大部分人,能够静下心来看书的时间基本集中在高中阶段,少数人进入大学后可能还回坚持阅读. 在进入职场 ...