cf1060D. Social Circles(贪心)
题意
Sol
我是这样考虑的:从大到小考虑每个\(l, r\),最大的\(l\)应该和最大的\(r\)匹配(不然就亏了),其次次大的\(r\)应该和次大的\(l\)匹配
然后就过了。。
/*
*/
#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long
#define LL long long
#define rg register
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
#define chmin(x, y) (x = x < y ? x : y)
using namespace std;
const int MAXN = 2001, INF = 1e18 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, l[MAXN], r[MAXN], ans;
priority_queue<int> p, q;
main() {
N = read();
for(int i = 1; i <= N; i++) p.push(read()), q.push(read());
for(int i = 1; i <= N; i++) {
int x = p.top(), y = q.top(); p.pop(); q.pop();
ans += max(x, y);
}
cout << ans + N;
return 0;
}
cf1060D. Social Circles(贪心)的更多相关文章
- CF1060D Social Circles
思路: 贪心.既然每个人的左边是其他人的右边,每个人的右边是其他人的左边,那么使重叠的部分最多即可. 实现: #include <bits/stdc++.h> using namespac ...
- 1060D Social Circles(贪心)
题意:有n个客人,第i个客人希望左边至少Li个空椅子,右边至少Ri个空椅子,每个客人都属于一个圈,问你最少需要准备的椅子数量 贪心做,每个人都可以去和另一个人牵手,组成一个新的人,那么我们让大的和大的 ...
- CF1060D Social Circle 排序
题目传送门:http://codeforces.com/problemset/problem/1060/D 题意:有$N$个人,你要让他们坐成若干个圆环.他们每个人需要坐一把椅子,左手边至少要有$l_ ...
- codeforces_D. Social Circles
http://codeforces.com/contest/1060/problem/D 题意: n个客人,每个客人希望自己左边空li个座位,右边空ri个座位,可以形成任意个圆,问最少多少个座位. 思 ...
- Codeforces Round #513 by Barcelona Bootcamp
A. Phone Numbers 签. #include <bits/stdc++.h> using namespace std; #define N 110 char s[N]; ], ...
- 【前行&赛时总结】◇第4站&赛时9◇ CF Round 513 Div1+Div2
◇第4站&赛时9◇ CF Round 513 Div1+Div2 第一次在CF里涨Rating QWQ 深感不易……作blog以记之 ( ̄▽ ̄)" +Codeforces 的门为你打 ...
- Codeforces Round #513 (rated, Div. 1 + Div. 2)
前记 眼看他起高楼:眼看他宴宾客:眼看他楼坍了. 比赛历程 开考前一分钟还在慌里慌张地订正上午考试题目. “诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省 ...
- Codeforces Round #513解题报告(A~E)By cellur925
我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. #include&l ...
- 10 signs you’re dating the wrong person
10 signs you’re dating the wrong person10个迹象表明TA不是你的真心人 Do you have any exes who were so awful ...
随机推荐
- windows10 pip install MySQL-python mysqlclient
https://dev.mysql.com/downloads/connector/python/ 到上述地址下载对应系统的驱动程序安装即可. 安装mysqlclient方法如下: https://w ...
- Xcode 工程文件“.xcodeproj”文件夹解析
项目.xcodeproj 文件夹底下一般有4个文件: project.pbxproj 文件 xcuserdata 文件夹 xcshareddata 文件夹 project.xcworkspace 文件 ...
- python学习,day4:生成器
1.生成器:只有在调用是才会生成相应的数据.(比较省内存,它只保留当时生成的.而列表会保存整个列表) a = [i*2 for i in range(10)] #列表生成式 print(a) 这样会把 ...
- php 判断两个时间段是否有交集
一开始,没啥思路,全靠百度,记录一下哈 public function demo(){ //例子 $astart = strtotime("1995-06-16 12:00:00" ...
- 物联网学习之路——物联网通信技术:NBIoT
NBIoT是什么 NB-IoT,Narrow Band Internet of Things,窄带物联网,是一种专为万物互联打造的蜂窝网络连接技术.顾名思义,NB-IoT所占用的带宽很窄,只需约180 ...
- spring定时任务详解
(一)在spring.xml里加入task的命名空间 xmlns:task="http://www.springframework.org/schema/task" http:// ...
- php中各种http报错的状态码分析
HTTP会经常遇见错误,本文主要和大家分享php中各种http报错的状态码,希望能帮助到大家. HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无 ...
- HBase 使用外部的 zookeeper
HBase 启动时,默认会根据hbase-site.xml文件中的如下设置端口上启动一个zookeeper服务: <property> <name>hbase.zookeepe ...
- django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
https://www.e-learn.cn/content/wangluowenzhang/165461 问题: I created a new project in django and past ...
- Sublime Text 3插件收集
0.Package Control 这个是必须装的,就不多解释了 1.ConvertToUTF8 支持 GBK, BIG5, EUC-KR, EUC-JP, Shift_JIS 等编码的插件. 2.B ...