zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #10 B. Cinema Cashier 暴力

    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
    ");
        else
        {
            for(int i=ans2;i<=ans3;i++)
                mp[ans1][i]=1;
            printf("%d %d %d
    ",ans1,ans2,ans3);
        }
    }
    int main()
    {
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)
            scanf("%d",&x),solve(x);
        return 0;
    }
  • 相关阅读:
    绕过校园网认证实现免费上网【三端】
    Java多线程下载器FileDownloader(支持断点续传、代理等功能)
    Java实现命令行中的进度条功能
    记一次基于Cloudflare服务的爬虫
    如何修改npm包源码后,重新npm包的时候能是修改后的版本
    将html片段的文本内容取出来
    阿里云的oss的文件资源链接强制下载
    常用正则记录
    flvjs的unload(),detachMediaElement(),destroy()报错,undefined,not a function解决方案
    微信扫码登陆,qq登陆,微博登陆等第三方登陆成功后返回原来的页面并进行跳转
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5438946.html
Copyright © 2011-2022 走看看