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-03-10 22:51:05 on Problem 1999
这道题目我在zoj和这里都过不了 郁闷1个晚上 是不是找2行数中 每个数最后一次出现的位置呢?我觉得是的 再qsort
但是一直错。 郁闷啊。求救,谢谢各位。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int size=sizeof(int);
 
int p[210002];//记录某种牌最晚出现轮数
int h[200002];  //工作数组


int cmp(const void *a,const void *b) {
	return *(int *) a-*(int *) b;
}

int main() {
int z,num,m,n,i,x,t;
	for (scanf("%d",&z);z>0;--z) {
		
		scanf("%d%d",&n,&m);
		memset(p,0,sizeof(p));
		for (i=0;i<n;++i) {
			scanf("%d",&x);
			h[i]=i;
			p[x]=i+1;
		}
		num=n;
		for (i=0;i<m;++i) {
			scanf("%d",&x);
			t=p[x];
			if (t==0) 
				h[num++]=i;
			else if (i+1>t) 
				h[t-1]=i;
		}

		qsort(h,num,size,cmp);
		for (i=0;i<num;++i)
			if (h[i]>i) 
				break;
		printf("%s\n",(i<num)?"Spatne usporadani.":"Hrac ma sanci vyhrat.");
	}
	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