• 题意:有三个背包,每个背包里都用一些数字,你可以选择某一个背包的数字\(a\),从另外一个背包拿出\(b\)(拿出之后就没有了),然后将\(a\)替换为\(a-b\),你可以进行任意次这样的操作,使得最后只剩下一个数,问这个数最大能是多少.
  • 题解:我的思路是,先任意选两个背包,假设\(x\)和\(y\),我们假设选\(x\)中的最大值,\(y\)中的最小值,很明显,我们让\(y\)的最小值减去没有选的背包的所有数和除了\(x\)最大值的所有数一定是最优的,但是\(y\)中除了最小值的其他数不好处理,这里我们可以先让\(x\)中的最小值减去\(y\)除了最小值的其他数,因为小的减大的可以使贡献损失最小,这里要注意,假如减完后,\(x\)的最小值是正数,那么我们让\(y\)的最小值直接减去\(x\)操作后最小值即可,如果是负数的话,我们就要将这个数减到没有用过的那个背包里面,然后再用\(y\)的最小值减去没有选的背包的所有数,其实这里我们只要加一个绝对值就可以了,最后的最大值就是用\(x\)中的最大值减去操作后的\(y\)中的最小值.因为只有三个背包,所以一共有\(6\)种情况,我们一一列举维护一个最大值就好了.
  • 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
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;} int n1,n2,n3;
ll s1,s2,s3; int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n1>>n2>>n3;
vector<ll> a(n1),b(n2),c(n3); for(auto &w:a) cin>>w,s1+=w;
for(auto &w:b) cin>>w,s2+=w;
for(auto &w:c) cin>>w,s3+=w;
n1--,n2--,n3--; sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(c.begin(),c.end()); ll ans=0; //max_1,min_2
ll sum1=s1-a[n1]-a[0];
ll sum2=s2-b[0];
ll sum3=s3;
ans=max(ans,a[n1]-(b[0]-sum3-sum1-abs(a[0]-sum2))); //max_1,min_3
sum1=s1-a[n1]-a[0];
sum2=s2;
sum3=s3-c[0];
ans=max(ans,a[n1]-(c[0]-sum2-sum1-abs(a[0]-sum3))); //max_2,min_1
sum1=s1-a[0];
sum2=s2-b[n2]-b[0];
sum3=s3;
ans=max(ans,b[n2]-(a[0]-sum3-sum2-abs(b[0]-sum1))); //max_2,min_3
sum1=s1;
sum2=s2-b[n2]-b[0];
sum3=s3-c[0];
ans=max(ans,b[n2]-(c[0]-sum1-sum2-abs(b[0]-sum3))); //max_3,min_1
sum1=s1-a[0];
sum2=s2;
sum3=s3-c[n3]-c[0];
ans=max(ans,c[n3]-(a[0]-sum2-sum3-abs(c[0]-sum1))); //max_3,min_2
sum1=s1;
sum2=s2-b[0];
sum3=s3-c[n3]-c[0];
ans=max(ans,c[n3]-(b[0]-sum1-sum3-abs(c[0]-sum2))); cout<<ans<<'\n'; return 0;
}

Codeforces Round #695 (Div. 2) C. Three Bags (贪心,思维)的更多相关文章

  1. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  2. Codeforces Round #695 (Div. 2)

    比赛地址 A (水题) 题目链接 题目: 给出\(n\)个面板,每个面板初始时间相同,每过1s面板上数字会加1(数字在\(0\sim9\)循环播放),任意时刻选择一个面板\(x\)使他的时间停止,其他 ...

  3. Codeforces Round #180 (Div. 2) D. Fish Weight 贪心

    D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that th ...

  4. Codeforces Round #180 (Div. 2) A. Snow Footprints 贪心

    A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a stra ...

  5. Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心

    C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...

  6. Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心

    A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Des ...

  7. Codeforces Round #548 (Div. 2) F splay(新坑) + 思维

    https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\), ...

  8. Codeforces Round #258 (Div. 2) . Sort the Array 贪心

    B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...

  9. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造

    题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...

随机推荐

  1. 获取json格式的数据变成了undefined!?

    今天在做一个简单的登陆功能时,当一切准备就绪,点击登陆时,什么都没发生..然后开始debug,打断点调试,然后发现了这个.向页面传递数据flag是true代表该用户的账号密码验证码等信息正确可以登录, ...

  2. 虚拟机Linux安装Oracle容器并实现局域网其他主机访问查询

    该文涉及Docker下Oracle容器的安装,主机端口的设置实现局域网内终端均能连接上Oracle数据库,图解如下: 一.关于Docker安装oracle容器可以参考下面博文: https://blo ...

  3. 【Problems】MySQL5.7 datetime 默认值设为‘0000-00-00 00:00:00'值出错

    记录 MySQL5.7 datetime 默认值设为'0000-00-00 00:00:00'值出错 我的MySQL版本 mysql --version 5.7.28 C:\Users\x1c> ...

  4. 【Redis】Redis基础 - Redis安装启动测试

    Redis基本 - 安装 文章目录 Redis基本 - 安装 Linux下安装Redis Docker 方式 Github 源码编译方式 直接安装方式 Windows下Redis安装 记录 - Red ...

  5. 企业项目迁移go-zero全攻略(一)

    作者:Mikael 最近发现 golang 社区里出了一个新兴的微服务框架.看了一下官方提供的工具真的很好用,只需要定义好 .api 文件模版代码都可以一键生成,只需要关心业务:同时 core 中的工 ...

  6. consul是什么?

    consul概念: consul是用来做注册中心的 他和eureka是一样的 注册中心一般都是集群的形式存在保证高可用 consul像是一个nosql 存储着键值对 可以做存储consul是c/s架构 ...

  7. 微信登录4-开发回调URL

    一.准备 1.引入pom依赖 在要使用HttpClient的项目中加入依赖 <!--httpclient--> <dependency> <groupId>org. ...

  8. Linux Centos7之由Python2升级到Python3教程

    1.先查看当前系统Python版本,默认都是Python2.7,命令如下: [root@localhost gau]# python -V Python 2.7.5 2.安装Python3,安装方法很 ...

  9. js千分位分隔,数字货币化方法学习记录

    js千分位分隔,数字货币化-4种方法(含正则) 方法1-整数货币化 // 整数货币化 function intCurrency(num) { var reg = new RegExp("^[ ...

  10. jQuery 文本段落展开和折叠效果

    jQuery 文本段落展开和折叠效果 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" c ...