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:求救今天的D

Posted by Fank at 2008-09-18 20:23:02
In Reply To:顶起 Posted by:Thank_you at 2008-09-18 12:11:47
http://acm.hust.edu.cn/thx/problem.php?cid=1024&pid=3

这个题目怎么做

这个程序哪错了?
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define type long long

type v[50050];

int  main()
{
	int T;
	type x1,x2,n,k,i,p,t,all,ans;
	cin>>T;
	while(T--)
	{
		x1=1,x2=0;
		scanf("%lld%lld",&n,&k);
		all=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&v[i]);
			all+=v[i];
		}
		t=-all;
		sort(v+1,v+n+1);
		p=-n;
		if((k-all)/p<=v[1])
			x1=(k-all)/p;
		else
		{
			p+=2;
			all-=v[1]*2;
			for(i=2;p<0;i++,p+=2)
			{
				if((k-all)/p>v[i-1] && (k-all)/p<=v[i])
				{
					x1=(k-all)/p;
					break;
				}
				all-=v[i]*2;
			}
		}
		p=n;
		if((k-t)/p>=v[n])
			x2=(k-t)/p;
		else
		{
			p-=2;
			t+=v[n]*2;
			for(i=n;p>0;i--,p-=2)
			{
				if((k-t)/p>=v[i-1]&&(k-t)/p<v[i])
				{
					x2=(k-t)/p;
					break;
				}
				t+=v[i-1]*2;
			}
		}
		ans=x2-x1+1;
		printf("%lld\n",ans);		
	}
	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