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:和你一样的思路,或许可以参考一下(用C++提交就对了,耗时600多秒,用C就会出现编译错误,晕)

Posted by rainstorm at 2007-08-26 10:25:53 on Problem 1674
In Reply To:我的为什么超时啊!! help!!!!!!!!!!!!!!!!!!! Posted by:sun_huangjian at 2007-08-25 11:35:20
#include <stdio.h>
int main()
{
	int t, n, number;
	int i, k, temp;
	int integer[10000] = {0};
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		number = 0;
		for(i = 0; i < n; i++)
		{
			scanf("%d", &integer[i]);
		}
        for(i = 0; i < n-1; i++)
		{
			//选择出最小的数
			if(integer[i] != i+1)
			{
            	for(k = i+1; k < n; k++)
				{
					if(integer[k] == i+1)
					{
	    	        	temp = k;
						break;
					}
				}
  		    	int temp_integer;
				temp_integer = integer[temp];
                integer[temp] = integer[i];
			  	integer[i] = temp_integer;
        	   	number++;			
			}
		}
		printf("%d\n", number);
	}
	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