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. iOS中响应者链条-触摸事件,hitTest方法坐标转换

    总体来说,分2个步骤: 一,从上到下寻找合适的控件来处理这个触摸事件.如下图,如果点击了黄色4,则UIApplication -> UIWindow -> 1白色 -> 2橙色 -& ...

  2. MySQL join 用法

    select column1, column2 from TABLE1 join TABLE2 on 条件 # select * from table1 join table2; #两个表合成一个se ...

  3. Deep Learning基础--各个损失函数的总结与比较

    损失函数(loss function)是用来估量你模型的预测值f(x)与真实值Y的不一致程度,它是一个非负实值函数,通常使用L(Y, f(x))来表示,损失函数越小,模型的鲁棒性就越好.损失函数是经验 ...

  4. openjudge-NOI 2.6-1775 采药

    题目链接:http://noi.openjudge.cn/ch0206/1775/ 题解: 很经典的01背包问题,设时间为t,价值为v 一维压缩,状态转移方程fj=max(fj,fj-ti+vi) # ...

  5. Linux 基础——关机重启命令shutdown、reboot等

    一.关机重启命令的作用 相信对于接触过电脑的人来说,特别是对于windows系统来说,如果长时间使用不经重启的话会出现一点点卡顿的感觉.但是当重启整个系统后,这点点卡顿的感觉好像又没了,重启后wind ...

  6. jquery datatable的详细用法

    1,首先需要引用下面两个文件 <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css ...

  7. python开发学习-day04(迭代器、生成器、装饰器、二分查找、正则)

    s12-20160123-day04 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  8. 错误:Could not create the Android package. See the Output (Build) window for more details

    错误:Could not create the Android package. See the Output (Build) window for more details. Mono For An ...

  9. 【Java】Java中常用的String方法

    本文转载于:java中常用的String方法 1 length()字符串的长度 String a = "Hello Word!"; System.out.println(a.len ...

  10. 转:Ubuntu16.04下配置php+vscode+xdebug开发环境

    转:https://blog.csdn.net/its_my_dream/article/details/78549619 操作系统是Ubuntu16.04,首先要安装和配置php运行环境,我这里用的 ...