Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么runtime error,大神请解#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator