codeforces 1060 D
https://codeforces.com/contest/1060/problem/D
题意:你可以用1个及以上的圆桌,给n个人排座位,每个人左边需要有Li个空凳子,右边需要有Ri个空凳子,问你最少用多少个凳子
题解:一定要注意可以用多个圆桌,这样其实就是每个人的左边和右边无所谓,只需要求出左边或者右边的最大值即可,然后再加上本人的一个座位。
代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
double dpow(double a,LL b){double ans=1.0;while(b){if(b%)ans=ans*a;a=a*a;b/=;}return ans;}
int l[maxn];
int r[maxn];
int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
int n;
LL ans=;
cin>>n;
for(int i=;i<n;i++){
cin>>l[i]>>r[i];
}
sort(l,l+n);
sort(r,r+n);
for(int i=;i<n;i++){
ans+=(LL)max(l[i],r[i])+;
}
cout<<ans<<endl;
}
codeforces 1060 D的更多相关文章
- codeforces 1060 C
https://codeforces.com/contest/1060/problem/C 题意:给你一个长度为n的数列a和长度为m的数列b,定义c(i,j)=ai*bj,得到c矩阵,给定值x,求c矩 ...
- codeforces 1060 B
https://codeforces.com/contest/1060/problem/B 题意:给你一个数C ,你要找到两个数A.B,使得A+B=C并且A的每个位的数的和最大,求最大的和是多少 题解 ...
- codeforces 1060 A
https://codeforces.com/contest/1060/problem/A 题意:电话号码是以8开头的11位数,给你n 个数问最多可以有多少个电话号码 题解:min(8的个数,n/11 ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- Codeforces 1060 F. Shrinking Tree
题目链接 一道思维好题啊...感觉这种类型的题很检验基本功是否扎实(像我这样的就挂了). 题意:你有一棵\(n\)个点的树,每次随机选择一条边,将这条边的两个端点合并,并随机继承两个点标号中的一个,问 ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Codeforces Round #513 by Barcelona Bootcamp C. Maximum Subrectangle(双指针+思维)
https://codeforces.com/contest/1060/problem/C 题意 给两个数组,a数组有n个元素,b数组有m个元素,两个数组元素互相相乘形成n*m的矩阵,找一个子矩阵,元 ...
- Codeforces Round #513-ABCD
ABC现场做出,涨了八十几分吧.D有点思路不知道怎么实现,赛后看题解发现巨简单,想得太复杂了.蓝瘦. A----http://codeforces.com/contest/1060/problem/A ...
随机推荐
- echarts实用小技巧,控制字符串长度,限定整数等
限定横坐标文本字符长度 xAxis : [ axisLabel:{ formatter: function (value) { var maxlength=6; if (value.length> ...
- P2153 [SDOI2009]晨跑(最小费用最大流)
题目描述 Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街 ...
- Java:Random函数及其种子的作用
伪随机(preundorandom):通过算法产生的随机数都是伪随机!! 只有通过真实的随机事件产生的随机数才是真随机!!比如,通过机器的硬件噪声产生随机数.通过大气噪声产生随机数 Random生成的 ...
- 从C到C++ (1)
从C到C++ 一. bool类型 bool取值false和true,是0和1的区别: false可以代表0,但true有很多种,并非只有1. 二. const限定符 常量在定义后就不能修改,所以定义时 ...
- itop-4412开发板使用第一篇-信号量的学习使用
1. 本次基于itop-4412研究下Linux信号量的使用方法. 2. 创建信号量的函数,信号量的头文件在那个路径?编译应用程序的话,头文件有3个路径,内核源码头文件,交叉编译器头文件,ubuntu ...
- awk用法介绍
Awk 程序的结构如下: awk 'BEGIN{ print "start" } pattern { commands } END{ print "end" } ...
- js数字格式化千分位格式
带小数点的 var a = 8462948.2453; console.log(a.toLocaleString()) //8,462,948.245 不带小数点的 num.toString().re ...
- EFT4 生成实体类
创建T4模本拷贝以下代码 <#@ template language="C#" debug="false" hostspecific="true ...
- 在Kotlin编写RecyclerView适配器(KAD 16)
作者:Antonio Leiva 时间:Mar 14, 2017 原文链接:https://antonioleiva.com/recyclerview-adapter-kotlin/ 通过创建Recy ...
- python学习总结----内置函数及数据持久化
抽象基类(了解) - 说明: - 抽象基类就是为了统一接口而存在的 - 它不能进行实例化 - 继承自抽象类的子类必须实现抽象基类的抽象方法 - 示例: from abc import ABC, abs ...