[贪心 二分] 2016 计蒜之道 复赛 B. 联想专卖店大促销
来源:互联网 发布:软件开发哪里学 编辑:程序博客网 时间:2024/04/27 23:54
注意相邻不能相同 意味着最大的不超过其余两个的和+1
可以发现 三个礼包的交集是1个a 1个b
剩余分别对应1个a 1个b 1个c
那么我们二分 是否x+y+z>=mid
然后验证
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}int A,B,C;int tem[5];inline bool check(int mid){ tem[1]=min(A-mid,mid); tem[2]=min(B-mid,mid); tem[3]=min(C,mid); sort(tem+1,tem+4); return tem[1]+tem[2]+min(tem[1]+tem[2]+1,tem[3])>=mid; }int main(){ int T; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(T); while (T--){ read(A); read(B); read(C); int L=0,R=B+1,MID; while (L+1<R) if (check(MID=(L+R)>>1))L=MID; elseR=MID; printf("%d\n",L); } return 0;}
0 0
- [贪心 二分] 2016 计蒜之道 复赛 B. 联想专卖店大促销
- 2016计蒜之道复赛 联想专卖店大促销 二分+贪心
- 2016计蒜之道复赛 B. 联想专卖店大促销(二分)
- 计蒜之道 2016 复赛 B. 联想专卖店大促销
- 计蒜客 联想专卖店大促销 二分
- 计蒜客-联想专卖店大促销 (二分答案)
- 计蒜客 联想专卖店大促销
- 2016 计蒜之道 复赛 A
- 计蒜客-2017 计蒜之道 复赛-B-Windows 画图
- 2016计蒜之道复赛 微信钱包付款
- 2016 计蒜之道 复赛 题解 部分
- 2017计蒜之道 复赛 BDF
- 2017 计蒜之道 复赛 题解
- 2017 计蒜之道 复赛 B. Windows 画图 坐标描点
- 2017 计蒜之道 复赛 B. Windows 画图(暴力)
- 2017计蒜之道复赛-Windows 画图
- 2017计蒜之道程序设计大赛复赛题解
- 2017 计蒜之道 复赛 <状压DP+最短路>
- SimpleAudioEngine
- JaxWsProxyFactoryBean 与 JaxWsDynamicClientFactory
- scrollToFixed.js——导航...滚动固定
- 单列模式,工厂模式,观察者模式
- 前端攻防篇-XSS攻击及防御
- [贪心 二分] 2016 计蒜之道 复赛 B. 联想专卖店大促销
- openwrt: Makefile 框架分析
- 那些我们解过的bug之listview滑动不流畅
- OpenStack之Neutron源码分析 Neutron-server初始化----从文件夹的命名也基本可以得出该目录代码的作用,几个重要的文件夹如下: agent: 主要是l3 agent及l
- Java 通过JDBC连接Mysql数据库的方法和实例
- BAT 计算指定天数之前的日期
- JeMeter访问https请求
- 内存理解
- 理解各种不同含义的new和delete