Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:Notice~暴力加scanf水过~cin。。TLE

Posted by like680623 at 2011-01-29 15:30:07 on Problem 1833
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int num[1025];
int main()
{
	//ifstream cin("a.txt");
	int tot, n, m;
	scanf("%d", &tot);
	while (tot--)
	{
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)
			scanf("%d", &num[i]);
		while (m--)
		{
			int i, signal = 0;
			for (i = n - 1; i > 0; i--)
				if (num[i] < num[i + 1])
				{
					signal = 1; break;
				}
				if (!signal)
				{
					for (int i = 1; i <= n; i++)
						num[i] = i;
					continue;
				}
			int min = 10000, k;
			for (int j = i + 1; j <= n; j++)
				if (num[j] - num[i] > 0 && num[j] - num[i] < min)
				{
					min = num[j] - num[i];
					k = j;
				}
			int temp = num[k];
			num[k] = num[i];
			num[i] = temp;
			for (int l = i + 1; l <= (n + i + 1) / 2; l++)
			{
				temp = num[l];
				num[l] = num[n + i + 1 - l];
				num[n + i + 1 - l] = temp;
			}
		}
		for (int j = 1; j <= n; j++)
			printf("%d ", num[j]);
		printf("\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator