Social Circles

2024-09-04 23:38
文章标签 circles social

本文主要是介绍Social Circles,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

来自codeforces

You invited nn guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles.

Your guests happen to be a little bit shy, so the ii-th guest wants to have a least lili free chairs to the left of his chair, and at least riri free chairs to the right. The “left” and “right” directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the lili chairs to his left and riri chairs to his right may overlap.

What is smallest total number of chairs you have to use?

Input
First line contains one integer nn — number of guests, (1⩽n⩽1051⩽n⩽105).

Next nn lines contain nn pairs of space-separated integers lili and riri (0⩽li,ri⩽1090⩽li,ri⩽109).

Output
Output a single integer — the smallest number of chairs you have to use.

inputCopy
3
1 1
1 1
1 1
outputCopy
6
inputCopy
4
1 2
2 1
3 5
5 3
outputCopy
15
inputCopy
1
5 6
outputCopy
7
Note
In the second sample the only optimal answer is to use two circles: a circle with 55 chairs accomodating guests 11 and 22, and another one with 1010 chairs accomodationg guests 33 and 44.
In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.

题意一个人开晚会要叫朋友但他的朋友很害羞 需要左右两边都有空位求最小需要多少椅子,
这个题是真的不好看出来是贪心,看出来是贪心后就非常简单了(好神奇)
只需要将每个人的左边和右边分别排序,每次只需将大的空椅子(多的空椅子可以包含少的空椅子)+1(因为客人也要坐)这样就可以得出答案还有注意数据的大小用longlong。

#include <cmath>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int n,a[100009],b[1000009];
int main()
{long long int s=0;while(cin>>n){s=0;for(int i=0;i<n;i++){cin>>a[i]>>b[i];}sort(a,a+n);sort(b,b+n);for(int i=0;i<n;i++){s+=max(a[i],b[i])+1;}cout<<s<<endl;}return 0;
}

这篇关于Social Circles的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1137365

相关文章

--uva247(calling circles)强联通与floyd-warshell

图论题:一开始我是用tarjan算法做的,wrong answer 了很多次,然后又用了floyd-warshell算法,也wa了 最后找了题解,原来最后的dataset后面不是组数,是样例的编号,题根本就没说,让人怎么理解。。。 tarjan #include<stdio.h>#include<iostream>#include<string.h>#include<string>#

BSCI(Business Social Compliance Initiative)验厂

在当今全球化的经济环境中,企业社会责任(Corporate Social Responsibility, CSR)已成为衡量企业成功与否的重要标尺之一。而BSCI(Business Social Compliance Initiative)验厂,作为国际间广泛认可的社会责任审核体系,不仅是对企业供应链管理的一种严格考验,更是推动企业践行可持续发展理念、维护劳工权益、促进环境友好型生产的重要机制。本

Qt5官方demo解析集34——Concentric Circles Example

本系列所有文章可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集33——Qt Quick Examples - Window and Screen 好像有一段时间没有更新这个系列了,一方面是很多的事掺杂着一起来了,稍微比原来忙了一些;但时间哪有挤不出来的呢,所以更重要的一个原因其

iOS小技能:【营业执照编号校验】18位社会信用代码验证 unified social credit identifier

文章目录 引言I、商户进件新增营业执照编号校验1.1 【需求背景】1.2 【需求描述】1.3 术语和定义1.4 统一代码的构成(unified identifier)1.5 代码及说明 II、iOS代码实现2.1 简单校验字母2.2 严格按照18位社会信用代码生成规则验证(GB/T 17710) see alsoiOS 银行卡号有效性校验Luhn算法 (银行卡号码校验算法) & 身份证校验:

一个全栈SpringBoot项目-Book Social Network

一个全栈SpringBoot项目-Book Social Network BSN是一个会员之间交换图书的社交网络平台。图书社交网络是一个全栈应用程序,使用户能够管理他们的图书收藏并与图书爱好者社区互动。它提供的功能包括用户注册、安全电子邮件验证、图书管理(包括创建、更新、共享和归档)、图书借阅(检查可用性)、图书归还功能以及图书归还批准。该应用程序使用 JWT 令牌确保安全性,并遵循 REST

Tagging: People-powered Metadata for the Social Web

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Tagging is fast becoming one of the primary ways people organize and manage digital information. Tagging

No Tech Hacking: A Guide to Social Engineering, Dumpster Diving, and Shoulder Surfing

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp As the clich reminds us, information is power. In this age of computer systems and technology, an incre

Social Media Marketing: An Hour a Day

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Develop an Integrated, Successful Social Media Strategy A Step-by-Step Guide Put the buzz about your b

ASP.NET 3.5 Social Networking

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp   Channel Data Warehouse Sql Language ACCESS FileMaker Data Mining Database Design Database General

Social to Sales,洞见生意进阶生机丨数说故事重磅发布2024全新战略

洞察,让生意发生。 4月12日,以“Social to Sales  洞察让生意发生”为主题的2024数说故事D3智能营销论坛于上海圆满举办,数说故事与来自清华大学、中欧国际工商学院、周大福、小红书、澎湃新闻、互联网大厂营销专家等12位重磅级嘉宾,融合产、研、媒各界实战经验,透过大数据分享了社交媒体新风向、出海掘金思路、消费新弄潮等趋势洞察,用“洞察”重构品牌与生意之间的