B. Cinema Cashier

题目连接:

http://www.codeforces.com/contest/10/problem/B

Description

All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the responsibility of a special seating program. It was found out that the large majority of Berland's inhabitants go to the cinema in order to watch a movie, that's why they want to sit as close to the hall center as possible. Moreover, a company of M people, who come to watch a movie, want necessarily to occupy M successive seats in one row. Let's formulate the algorithm, according to which the program chooses seats and sells tickets. As the request for M seats comes, the program should determine the row number x and the segment [yl, yr] of the seats numbers in this row, where yr - yl + 1 = M. From all such possible variants as a final result the program should choose the one with the minimum function value of total seats remoteness from the center. Say, — the row and the seat numbers of the most "central" seat. Then the function value of seats remoteness from the hall center is . If the amount of minimum function values is more than one, the program should choose the one that is closer to the screen (i.e. the row number x is lower). If the variants are still multiple, it should choose the one with the minimum yl. If you did not get yet, your task is to simulate the work of this program.

Input

The first line contains two integers N and K (1 ≤ N ≤ 1000, 1 ≤ K ≤ 99) — the amount of requests and the hall size respectively. The second line contains N space-separated integers Mi from the range [1, K] — requests to the program.

Output

Output N lines. In the i-th line output «-1» (without quotes), if it is impossible to find Mi successive seats in one row, otherwise output three numbers x, yl, yr. Separate the numbers with a space.

Sample Input

2 1

1 1

Sample Output

1 1 1

-1

Hint

题意

有一个电影院,是k*k的,然后有n波人依次到来

每一波人都想选择尽量靠中间的位置,就是这一波人都必须坐在同一行,并且有一个花费就是abs(x-zx)+abs(y-zy)

然后你需要给他们安排座位,使得花费最小,如果花费一样,就坐左前方。

问你怎么去安排

题解:

对于每一波客人,我们都直接暴力就好了

代码

#include<bits/stdc++.h>
using namespace std;
int n,k,x;
int mp[1002][1002];
void solve(int x)
{
int px = (k+1)/2,py = (k+1)/2;
int ans1=0,ans2=0,ans3=0,ans4=1e9;
for(int i=1;i<=k;i++)
{
for(int j=1;j<=k-x+1;j++)
{
int sum = 0,flag=1;
for(int t=j;t<j+x;t++)
{
if(mp[i][t])
{
flag = 0;
break;
}
sum += abs(t-py)+abs(i-px);
}
if(flag==1&&sum<ans4)
ans4=sum,ans1=i,ans2=j,ans3=j+x-1;
}
}
if(ans4==1e9)printf("-1\n");
else
{
for(int i=ans2;i<=ans3;i++)
mp[ans1][i]=1;
printf("%d %d %d\n",ans1,ans2,ans3);
}
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&x),solve(x);
return 0;
}

Codeforces Beta Round #10 B. Cinema Cashier 暴力的更多相关文章

  1. Codeforces Beta Round #10 B. Cinema Cashier (树状数组)

    题目大意: n波人去k*k的电影院看电影. 要尽量往中间坐,往前坐. 直接枚举,贪心,能坐就坐,坐在离中心近期的地方. #include <cstdio> #include <ios ...

  2. Codeforces Beta Round #10 D. LCIS 动态规划

    D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from o ...

  3. Codeforces Beta Round #10 C. Digital Root 数学

    C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...

  4. Codeforces Beta Round #10 D. LCIS

    题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limi ...

  5. Codeforces Beta Round #10 A. Power Consumption Calculation 水题

    A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...

  6. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

  7. Codeforces Beta Round #37 B. Computer Game 暴力 贪心

    B. Computer Game 题目连接: http://www.codeforces.com/contest/37/problem/B Description Vasya's elder brot ...

  8. Codeforces Beta Round #17 A - Noldbach problem 暴力

    A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...

  9. Codeforces Beta Round #10 D. LCIS(DP&amp;LCIS)

    D. LCIS time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

随机推荐

  1. Lucene7.2.1系列(三)查询及高亮

    系列文章: Lucene系列(一)快速入门 Lucene系列(二)luke使用及索引文档的基本操作 Lucene系列(三)查询及高亮 一 准备 创建项目并添加Maven依赖 <dependenc ...

  2. Linux下帮助命令

    帮助命令(各种命令区别)   最常用的帮助命令   help --help help cd 查看内置命令的使用 info man   help cd 查看内置命令的使用   获得帮助的途径:   ma ...

  3. itext 生成pdf文件添加页眉页脚

    原文来自:https://www.cnblogs.com/joann/p/5511905.html 我只是记录所有jar版本,由于版本冲突及不兼容很让人头疼的,一共需要5个jar, 其中itextpd ...

  4. ELK&ElasticSearch5.1基础概念及配置文件详解【转】

    1. 配置文件 elasticsearch/elasticsearch.yml 主配置文件 elasticsearch/jvm.options jvm参数配置文件 elasticsearch/log4 ...

  5. Machine Learning系列--判别式模型与生成式模型

    监督学习的任务就是学习一个模型,应用这一模型,对给定的输入预测相应的输出.这个模型的一般形式为决策函数:$$ Y=f(X) $$或者条件概率分布:$$ P(Y|X) $$监督学习方法又可以分为生成方法 ...

  6. Laravel 中自定义日志目录

    参考:https://laravel-china.org/articles/7125/custom-log-directory-in-laravel

  7. 苹果容器超出内容overflow滑动卡顿问题

    -webkit-overflow-scrolling:touch; 就这么一段代码,加载需要滚动的容器css样式中.因为苹果的硬件加速产生的后果....

  8. Effective C++笔记(四):设计与声明

    参考:http://www.cnblogs.com/ronny/p/3747186.html 条款18:让接口容易被正确使用,不易被误用 1,好的接口很容易被正确使用,不容易被误用.你应该在你的所有接 ...

  9. 前端html第三方登录集合,微信,微博,QQ

    申请开发者账号之内的就不累赘了,网上一大堆: 说下需求,一个网页要在三类容器运行,公司app,微信自动登录,浏览器. 假设是已经申请完成各平台开发者账号. 先来简单的,微博和QQ 微博: 引入微博JS ...

  10. Percona XtraDB Cluster(PXC) Mysql 集群

    Percona XtraDB Cluster(PXC)   ---原理介绍篇         目录 一.简介 1 二.优缺点 2 三.区别/局限性 3 四. PXC复制原理 4 五. 服务解释 5   ...