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 javaman at 2005-04-18 15:44:57 on Problem 1407
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

typedef struct {
int who;
int price;
bool type; //true---sell false---buy
} VVV;

int have[26],total[26],id[1001];
char name[1001][11];
vector<VVV> v[26];
int maxi[26],mini[26],pay[1001],rec[1001],num;
char s[21];

int cmp(const void *a,const void *b) {
	return strcmp(name[*(int *) a],name[*(int *) b]);
}


int findname(char *s) {
int i;
	for (i=0;i<num;++i) 
		if (!strcmp(name[i],s))
			return i;
	strcpy(name[num],s);
	pay[num]=rec[num]=0;
	id[num]=num;
	return num++;
}

void dowith(VVV t,int thing) {
vector<VVV>::iterator tt,should;
int high,low,p;

	if (t.type) { //sell
		high=-1;
		for (tt=v[thing].begin();tt!=v[thing].end();++tt) 
			if ((!tt->type) && (tt->price>=t.price) && (tt->price>high) && (tt->who!=t.who)) {
				high=tt->price;
				should=tt;
			}
			
		if (high>=0){
			p=(t.price+high)>>1;
			if (have[thing]) {
				if (p>maxi[thing])
					maxi[thing]=p;
				if (p<mini[thing])
					mini[thing]=p;
			}
			else 
				maxi[thing]=mini[thing]=p;
			++have[thing];
			total[thing]+=p;
			pay[should->who]+=p;
			rec[t.who]+=p;
		}
		else 
			v[thing].push_back(t);
	} 
	else {  // buy
			low=10000;
			for (tt=v[thing].begin();tt!=v[thing].end();++tt) 
				if ((tt->type) && (tt->price<=t.price) && (tt->price<low) && (tt->who!=t.who)) {
					low=tt->price;
					should=tt;
				}
			if (low<10000) {
				p=(t.price+low)>>1;
				if (have[thing]) {
					if (p>maxi[thing])
						maxi[thing]=p;
					if (p<mini[thing])
						mini[thing]=p;
				}
				else 
					maxi[thing]=mini[thing]=p;
				++have[thing];
				total[thing]+=p;
				rec[should->who]+=p;
				pay[t.who]+=p;
			}
			else
				v[thing].push_back(t);
		
	}
}






int main() {
int i,n,thing;
VVV temp;

	while (true) {
		scanf("%d",&n);
		if (!n)
			break;
		for (i=0;i<26;++i) {
			v[i].clear();
			have[i]=total[i]=0;
		}
		num=0;
		for (i=0;i<n;++i) {
			scanf("%s",s);
			temp.who=findname(s);
			scanf("%s",s);
			temp.type=(s[0]=='S');
			scanf("%s",s);
			thing=s[0]-65;
			scanf("%d",&temp.price);
			dowith(temp,thing);
		}
		for (i=0;i<26;++i)
			if (have[i]) 
				printf("%c %d %d %d\n",(char) (i+65),mini[i],total[i]/have[i],maxi[i]);
		printf("--\n");
		qsort(id,num,sizeof(int),cmp);
		for (i=0;i<num;++i)
			printf("%s %d %d\n",name[id[i]],pay[id[i]],rec[id[i]]);
		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