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

谁能比我还惨!!! 求各路大神。。。

Posted by swuroyalty at 2011-03-22 19:03:25 on Problem 1010
以上各位所说数据均能过, 但是就不AC

无奈求大神!
源码如下:
#include<istream>
#include<algorithm>
using namespace std;

#include<cstdio>

int type_num=0;
int max1=0;
int min1=0;

int array[65];

int jie[4];
int type[4];
int num_jie=0;
bool is_equal=0;
int cc=0;

//template<class T>
void swap(int &a, int &b)
{
	int t=a; 
	a=b; 
	b=t;
}

struct ourdata{
	int data_;
	int type_;
	ourdata(int data=0, int type=-1):data_(data), type_(type){}
	bool operator <(ourdata &other)
	{
		if(data_<other.data_)
		{
			return true;
		}
		else if(data_==other.data_)
		{
			return type_<other.type_?true:false;
		}
		else
		{
			return false;
		}
	}
};

struct solution{
	struct ourdata data_[4];
	int num_;
	int type_;	
	int max_val_;
	solution(){}
	void set(ourdata *data, int num)
	{
		num_=num;
		max_val_=0;
		for(int i=0; i<num; i++)
		{
			data_[i]=data[i];
			if(max_val_<data_[i].data_) max_val_=data_[i].data_;
		}
		
		type_=num;
		for(int x=0; x<num-1; x++)
		{
			for(int y=x+1; y<num; y++)
			if(data_[x].type_==data_[y].type_)
				type_--;
		}
		
		for(int i=0; i<num-1; i++)
		{
			int tmp=i;
			for(int j=i+1; j<num; j++)
			{
				//if(data_[j].data_<data_[tmp].data_)
				if(data_[j]<data_[tmp])
					tmp=j;
			}
			if(tmp!=i)
			{
				//swap(data_[i], data_[tmp]);
				swap(data_[i].data_, data_[tmp].data_);
				swap(data_[i].type_, data_[tmp].type_);
			}
		}
	}
	
	void display()
	{
		for(int i=0; i<num_; i++)
		{
			printf("%d ", data_[i].data_);
		}
		printf("\n");
		
		for(int i=0; i<num_; i++)
		{
			printf("%d ", data_[i].type_+1);
		}
		printf("\n");
	}

};


solution solution_a, solution_b, temp;

int compare_solution(solution &a, solution &b)
{
	if(a.type_>b.type_)
	{
		return 1;
	}
	else if(a.type_<b.type_)
	{
		return -1;
	}
	else
	{
		if(a.num_<b.num_)
		{
			return 1;
		}
		else if(a.num_>b.num_)
		{
			return -1;
		}
		else
		{
			if(a.max_val_>b.max_val_)
			{
				return 1;
			}
			else if(a.max_val_<b.max_val_)
			{
				return -1;
			}
			else
			{
				for(int i=0; i<a.num_; i++)
				{
					if((a.data_)[i].data_==(b.data_)[i].data_&&(a.data_)[i].type_==(b.data_)[i].type_)
					//daozheli
						;
					else
						return 0;
				}
				return 2;
			}
		}
	}
	
}



void process(int val, int k)
{
	if(val==0)
	{
		//jilu shuju; bijiao
		ourdata my_data[4];
		for(int i=0; i<num_jie; i++)
		{
			my_data[i].data_=jie[i];
			my_data[i].type_=type[i];
		}
		cc++;
		if(cc==1)
		{
			is_equal=0;
			solution_a.set(my_data, num_jie);
		}
		else if(cc==2)
		{
			temp.set(my_data, num_jie);
			//printf("solution_a:\n");
			//solution_a.display();
			//printf("temp:\n");
			//temp.display();
			int ret=compare_solution(solution_a, temp);

			if(ret==-1)
			{
				is_equal=0;
				solution_a.set(my_data, num_jie);
				//cc--;
			}
			else if(ret==0)
			{
				is_equal=1;
				//solution_b.set(jie, num_jie);
				//solution_b.set_types(type);
				//cc--;
			}

			cc--;
		}
		//printf("is_equal=%d\n", is_equal);
					
		return; 
	}
	else if(val<0)
	{
		return;
	}
	else if(k==4) 
	{
		if(val==0)
		{
			ourdata my_data[4];
			for(int i=0; i<num_jie; i++)
			{
				my_data[i].data_=jie[i];
				my_data[i].type_=type[i];
			}
			cc++;
			if(cc==1)
			{
				is_equal=0;
				solution_a.set(my_data, num_jie);
			}
			else if(cc==2)
			{
				temp.set(my_data, num_jie);
				//printf("solution_a:\n");
				//solution_a.display();
				//printf("temp:\n");
				//temp.display();
				int ret=compare_solution(solution_a, temp);
	
				if(ret==-1)
				{
					is_equal=0;
					solution_a.set(my_data, num_jie);
					//cc--;
				}
				else if(ret==0)
				{
					is_equal=1;
					//solution_b.set(jie, num_jie);
					//solution_b.set_types(type);
					//cc--;
				}
	
				cc--;
			}
			
			//printf("is_equal=%d\n", is_equal);
		}
		
		return; 
	}
	else
	{
		for(int i=0; i<type_num; i++)
		{
			//swap(array[k], array[i]);
			jie[num_jie]=array[i];
			type[num_jie]=i;
			num_jie++;
			process(val-array[i], k+1);
			num_jie--;
			//swap(array[k], array[i]);
		}
	}
} 

int main()
{
	
	while(scanf("%d",&array[type_num])!=EOF)
	{
		max1=array[type_num];
		min1=array[type_num];
		type_num++;
		while(scanf("%d",&array[type_num])!=EOF&&array[type_num]!=0)
		{
			if(max1<array[type_num])
				max1=array[type_num];
			if(min1>array[type_num])
				min1=array[type_num];
			type_num++;
		}
		//type_num--;
		//printf("type_num=%d------------\n",type_num);
		int val;
		while(scanf("%d",&val)!=EOF&&val!=0)
		{
			process(val, 0);
			if(cc==0)
			{
				printf("%d ---- none\n",val);
			}
			else if(cc==1)
			{
				if(is_equal)
				{
					printf("%d (%d): tie\n",val, solution_a.type_);
					/*
					printf("%d (%d): ",val, solution_a.num_);
					for(int x=0; x<solution_a.num_; x++)
						printf("%d ", (solution_a.data_[x].data_));
					printf("\n");
					
					printf("%d (%d): ",val, temp.type_);
					for(int x=0; x<temp.num_; x++)
						printf("%d ", (temp.data_[x].data_));
					printf("\n");
					*/
				}
				else
				{
					printf("%d (%d): ",val, solution_a.type_);
					for(int x=0; x<solution_a.num_; x++)
					{	
						if(x!=solution_a.num_-1)
							printf("%d ", (solution_a.data_[x].data_));
						else
							printf("%d\n", (solution_a.data_[x].data_));
					}
				}
			}
			cc=0;
			is_equal=0;	
			num_jie=0;
		}
		type_num=0;
		max1=0;
		min1=0;
	}
	//system("pause");
}

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