【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个最优解即可,遍历求 ...
随机推荐
- 微信企业号 发送信息 shell
微信企业号发送信息shell #可作为shell函数模块调用,用于微信通知.jenkins发版微信通知等等 # 微信API官方文档 https://work.weixin.qq.com/api/doc ...
- 【BASIS系列】SAP 中查看account登陆次数及时间的情况
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 中查看account登 ...
- [Udemy] ES 7 and Elastic Stack - part 1
Section 1 基本概念: Index(indices) 相当于 关系型数据库的 table, document 相当于关系型数据库的 row, 还有一个type的概念(可以理解为table的s ...
- == 和 equals的区别
== 和 equals的区别 基本类型:== 比较的是两个变量的面值大小 对象对象: 比较的是内存地址 特例: String a = "abc" String b = &qu ...
- C语言第七周作业
每个单词的最后一个字母改成大写 函数fun的功能是:将p所指字符串中每个单词的最后一个字母改成大写.(这里的"单词"是指由空格隔开的字符串). 函数接口定义: void fun( ...
- “希希敬敬对”团队——敏捷冲刺Alpha过程总结
“希希敬敬对”团队在七天冲刺过程中每一个小组成员都尽力去完成自己的任务.在合作过程中,总算是有一些成果出现,代码功能能够实现. 对此次冲刺有如下优缺点: 优点: 团队人员合作较多,成员都能够积极响应参 ...
- python 二维数组转一维数组
三种方法 比如 a = [[1, 2], [3, 4], [5, 6]] 列表推导式 [i for j in a for i in j] 库函数 from itertools import chain ...
- Topcoder SRM656div1 250 ( 期望DP )
Problem Statement Charlie has N pancakes. He wants to serve some of them for breakfast. We will n ...
- C# DataTable与实体的相互转换
using System; using System.Collections.Generic; using System.Data; using System.Reflection; namespac ...
- 百度地图api 实例 自动提示 并计算两地的行驶距离
百度地图api 实例 自动提示 并计算两地的行驶距离 <!DOCTYPE html> <html> <head> <meta http-equiv=" ...