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 loloseed at 2009-03-29 21:50:02 on Problem 1010
#include <iostream>
#include <set>
#include <vector>
#include <stack>
using namespace std;

int flag;
vector<int>res;
int typer ;
void stamp(multiset<int> &s, int left,stack<int> &st,int type,multiset<int> ::iterator it,int n,int f){
	if(n >3) return;
	for(multiset<int> ::iterator it1 = it;it1 != s.end();it1++){
		st.push((*it1));
		if( it1 != it ||(it1 == it &&f))
				type ++;
		if((*it1) < left){	
			stamp(s,left - (*it1),st,type,it1,n+1,0);
		}
		else if((*it1) == left){
			
			if(type == typer && st.size() == res.size() &&st.top() == res[res.size()-1]){
				flag = 2;
			}
			else if((type > typer) || (type == typer && st.size() < res.size()) || (type == typer && st.size() == res.size() && st.top() > res[res.size()-1])){
				res.clear();
				while(!st.empty()){
					res.push_back(st.top());
					st.pop();
				}
				for(int i = res.size()-1;i>=0;i--)
					st.push(res[i]);
				flag = 3;
				typer = type;
			}
		}
		st.pop();
		if(it1 != it ||(it1 == it &&f))
			type--;
	}
}
int main(int argc, char* argv[])
{
	multiset <int> s;
	vector <int> v;
	stack <int> st;
	int n;
	int type;
//	FILE *fp = fopen("a.txt","r");
	while(scanf("%d",&n)!= EOF){
		s.clear();
		v.clear();
		s.insert(n);
		while(scanf("%d",&n) && n)
			s.insert(n);
		while(scanf("%d",&n) && n)
			v.push_back(n);
		for(int i = 0;i<v.size();i++){
			res.clear();
			type = 0;
			typer = 0;
			flag = 1;
			stamp(s,v[i],st,type,s.begin(),0,1);
			if(flag == 1)		printf("%d%s\n",v[i]," ---- none");
			else if(flag == 2)  printf("%d %c%d%s%s\n",v[i],'(',typer,"):"," tie");
			else{
				printf("%d %c%d%s",v[i],'(',typer,"): ");
				for(int j = res.size()-1;j >=0;j--)
						if(j>0)printf("%d ",res[j]);
						else printf("%d",res[j]);
				printf("\n");
			}
		}
	}
	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