| ||||||||||
| 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 | |||||||||
Re:Notice~把菜鸟的代码贴出来。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator