【HDOJ6667】Roundgod and Milk Tea(模拟)
题意:有n个班级,每个班级有a[i]个人,b[i]杯奶茶
每个人至多喝一杯奶茶,且不能喝自己班的
问能喝到奶茶的最多总人数
n<=1e6,a[i],b[i]<=1e9
思路:
做法一:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
//typedef pair<ll,ll>P;
#define N 1000010
#define M 200010
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1 const int MOD=1e9+,inv2=(MOD+)/;
double eps=1e-;
int INF=1e9;
int inf=0x7fffffff;
int dx[]={-,,,};
int dy[]={,,-,}; ll a[N],b[N]; ll read()
{
ll v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void solve()
{
int n;
scanf("%d",&n);
ll s=,ans=;
rep(i,,n)
{
a[i]=read(),b[i]=read();
s+=b[i];
}
rep(i,,n) ans+=min(a[i],s-b[i]);
ans=min(ans,s);
printf("%I64d\n",ans);
} int main()
{
int cas=read();
while(cas--) solve();
return ;
}
做法二:题解做法
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
#define N 1100000
#define M 4100000
#define fi first
#define se second
#define MP make_pair
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1 const ll MOD=1e9+,inv2=(MOD+)/;
double eps=1e-;
int INF=1e9; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} int a[N],b[N]; int main()
{
//freopen("1.in","r",stdin);
int cas;
scanf("%d",&cas);
while(cas--)
{
int n=read();
ll sa=,sb=;
rep(i,,n)
{
a[i]=read(); b[i]=read();
sa+=a[i];
sb+=b[i];
}
if(sa>sb)
{
int flag=,s=;
rep(i,,n)
if(a[i]+b[i]-(sa-sb)>sb)
{
flag=;
s=a[i]+b[i]-(sa-sb)-sb;
}
if(flag) printf("%I64d\n",sb-s);
else printf("%I64d\n",sb);
}
else
{
int flag=,s=;
rep(i,,n)
if(a[i]+b[i]-(sb-sa)>sa)
{
flag=;
s=a[i]+b[i]-(sb-sa)-sa;
}
if(flag) printf("%I64d\n",sa-s);
else printf("%I64d\n",sa);
}
} return ;
}
【HDOJ6667】Roundgod and Milk Tea(模拟)的更多相关文章
- HDU 6667 Roundgod and Milk Tea (思维)
2019 杭电多校 8 1011 题目链接:HDU 6667 比赛链接:2019 Multi-University Training Contest 8 Problem Description Rou ...
- 喝奶茶最大值(不能喝自己班级的)2019 Multi-University Training Contest 8--hdu杭电第8场(Roundgod and Milk Tea)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6667 题意: 有 n个班级,每个班级有a个人.b个奶茶,每个班的人不能喝自己的奶茶,只能喝别人班的奶茶 ...
- HDU 6667 Roundgod and Milk Tea
hdu题面 Time limit 6000 ms Memory limit 131072 kB OS Windows Source 2019 Multi-University Training Con ...
- 【HDU6667】Roundgod and Milk Tea【贪心】
题目大意:给你ai,bi,限制ai不能流向bi,求最大流 题解:贪心,对于第i个班级,考虑前i-1个班级匹配完剩余多少a,b,将这些ab对第i个班级进行贪心匹配 匹配完若第i个班级还有剩余的ab,考虑 ...
- [2019杭电多校第八场][hdu6667]Roundgod and Milk Tea
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6667 题目大意是说n个班级,每个班级有ai人和bi杯茶,每个人只能喝其他班的茶并且只能喝一杯.问最多有 ...
- hdu多校第八场 1011 (hdu6667) Roundgod and Milk Tea 二分图匹配
题意: 有若干个班,每个班有些人要喝奶茶,也提供一些奶茶,一人喝一杯,但是自己班的人不能喝自己班的奶茶,求最多能有多少人喝上奶茶. 题解: 典型的二分图匹配问题,学生在左,奶茶在右,学生和非自己班的奶 ...
- HDU 1070 Milk (模拟)
题目链接 Problem Description Ignatius drinks milk everyday, now he is in the supermarket and he wants to ...
- HDU 5881 Tea (模拟)
题意:有一壶水, 体积在 LLL 和 RRR 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水 ...
- Google Kickstart Round E 2018 B. Milk Tea
太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误 大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求 ...
随机推荐
- XML读写工具类
摘要:①读取XML文件,生成pojo对象:②将对象信息保存到xml中. 步骤: ①新建一个普通的java类BasePage: package com.test.selenium.pages; impo ...
- vue组件父子间通信之综合练习--假的聊天室
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- 关于微信授权和unionid 的获取思路。
1.首先根据appid 获取到预授权码的code string Appid = "******";//appid.由于网页授权与js-jdk使用不同微信,所以暂时独立于此处. st ...
- js:获取单选组radio中的被选择的数据
现在有一name为sex的单选组,代表的是选择性别,要求获取radio中被选择的选项值 <div class="sexDiv"> 用户性别: <input cla ...
- [19/05/26-星期日] JavaScript_ 基本语法_运算符
一.概念 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- selenium 定位方式
在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下 ...
- MIT 6.824学习笔记4 Lab1
现在我们准备做第一个作业Lab1啦 wjk大神也在做6.824,可以参考大神的笔记https://github.com/zzzyyyxxxmmm/MIT6824_Distribute_System P ...
- InvalidMappingException提示Could not parse mapping document错误的解决方法
转自:http://www.itzhai.com/invalidmappingexception-could-not-parse-mapping-document-prompt-the-wrong-s ...
- Hadoop MapReduce实现人员二度关系运算
1.一度人脉:双方直接是好友 2.二度人脉:双方有一个以上共同的好友,这时朋友网可以计算出你们有几个共同的好友并且呈现数字给你.你们的关系是: 你->朋友->陌生人 3.三度人脉:即你朋友 ...
- 使用Python和AWK两种方式实现文本处理的长拼接案例
最近由于业务系统新需求的需要,我们平台需要将供应商G提供一类数据转换格式后提供给客户K.比较头疼是供应商G提供的数据都是在Windows下使用Excel存储的,而客户K先前与我们相关对接人员商定的数据 ...