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

这道题是这么做的吗?wa得不行了

Posted by xiaol at 2005-10-30 17:02:12 on Problem 2362
#include <iostream>
using namespace std;
int main() {
	int n,i,j,a[21];
	int t,d,count;
	int len,tem,tp,p;
	cin>>d;
	for(t=0;t<d;t++){
		cin>>n;
		len=0; tp=1;
		for(i=0;i<n;i++) {
			tp*=2;
			cin>>a[i];
			len+=a[i];
		}
		if(len%4!=0){
			cout<<"no"<<endl;
			continue;
		}
		len/=4;count=0;
		for(i=0;i<tp;i++) {
			p=i;
			j=n-1;
			tem=0;
			while(p) {
				tem+=a[j]*(p&1);
				--j;
				p>>=1;
			}
			if(tem==len){
				++count;
				if(count==4)break;
			}
		}
		if(count==4)cout<<"yes"<<endl;
		else cout<<"no"<<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