选座( 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. MOOC python笔记(二)python中的数据类型和基本语句

    python数据类型 数字类型 整数(int) 与数学中整数概念一致(数字大小没有限制,这和其他语言不同),整数可正可负,默认情况下,整数采用十进制.其他进制需要增加相应的引导符号. 如果是二进制在前 ...

  2. laravel中hasOne、HasMany、belongsTo、belongsToMany的ORM方法

    在laravel5.4框架中,使用ORM关联方法,一对一,一对多 一对一关系,代码: user表为主表,需要向下找关联表的字段用hasOne video表为关联表,需要向上找关联表的字段用belong ...

  3. c#异步方法调用

    var t1 = new Task(() => GkeyTest()); DisplaylistboxMSG("初始化:" + t1.Status.ToString()); ...

  4. 锤子剪刀布pat-1018

    题目描述 大家应该都会玩“锤子剪刀布”的游戏:现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算最大. 输入描述: 输入第1行给出正整数N(<=105),即双方交 ...

  5. js事件【续】(事件类型)

    一.UI事件[使用时需要添加on eg: onload 页面加载完成事件]load    [一张页面或一幅图像完成加载]页面加载后触发的事件,即进入页面后 unload    [用户退出页面]页面卸载 ...

  6. iOS 视图调用

    init-初始化程序 viewDidLoad-加载视图 viewWillAppear-UIViewController对象的视图即将加入窗口时调用: viewDidApper-UIViewContro ...

  7. 8 smali文件格式

    Apktool反编译apk后程序中每一个类都会有一个smali文件. 一.当前类信息:smali文件的头三行描述了当前类的一些信息. Eg: .class <访问权限> [修饰关键字]&l ...

  8. kbmmw 中的Boyer-Moore算法

    kbmmw 5.10 版本中实现了一个非常好用的字符串搜索算法,即Boyer-Moore算法. 在用于查找子字符串的算法当中,BM(Boyer-Moore)算法是目前被认为最高效的字符串搜索算法, 它 ...

  9. Pandas 之 DataFrame 常用操作

    import numpy as np import pandas as pd This section will walk you(引导你) through the fundamental(基本的) ...

  10. Linux命令groupadd

    groupadd [选项] 组 创建一个新的组.Groupadd命令使用命令行中指定的值加上系统默认值创建新的组账户.新组将根据需要输入系统. (1).选项 -f,--force 如果指定的组已经存在 ...