题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6667

题意:

有 n个班级,每个班级有a个人、b个奶茶,每个班的人不能喝自己的奶茶,只能喝别人班的奶茶,问你最多有多少人喝到奶茶。

思路:

明显一道贪心题:

n=3

3   4  min=3

4   2  min=2

4   2  min=2

首先根据min值从大到小排序(先消除大的更优),两个min值是肯定可以消掉一个的,ans+=min*2,而且消到最后最多只有一个a、b都不为0。

然后就是要先判一下最后一个能不能消去。

最后就是除了最后一个其他a、b的总和就可以加起来了,取个min,ans+=min 就可以了。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; struct node
{
long long a,b;
long long mi;
friend bool operator<(node a,node b)
{
return a.mi<b.mi;
}
}P[N]; int main()
{
// freopen("D:\\QQ DATA\\1659826587\\FileRecv\\hdu-multi2019-8 5个账号 - 复件\\data\\k.in","r",stdin);
int T;
sc("%d",&T);
while(T--)
{
int n;
sc("%d",&n);
fo(i,,n)
{
sc("%lld%lld",&P[i].a,&P[i].b);
P[i].mi=min(P[i].a,P[i].b);
}
sort(P+,P++n);
long long ans=;
int pos=n;
for(int i=n-;i>=;--i)
{
long long temp=min(P[i].mi,P[pos].mi);
ans+=temp*;
P[i].mi-=temp;P[i].a-=temp;P[i].b-=temp;
P[pos].mi-=temp;P[pos].a-=temp;P[pos].b-=temp;
if(P[i].mi)
pos=i;
}
sort(P+,P++n);
struct node temp=P[n];
long long x=,y=;
for(int i=;i<=n-;++i)
x+=P[i].a,y+=P[i].b;
if(x&&temp.b)
{
long long tt=min(x,temp.b);
ans+=tt;
x-=tt;temp.b-=tt;
}
if(y&&temp.a)
{
long long tt=min(y,temp.a);
ans+=tt;
y-=tt;temp.a-=tt;
}
long long xx=min(x,y);
ans+=xx;
x-=xx;y-=xx;
pr("%lld\n",ans);
}
// fclose(stdin);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

喝奶茶最大值(不能喝自己班级的)2019 Multi-University Training Contest 8--hdu杭电第8场(Roundgod and Milk Tea)的更多相关文章

  1. HDU 6319.Problem A. Ascending Rating-经典滑窗问题求最大值以及COUNT-单调队列 (2018 Multi-University Training Contest 3 1001)

    2018 Multi-University Training Contest 3 6319.Problem A. Ascending Rating 题意就是给你长度为k的数列,如果数列长度k<n ...

  2. 2019 Multi-University Training Contest 8

    2019 Multi-University Training Contest 8 C. Acesrc and Good Numbers 题意 \(f(d,n)\) 表示 1 到 n 中,d 出现的次数 ...

  3. [转]cookie、session、sessionid 与jsessionid

    cookie.session.sessionid 与jsessionid,要想明白他们之间的关系,下面来看个有趣的场景来帮你理解. 我们都知道银行,银行的收柜台每天要接待客户存款/取款业务,可以有几种 ...

  4. cookie、session、sessionid ,jsessionid 的区别

    本文是转载虫师博客的文章http://www.cnblogs.com/fnng/archive/2012/08/14/2637279.html cookie.session.sessionid 与js ...

  5. HDU1160 FatMouse's Speed —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...

  6. hdu1078 FatMouse and Cheese(记忆化搜索)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...

  7. 2019DX#8

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Acesrc and Cube Hypernet 7.32%(3/41)   1002 A ...

  8. Bzoj3441 乌鸦喝水

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 258  Solved: 97 Description [题目背景]     一只乌鸦在自娱自乐,它在面 ...

  9. Appium+python自动化(二十八)- 滑呀滑,滑到奈何桥喝碗孟婆汤 - 高级滑动(超详解)

    简介 奈何桥上叹奈何,三生石前憾三生,彼岸花下非彼岸,奈何三生彼岸人. 相传过了鬼门关便上一条路叫黄泉路,路上盛开着只见花,不见叶的彼岸花.花叶生生两不见,相念相惜永相失,路尽头有一条河叫忘川河,河上 ...

随机推荐

  1. Vue_(组件通讯)非父子关系组件通信

    Vue单项数据流 传送门 Vue中不同的组件,即使不存在父子关系也可以相互通信,我们称为非父子关系通信 我们需要借助一个空Vue实例,在不同的组件中,使用相同的Vue实例来发送/监听事件,达到数据通信 ...

  2. koa 基础(五)动态路由的传值

    1.动态路由的传值 app.js /** * 动态路由的传值 */ // 引入模块 const Koa = require('koa'); const router = require('koa-ro ...

  3. 浅析java中的四种线程池

      1.使用线程池的好处 2.JUC中几种常用的线程池 java.util.concurrent包下的Executors工厂类,提供了一系列的线程池的创建方法,其构造方法如下: public Thre ...

  4. WOE1-Feature Selection 相关:一个计算WOE和Information Value的python工具

    python信用评分卡建模(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_ca ...

  5. mysql timestamp为0值时,python读取后的对象为None

    MySQL数据表中,如果timestamp类型的字段,值为0, python从数据库读取数据后,得到对象是什么类型,是否为None呢? 下面来测试下. 创建数据表 首先创建数据表,其中字段pr_rul ...

  6. 算法 - 插入排序交换次数 - Binary Indexed Tree

    场景:快速得到一段数组元素的和 题目:Insertion Sort Advanced Analysis | HackerRank 算法:binary-indexed-tree :: HackerRan ...

  7. Dialog 对话框

    在保留当前页面状态的情况下,告知用户并承载相关操作. 基本用法 Dialog 弹出一个对话框,适合需要定制性更大的场景. 需要设置visible属性,它接收Boolean,当为true时显示 Dial ...

  8. Jenkins初次启动卡住问题解决

    Jenkins在初次使用时, 一直卡住, 无论如何也不出现输入用户名密码. 忘记截图, 下次出现更新图示. 解决方案: 需要你进入Jenkins的工作目录,打开 hudson.model.Update ...

  9. springboot项目启动无法访问到controller原因之一:引导类位置有问题

    新建的springboot项目启动后,无法访问到controller 页面是404错误 查看项目结构,发现是新建工程的启动类位置有问题,controller类应该位于引导类的同级包或者子级包中.需要将 ...

  10. java7:(Files.walkFileTree())

    1.Files.walkFileTree(): 顺序:顺序访问,碰到目录会一直递归下去 package com.test; import java.io.File; import java.io.IO ...