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

为什么runtime error,大神请解

Posted by 18726135518 at 2016-06-15 13:30:26 on Problem 3977
#include<cstdio>
#include<algorithm>
#include<map>
#include<limits>
#include<iostream>
#define maxn 500
using namespace std;
typedef long long LL;
LL Abs(const LL& x){
	return x>=0?x:-x;
}
LL a[maxn];
int n;
int main(){
	while (cin>>n && n){
		map<LL,int>b;
		for (int i=0;i<n;i++)cin>>a[i];
		pair<LL,int>result(Abs(a[0]),1);
		int half=n/2;
		for (int i=1;i<1<<half;i++){
			LL sum=0;
			int ct=0;
			for (int j=0;j<half;j++)
				if (i>>j &1){
					sum+=a[i];
					ct++;
				}
			result=min(result,make_pair(Abs(sum),ct));
			map<LL,int>::iterator it=b.find(sum);
			if (it != b.end())it->second=min(it->second,ct);
				else b[sum]=sum;
		}
		for (int i=1;i<1<<(n-half);i++){
			LL sum=0;
			int ct=0;
			for (int j=0;j<n-half;j++)
				if (i>>j &1){
					sum+=a[half+j];
					ct++;
				}
			result=min(result,make_pair(Abs(sum),ct));
			map<LL,int>::iterator it=b.lower_bound(-sum);
			if (it!=b.end())result=min(result,make_pair(Abs(it->first+sum),it->second+ct));
			if (it!=b.begin()){
				it--;
				result=min(result,make_pair(Abs(it->first+sum),it->second+ct));	
			}
		}
		cout<<Abs(result.first)<<result.second<<endl;
	}
	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