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.
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 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.
2 1 1 1
1 1 1 -1
4 3 1 2 3 1
2 2 2 1 1 2 3 1 3 2 1 1
给出一个k*k的会场,每次来一定数目的人,且同时来的人要坐在一起,总共的花费是这批人所有的花费的总和,每个人的花费定义为:这个人的位置坐标和会场的位置坐标的差值的和。
要求费用最少,如果费用一样,那个人要尽量往x小的地方坐,其次尽量往y小的地方做,对每次的人员,输出他们所在行以及所在的列的起始和终止位置
暴力模拟题目,因为题意各种理解错误,细节各种没注意,错了好多次.........
最后也没有用什么优化什么的,直接循环枚举,过了....
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,k,gra[105][105],x[1005];
int r,c;
int cost(int len,int sx,int sy)//花费
{
int mid=k-k/2;
int bg=sy-len+1,ans=0;
for(int i=bg;i<=sy;++i)
{
ans+=abs(mid-i);
}
return ans+len*abs(sx-mid);
}
void slove(int len)
{
for(int i=1;i<=k;++i)
{
int cnt=0;
for(int j=1;j<=k;++j)
{
if(!gra[i][j])
{
++cnt;
if(cnt<len)
{
continue;
}
if(c==-1||cost(len,i,j)<cost(len,r,c))
{
r=i;c=j;
}
else if(cost(len,i,j)==cost(len,r,c))
{
if(i<r||i==r&&j<c)
{
r=i;c=j;
}
}
}
else
{
cnt=0;
}
}
}
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=0;i<n;++i)
{
scanf("%d",&x[i]);
}
for(int i=0;i<n;++i)
{
r=c=-1;
slove(x[i]);
if(r!=-1&&c!=-1)
{
printf("%d %d %d\n",r,c-x[i]+1,c);
for(int j=c-x[i]+1;j<=c;++j)
{
gra[r][j]=1;
}
}
else
{
printf("-1\n");
}
}
return 0;
}
本文介绍了一种电影票务系统的模拟实现,该系统能够根据观众的需求自动分配座位,以最小化观众与影厅中心的距离,并确保同一团体的成员能够坐在连续的座位上。

581

被折叠的 条评论
为什么被折叠?



