| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
极其简单的DP 就是 WA不段 郁闷啊!!
#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator