CodeForces 597B Restaurant

简单贪心。

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;

int n;
const int maxn=500000+10;
struct X
{
    int L,R;
}s[maxn];

bool cmp(const X&a,const X&b)
{
    if(a.R==b.R) return a.L<b.L;
    return a.R<b.R;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&s[i].L,&s[i].R);
    sort(s+1,s+1+n,cmp);
    int ans=0,pre=0;;
    for(int i=1;i<=n;i++)
    {
        if(s[i].L>pre)
        {
            pre=s[i].R;
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}
时间: 2024-07-30 10:20:27

CodeForces 597B Restaurant的相关文章

Codeforces 597B Restaurant(离散化 + 贪心)

题目链接 Restaurant 题目意思就是在n个区间内选出尽可能多的区间,使得这些区间互不相交. 我们先对这n个区间去重. 假如有两个区间[l1, r1],[l2, r2] 若满足l1 >= l2且 r1 <= r2,那么[l2, r2]就是可以被去掉的. 因为这两个区间里我们显然最多只能选择一个. 如果我们在答案里选择了[l2, r2],那么我们如果把[l2, r2]换成[l1, r1]的话 这个答案肯定还是满足题意的. 甚至可能腾出了可以放下其他区间的空间. 那么我们去重之后进行离散化,

codeforces 261B Maxim and Restaurant(概率DP)

B. Maxim and Restaurant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has

【CodeForces 261B】Maxim and Restaurant(DP,期望)

题目链接 第一种解法是$O(n^3*p)$的:f[i][j][k]表示前i个人进j个人长度为k有几种方案(排列固定为123..n时).$f[i][j][k]=f[i-1][j][k]+f[i-1][j-1][k-a[i]]$最外层枚举t表示被卡的那个人.i=t时不加上f[i-1][j-1][k-a[i]].$ans={{(\sum f[n][j][k]*j*j!*(n-1-j)!)+(\sum f[n][n][k]*n)}}/(n!)$. 可以看看这篇题解 #include<cstdio> #

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B

Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seate

codeforces#536题解

CodeForces#536 A. Lunar New Year and Cross Counting Description: Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix \(M\) of size \(n \times n\) contains only 'X' and '.' (without quotes). The element in t

Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers

原文链接:https://www.cnblogs.com/xwl3109377858/p/11404050.html Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburg

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th