【bzoj2882】工艺

题目描述:

小敏和小燕是一对好朋友。
他们正在玩一种神奇的游戏,叫Minecraft。
他们现在要做一个由方块构成的长条工艺品。但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方块放到最右边。
他们想,在仅这一个操作下,最漂亮的工艺品能多漂亮。
两个工艺品美观的比较方法是,从头开始比较,如果第i个位置上方块不一样那么谁的瑕疵度小,那么谁就更漂亮,如果一样那么继续比较第i+1个方块。如果全都一样,那么这两个工艺品就一样漂亮。

输入:

第一行两个整数n,代表方块的数目。
第二行n个整数,每个整数按从左到右的顺序输出方块瑕疵度的值。

输出:
一行n个整数,代表最美观工艺品从左到右瑕疵度的值。

样例输入:
10
10 9 8 7 6 5 4 3 2 1

样例输出:
1 10 9 8 7 6 5 4 3 2

题解:

求最小表示法。之前在bzoj上交了一发ac了,结果被同学x掉了qaq。以下是正确(应该吧)= =

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 300010
#define cmod(_x, mod) ((_x) > mod ? (_x) - mod : (_x))
int a[maxn];
int main()
{
	R int n = FastIn();
	for (R int i = 0; i < n; ++i) a[i] = FastIn();
	R int i = 0, j = 1, k = 0;
	while (i < n && j < n && k < n)
	{
		R int tmp = a[(i + k) % n] - a[(j + k) % n];
		if (!tmp) k++;
		else
		{
			if (tmp > 0) i += k + 1;
			else j += k + 1;
			if (i == j) ++j;
			k = 0;
		}
	}
	j = dmin(i, j);
	for (R int i = j; i < n; ++i) printf("%d ",a[i] );
	for (R int i = 0; i < j - 1; ++i) printf("%d ",a[i] );
	if (j > 0) printf("%d\n",a[j - 1] );
	return 0;
}
/*
hack:
input:
5
2 1 1 1 1
output:
1 1 1 1 2
*/



 

posted @ 2016-03-28 11:44  cot  阅读(269)  评论(0编辑  收藏  举报