设为首页 加入收藏

TOP

BNU Concentric Rings
2014-11-23 17:44:42 来源: 作者: 【 】 浏览:6
Tags:BNU Concentric Rings

There are several different concentric rings on the ground. Some of them may overlap. In Figure 1, there are 3 rings: blue, green and red. The red one is just above the green one. The problem is to remove minimum number of rings so that no two of the remaining overlap.

Figure 1Input The input consists of multiple test cases. Each test case starts with a positive integer N (<=10000) which represents the number of rings. The next N lines each line contains two positive integers which represents the inner radius and outer radius respectively.
Output For each test case, output the minimum number of rings to remove.
Sample Input: 3
1 2
3 6
4 5
Sample Output: 1


Source
CYJJ's Funny Contest #1, Killing in Seconds


这题和杭电上有个看电视的那个一样,简单贪心题,这个题首先输入有n个环,接下来每行都是环的内半径和外半径,然后求满足不能有重叠所需要删除几个环。

#include
#include
#include
#include

using namespace std;

struct Node
{
    int inner,outer;
}a[10010];

bool cmp(Node a, Node b)
{
    return a.outer < b.outer;
}

int main()
{
    int n,i,j,sum;
    while(scanf("%d",&n)!=EOF)
    {
        sum = 0;
        for(i = 0; i < n; i++)
        {
            scanf("%d%d",&a[i].inner,&a[i].outer);
        }
        sort(a,a+n,cmp);
        j = 0;
        for(i = 1; i < n; i++)
        {
            if(a[i].inner < a[j].outer)
            {
                sum++;
                a[i].inner = a[i].outer = 0;
            }
            else
            {
                j = i;
            }
        }
        printf("%d\n",sum);
    }

    return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[C++基础]在子类中向父类的构造函.. 下一篇Triangular numbers

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·请问c语言刚入门,该 (2025-12-26 10:21:04)
·python 编程怎么定义 (2025-12-26 10:21:01)
·09-指 针 (一)-c语言 (2025-12-26 10:20:58)
·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)