比赛 20120217 评测结果 AAAAAAAAAA
题目名称 编码问题 最终得分 100
用户昵称 Citron酱 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-02-17 19:45:18
显示代码纯文本
#include <fstream>

#define I_F "code.in"
#define O_F "code.out"

const short Maxn=100;
const short Maxm=100;

std::ifstream fin(I_F);
std::ofstream fout(O_F);

short n,m,p;
short s[Maxn],ans[Maxn];

inline void Input();
inline void Search1();
inline void Search2();
inline void Output();

int main()
{
	fin>>m>>n;
	for (short i=0; i<m; i++)
	{
		Input();
		if (p==1)
			Search1();
		else
			Search2();
		Output();
	}
	fin.close();
	fout.close();
	return 0;
}

inline void Input()
{
	fin>>p;
	for (short i=0; i<n; fin>>s[i++]);
}

inline void Search1()
{
	for (short i=0; i<n; ans[i++]=0);
	for (short i=1; i<n; i++)
		for (short j=0; j<i; j++)
			if (s[j]<s[i])
				ans[i]++;
}

inline void Search2()
{
	bool f[Maxn]={false};
	short k;
	for (short i=n-1; i>=0; i--)
	{
		k=0;
		for (short j=0; j<n; j++)
			if (!f[j])
			{
				if (k<s[i])
					k++;
				else
				{
					ans[i]=j;
					f[j]=true;
					break;
				}
			}
	}
}

inline void Output()
{
	for (short i=0; i<n-1; fout<<ans[i++]<<' ');
	fout<<ans[n-1]<<std::endl;
}