选座( ticket_chooser )

不会正解,欢迎讨论

//60分

#include<cstdio>
#define max(a,b) (a)>(b)?a:b
#define min(a,b) (a)<(b)?a:b
const int N=3e5+;
template <typename T>
inline void read(T &x){
T f=;register char ch=getchar();x=;
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
x*=f;
}
inline int abs(int x){return x>?x:-x;}
int n,k,L[N],R[N],tv,s,t,v,x,l,r;
inline int GetVal(const int &x,const int &l,const int &r){
int res(),mid=k+>>;
for(int i=l;i<=r;i++) res+=abs(x-mid)+abs(i-mid);
return res;
}
inline void GetPos(int &tv,const int &h,const int &s,const int &t,int &v,int &x,int &l,int &r){
tv=GetVal(h,s,t);
if(tv<v) v=tv,x=h,l=s,r=t;else
if(tv==v&&h<x) x=h,l=s,r=t;else
if(tv==v&&h==x&&s<l) x=h,l=s,r=t;
}
inline void Solve(){//L[x]表示x排从中间向左最早的空座
for(int i=;i<=k;i++) L[i]=k+>>,R[i]=k+>>;
for(int i=,q;i<=n;i++){
read(q);v=2e9;
for(int j=;j<=k;j++){//时间复杂度的瓶颈
//有想:贪心从(k+1)/2排同时向上、向下迭代,但不知道停止的条件,以及正确性
if(L[j]==R[j]){
if(q&){
s=(k+>>)-(q+>>)+,t=(k+>>)-(q+>>)+q,
GetPos(tv,j,s,t,v,x,l,r);
}
else{
s=(k+>>)-(q>>),t=(k+>>)+(q>>)-,
GetPos(tv,j,s,t,v,x,l,r);
}
}
if(L[j]>=q){
s=L[j]-q+,t=L[j],
GetPos(tv,j,s,t,v,x,l,r);
}
if(R[j]+q-<=k){
s=R[j],t=R[j]+q-,
GetPos(tv,j,s,t,v,x,l,r);
}
}
if(v==2e9){puts("-1");continue;}
L[x]=min(L[x],l-);
R[x]=max(R[x],r+);
printf("%d %d %d\n",x,l,r);
}
}
int main(){
while(~scanf("%d%d",&n,&k)) Solve();
return ;
}

中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2016 选座( ticket_chooser )的更多相关文章

  1. 中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2017 串行调度(serial)

    串行调度(serial) 除等价条件, 根据题意设置限制条件,然后求字典序最小拓扑序. 简洁版 #include<bits/stdc++.h> using namespace std; ; ...

  2. “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 分组加密器(encryption)

    分组加密器(encryption) 题解点这里 #include<map> #include<stack> #include<vector> #include< ...

  3. “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 贪心算法(greedy)

    --> 贪心算法 1)题解 •        分别用V0.V1和V>=2表示度为0.1以及至少为2的顶点集合 •        对于每个顶点,维护三个属性: •        degree ...

  4. “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 绝地求生(battleground)

    /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...

  5. 2016年湖南省第十二届大学生计算机程序设计竞赛Problem A 2016 找规律归类

    Problem A: 2016 Time Limit: 5 Sec  Memory Limit: 128 MB Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) ...

  6. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job

    描述 Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute ...

  7. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List

    描述 The history of Peking University Library is as long as the history of Peking University. It was b ...

  8. hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...

  9. hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...

随机推荐

  1. java中的Date类

    一.Date类简介 日期类主要包括Date类与Calendar类,这一节我们先介绍Date类, Date 表示特定的瞬间,精确到毫秒.Date类用于表示日期和时间,在计算机中的表示和我们现实世界使用差 ...

  2. Python基础之time、os模块

    1.时间模块 1)模块 python安装好之后,会有一些默认模块,我们称之为标准库,标准库中的模块python自带,无需安装. 除了标准库,还有一个第三方库,可以通过pip来安装,不同的库有不同的功能 ...

  3. 第一阶段:Java基础 1.JAVA开发介绍---5. Java的注释,标识符、标识符的命名规范

    1.java注释 java中有三种注释方式,单行注释,多行注释,文档注释. (1).单行注释:快捷键Ctrl+/再次按撤销注释, (2).多行注释:Ctrl+shift+/ 撤销Ctrl+shift+ ...

  4. drf框架--基础

    目录 drf框架 导入 什么是接口 restful接口规范 原生Django实现接口 drf框架 Django CBV 和drf CBV对比 响应渲染模块 请求数据解析模块 响应模块 二次封装Resp ...

  5. 使用别的电脑连接另一台电脑当中的虚拟机中的kylin项目

    环境说明: 本机A的ip:192.168.0.242 服务器B的ip:192.168.0.125 服务器上的虚拟机C的ip:192.168.43.129 目前状态: B上面能访问C上的站点kylin站 ...

  6. vue中进行窗口变化的监听

    今天vue项目中用到的元素的宽度依赖与窗口的宽度,所以在进行宽度设置的时候涉及到窗口的变化,因为元素的宽度要随着窗口变化 分成几个步骤来实现这一过程 1.首先元素的宽度依赖与窗口的宽度,就需要有接受窗 ...

  7. net start mysql 失败提示“NET HELPMSG 3534”

    lz使用的window系统8.0.16版本的mysql,以下四步解决如上问题: 1. mysqld -remove 2. mysqld --initialize 3.mysqld -install(m ...

  8. kbmmw 5.10.10 发布

    这个版本主要是bug修正. New stuff         =========         - Added OnException event property to TkbmMWSchedu ...

  9. angular8 打包时 文件过大 导致内存溢出解决方案(记录)

    在package.json 中添加 "scripts": { "ng": "ng", "start": "ng ...

  10. Django 之 restframework 频率组件的使用

    Django 之 restframework 频率组件的使用以及源码分析 频率组件的使用 第一步,先写一个频率类,继承SimpleRateThrottle 一定要在这个类里面配置一个scop='字符串 ...