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

测试了N组数据都没问题,但是依然WAWA。。。

Posted by pluie at 2010-08-05 16:22:23 on Problem 3253
#include<stdio.h>
#define MAX 20005
#define M 65530
int main()
{
    __int64 cost=0;//某位大虾说这里必须要用64位整型才能ac
	int N;      
        long int a[MAX]={0};//存放输入数据
	int i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%ld",&a[i]);
	}
        long int m1,m2;
	 int x1,x2;
	for(i=N;i<2*N-1;i++)
	{
	    m1=M;
	    m2=M;
	    x1=0;
		x2=0;
		for(j=0;j<i;j++)
		{
		   if(a[j]<m1&&a[j]!=-1)//选出两个最小的值
		   {
			  m2=m1;
			  x2=x1;
  	                  m1=a[j];
			  x1=j;
			  
		   }
		   else if(a[j]<m2&&a[j]!=-1)//同上
		   {
		   	m2=a[j];
		   	x2=j;
		   }
		 }
		 
		   a[x1]=-1;//将用过的值标记
		   a[x2]=-1;
		   a[i]=m1+m2;//记录a[N]到a[2*N-2]的值,就是需要加的值
		   cost+=a[i];	   //每轮更新cost     
	}
	printf("%I64d\n",cost);
	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