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 jlsf_zym at 2009-05-07 11:08:39 on Problem 1042
#include "iostream"
#include "set"
using namespace std;

struct Data {

	int fishes;
	int d;
	int num;
	Data(int fishes, int d,int num) {
		this->fishes = fishes;
		this->d = d;
		this->num = num;
	}

	void println() {
		cout<<fishes<<"**"<<d<<"**"<<num<<endl;
	}

	bool operator < (const Data & data)const {
		if(data.fishes != fishes){
			return fishes > data.fishes;
		}else {
			if(d != data.d) {
				return d < data.d;
			}else {
				return num < data.num;
			}
		}
        
     }
		bool operator == (const Data & data)const {
		
			return (fishes == data.fishes && d == data.d && num == data.num);
		}
 
};

int main () {
	
	set<Data> st;
	int n = 0;
	cin>>n;
	while(n != 0) {
		int count = 0;
		int max = -1;
		int *f = new int [n];
		int *d = new int [n];
		int *t = new int [n];
		int * re = new int[n];
		memset(re,0,sizeof(int) * n);
		t[0] = 0;
		int hour = 0;
		int times = 0;
		cin>>hour;
		times = hour * 12;
		for(int i = 0; i < n; i ++) {
			int temp = 0;
			cin>>temp;
			f[i] = temp;
		}
		for(int i = 0; i < n; i ++) {
			int temp = 0;
			cin>>temp;
			d[i] = temp;
		}
		for(int i = 1; i < n; i ++) {
			int temp = 0;
			cin>>temp;
			t[i] = temp;
		}

		
			
		for(int i = 0; i < n; i ++) {
			st.clear();
			for(int j = 0; j <= i; j ++) {
				st.insert(Data(f[j],d[j],j));
			}
			times -= t[i];
			if(times < 0) {
				times = 0;
			}


			int temp = times;
			int * an = new int[n];
			memset(an,0,sizeof(int) * n);
			while(temp--) {
				
				Data da = *st.begin();
				
				st.erase(da);
				count += da.fishes;
				an[da.num] ++;
				int ff = da.fishes - da.d;
				if(ff > 0) {
					st.insert(Data(ff,da.d,da.num));
				}else {
					st.insert(Data(0,da.d,da.num));
				}

			}
			if(max < count) {
				max = count;
				for(int t = 0; t < n; t ++) {
					re[t] = an[t];
				}
			}
			count = 0;

		}
		if(max == 0) {
			re[0] = hour * 12;
		}
		for(int k = 0; k < n - 1; k ++) {
			cout<<re[k] * 5<<", ";
		}
		cout<<re[n - 1] * 5 << endl;
		cout<<"Number of fish expected: "<<max<<endl;
		cout<<endl;
		cin>>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