zoukankan      html  css  js  c++  java
  • CF1060D Social Circles

    题目描述

    现在有N个人,每一个人都不想周围的人坐得离他很近,所以在他的左边至少要放L[i]张椅子,右边至少要放R[i]张椅子.

    现在他们要坐成若干个圈,请问最少要放多少张椅子.

    注意:可以一个人坐在一个圈内.每一个人还需要坐一张椅子.

    输入输出样例

    输入

    3
    1 1
    1 1
    1 1

    输出

    思路

    贪心,贪心策略,对所有左手及右手位置分别排序,再从1~n or n~1 对于排序后的每一对R【i】and L【i】取max并累加即可

    AC code

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    int n;
    int L[1000001],R[1000001];
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++)cin>>L[i]>>R[i];
        sort(L+1,L+n+1);
        sort(R+1,R+n+1);
        long long ans=n;
        for(int i=1;i<=n;i++){
            ans+=max(L[i],R[i]);
        }
        cout<<ans;
        return 0;
    }
    View Code
  • 相关阅读:
    bootstrap
    bootstrap
    bootstrap
    【k8s】Pod-terminationGracePeriodSeconds
    【k8s】Pod-tolerations
    【k8s】Pod-nodeSelector
    【k8s】Pod-nodeName
    【k8s】Pod-hostname
    【k8s】Pod-hostPID
    【k8s】Pod-hostNetwork
  • 原文地址:https://www.cnblogs.com/Larry-Zero/p/11727317.html
Copyright © 2011-2022 走看看