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

Re:Notice~把菜鸟的代码贴出来。。

Posted by like680623 at 2011-01-18 22:43:17 on Problem 1716
#include<iostream>
#include<algorithm>
using namespace std;

struct Node{
	int x, y;
}node[10005];

int cmp(const void *an, const void *bn)
{
	struct Node *c = (Node *)an;
	struct Node *d = (Node *)bn;
	if (c->y == d->y)return c->x - d->x;
	return c->y - d->y;
}
int value[10005];
int main()
{
	int tot, j, sum = 0;
	cin>>tot;
	for (int i = 0; i < tot; i++)
		scanf("%d%d", &node[i].x, &node[i].y);
	memset(value, 0, sizeof(value));
	qsort(node, tot, sizeof(node[0]), cmp);
	for (int i = 0; i < tot; i++)
	{
		int s = 0;
		for (j = node[i].x; j <= node[i].y; j++)
		{
			if (value[j] == 1)s++;
		}
		--j;
		while (s < 2)
		{
			if (value[j] == 0)
			{
				s++;
				value[j--] = 1;
			}
		}
	}
	//AC~~~~太搞兴啦~~~~~~~
	for (int i = 0; i <= node[tot - 1].y; i++)
		if (value[i] == 1)sum++;
	cout<<sum<<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