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

极其简单的DP 就是 WA不段 郁闷啊!!

Posted by hokey at 2008-03-31 22:10:41 on Problem 1609 and last updated at 2008-03-31 22:14:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MAX 10101

int dp[MAX];		
struct  tt{
	int l;
	int r;
}block[MAX];

int cmp(void const *a, void const *b)
{
	if(((struct tt*)a)->l == ((struct tt*)b)->l)
		return ((struct tt*)a)->r - ((struct tt*)b)->r;
	else
		return ((struct tt*)a)->l - ((struct tt*)b)->l;
}

int main()
{
	int i, n;
//	freopen("d.txt","r",stdin);
	while(scanf("%d", &n) && n)
	{
		memset(dp, 0 ,sizeof(dp));
		for(i=0; i<n; i++)	scanf("%d%d", &block[i].l, &block[i].r);
		qsort(block, n,sizeof(block[0]), cmp);			//  从小到大排
		dp[0] = 1;
		for(i=1; i<n; i++)
			if(block[i].r >= block[i-1].r)
				dp[i] = dp[i-1] + 1;
			else
				dp[i] = dp[i-1];
		printf("%d\n", dp[n-1]);
	}
	putchar('*');
	return 1;
}

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