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 andytom at 2005-04-02 00:23:19 on Problem 2380
#include<iostream.h>
#include<string.h>
#include<stdio.h>

long b[1000][1000]; 
struct node{
	long qi,si,vi;
};
int find1(node r[],long n,long&k)
{
	k=1;
	b[0][1]=r[0].qi;
	for(long i=1;i<n;i++){
		if(r[i].qi!=r[i-1].qi){
			b[0][k+1]=r[i].qi;
			r[i-1].qi=k;
			k++;
		}
		else r[i-1].qi=k;
	}
	r[n-1].qi=k;
	return 0;
}

int find2(node r[],long n,long&k)
{
	k=1;
	b[1][0]=r[0].si;
	for(int i=1;i<n;i++){
		if(r[i].si!=r[i-1].si){
			b[k+1][0]=r[i].si;
			r[i-1].si=k;
			k++;
		}
		else r[i-1].si=k;
	}
	r[n-1].si=k;
	return 0;
}
		


int binsort1(node r[],long n)
{
	for(long i=1;i<n;i++){
		node temp=r[i];
		long low=0;
		long high=i-1;
		long mid;
		while(low<=high){
			mid=(low+high)/2;
			if(temp.qi<r[mid].qi)
			high=mid-1;
			else low=mid+1;
		}
		for(long j=i-1;j>=low;j--)
			r[j+1]=r[j];
			r[low]=temp;
	}
	return 0;
}
int binsort2(node r[],long n)
{
	for(long i=1;i<n;i++){
		node temp=r[i];
		long low=0;
		long high=i-1;
		long mid;
		while(low<=high){
			mid=(low+high)/2;
			if(temp.si<r[mid].si)
			high=mid-1;
			else low=mid+1;
		}
		for(long j=i-1;j>=low;j--)
			r[j+1]=r[j];
			r[low]=temp;
	}
	return 0;
}
int main()
{ 
	long n;
	long k;
	long l;
memset(b,0,sizeof(b));
	cin>>n;
	node*a=new node[n];
	for(long i=0;i<n;i++){
		cin>>a[i].qi>>a[i].si>>a[i].vi;
	}
	binsort1(a,n);
	find1(a,n,k);
	binsort2(a,n);
	find2(a,n,l);


b[0][0]=-1;
for(i=0;i<n;i++){
	b[a[i].si][a[i].qi]+=a[i].vi;
}
for(i=0;i<l+1;i++){
	for(long j=0;j<k;j++){
		cout<<b[i][j]<<" ";
	}
	cout<<b[i][k]<<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