⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3047077_ac_45ms_152k.cpp

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CPP
字号:
#include <stdio.h>
#include <algorithm>

using namespace std;

struct node
{
	int w, d;
}cake[111], t;

int n, w, d;

bool cmp(node a,node b)
{
	return a.w*a.d<b.w*b.d;
}

int main()
{
	int i, j, id;
	int p, s;
	node tt;

	while(scanf("%d%d%d",&n,&w,&d)==3)
	{
		if(n==0&&w==0&&d==0)
		{
			break;
		}
		cake[1].w = w;
		cake[1].d = d;
		id = 2;
		for(i = 0; i < n; i++)
		{
			scanf("%d%d",&p,&s);
			tt = cake[p];
			for(j = p+1; j < id; j++)
			{
				cake[j-1] = cake[j];
			}
			id--;
			s %= 2*(tt.d+tt.w);
			if(s < tt.w || (s > tt.w+tt.d && s < 2*tt.w+tt.d))
			{
				if(s > tt.w)
				{
					s = 2*tt.w+tt.d-s;
				}
				t.w = tt.w-s;
				tt.w = s;
				t.d = tt.d;
				if(t.w < tt.w)
				{
					swap(t,tt);
				}
			}
			else
			{
				if(s < tt.w+tt.d)
				{
					s -= tt.w;
				}
				else
				{
					s = 2*(tt.w+tt.d)-s;
				}
				t.w = tt.w;
				t.d = tt.d - s;
				tt.d = s;
				if(t.d < tt.d)
				{
					swap(t,tt);
				}
			}
			cake[id++] = tt;
			cake[id++] = t;
		}
		sort(&cake[1],&cake[1]+id-1,cmp);
		printf("%d",cake[1].w*cake[1].d);
		for(i = 2; i < id; i++)
		{
			printf(" %d",cake[i].w*cake[i].d);
		}
		printf("\n");
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -