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. 【IDEA】与Eclipse "Link with Editor"等价功能设置

    Link With Editor是Eclipse内置功能中十分小巧,但却异常实用的一个功能.这个开关按钮 (Toggle Button) 出现在各式导航器视图 ( 例如 Resource Explor ...

  2. Mysql自带profiling性能分析工具使用分享

    1. show variables like '%profiling%';(查看profiling信息)       2. set profiling=1;(开启profiling)   3. 执行S ...

  3. ASCII-->Ansi-->Unicode-->UTF8 关于编码 自己的总结

    各种不同的编码 无非就是效率 最大化. 我猜测编码的进化流程: ASCII(American Standard Code for Information Interchange)----满足了美国和西 ...

  4. HTML 禁止显示input默认提示信息

    看问题 html代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  5. go的匿名组合

    golang也提供了继承机制,但采用组合的文法,因此称为匿名组合.与其他语言不同, golang很清晰地展示出类的内存布局是怎样的. 一  非指针方式的组合 1)基本语法 type base stru ...

  6. [转]Java中堆和栈创建对象的区别

    转载自http://blog.csdn.net/hbhhww/article/details/8152838 栈与堆都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序 ...

  7. 【PAT】1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN- ...

  8. ssh连接远程主机免密登入

    核心思想: 1.本地主机生成公钥私钥,私钥自己存着,公钥传到远程主机.ssh文件夹下authorized_keys文件(默认是这个,用追加的方式) 2.本地连接远程主机,公私钥对上就可以免密登入了. ...

  9. 《java虚拟机》----线程安全和锁优化

    No1: 线程安全:当多个线程访问一个对象时,如果不用考虑这些线程在运行环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方进行任何其他的协调操作,调用这个对象的行为都可以获得正确的结果,那这 ...

  10. 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array

    题目描述 Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...