10B - Cinema Cashier

原题链接

模拟模拟模拟,感觉我的复杂度 \(O(N K^3)\)\(N = 1000, K = 100\)居然能过

题意:
数批人依次来到电影院,每批人都希望尽可能坐中间,并且只能坐在同一行,问你怎么安排座位。

思路:暴力枚举计算。。。

代码如下

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set> 
#include<iomanip>
#define IOS 	cin.tie(0), ios::sync_with_stdio(false) 
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 105, M = 10010, mod = 1e9;
const double eps = 1e-4;
const double pi = acos(-1);
const int P = 131;

bool st[N][N];
int n, k, a, b;


int main()
{
	IOS;
	cin >> n >> k;
	a = b = (k + 1) / 2;
	while(n --)
	{
		int x;
		cin >> x;
		int sum = 1e9, l = 0, r = 0, c = 0;
		for(int i = 1 ; i <= k ; i ++)
		{
			for(int j = 1 ; j + x - 1 <= k ; j ++)
			{
				while(j + x - 1 <= k)
				{
					int d = 0;
					bool flag = true;
					for(int l = j ; l < j + x ; l ++)
						if(st[i][l])
							d = l, flag = false;
					if(d)	j = d + 1;
					if(flag) break;
				}
				if(j + x - 1 <= k)
				{
					int all = 0;
					for(int l = j ; l < j + x ; l ++)
						all += abs(i - a) + abs(l - b);
					if(all < sum)
					{
						sum = all;
						l = j, r = j + x - 1; 
						c = i;
					}
				}
			}
		}
		for(int j = l ; j <= r ; j ++) 
			st[c][j] = true;
		if(l && r)
			cout << c << " " << l <<" " << r << endl; 
		else cout << -1 << endl;
	}

	return 0;
}
posted @ 2021-04-06 22:30  beatlesss  阅读(179)  评论(0)    收藏  举报