湖大训练赛第十场 Electricity
来源:互联网 发布:java小程序实例 编辑:程序博客网 时间:2024/05/01 08:37
Input
The first line of input file contains two integer numbers n and m — the number of power strips of the first and the second type (0 ≤ n,m ≤ 100000).
The second line contains n integer numbers ai— the number of sockets on the power strips of the first type (1 ≤ ai≤ 1000).
The second line contains m integer numbers bi— the number of sockets on the power strips of the second type (1 ≤ bi≤ 1000).
Output
Output the maximum number of computers that can be connected to the power network.
Sample Input
3 23 2 12 32 32 22 3 1Sample Output
55
题意:实验室只有一个接口,还是A类型的。学生每台电脑的接头都是A类型的。肯定只能接一个用。唉。
莫慌。我们还有两座类型的插座分别有N,M个。A类型插头是A,插板上有许多个B类型接口。B类型的插头是B,插板上有许多A类型接口。输入N,M,接下来N个数是每个A类型插板上有多少个B型接口。接下来M个数是每个B类型插板上有多少个A型接口。问实验室最多能接多少台电脑。ORz。。。跟我们实验室串联好像啊。。。
题解:按平时习惯我们当然是喜欢接口越多的插板。所以我们分别把两种类型插座按从大到小排序。如果没有A类型插座当然只有1台电脑可以接电了。否则先接最多接口的A类型,然后插满!!!B,如果还有B没插到,继续插个A,继续插B...直到A没有了或者B没有了。OK.Accpet.看着就有点小激动呢。
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>#define LL __int64#define EPS 1e-8using namespace std;int cmp(int x,int y){return x>y;}int cmp1(int x,int y){return x>y;}int a[100010],b[100010];int main(){int n,m,i;while (~scanf("%d%d",&n,&m)){for (i=0;i<n;i++)scanf("%d",&a[i]);for (i=0;i<m;i++)scanf("%d",&b[i]);if (n==0) {puts("1");continue;}sort(a,a+n,cmp);sort(b,b+m,cmp1);int a1=0,b1=0;int ans=1;while (1){ans--;for (i=0;i<a[a1];i++){ans+=b[b1];b1++;if (b1==m) break;}a1++;if (a1==n || b1==m) break;}cout<<ans<<endl;}return 0;}
- 湖大训练赛第十场 Electricity
- 湖大训练赛第十场 Battleship
- 湖大训练赛第十场 Aztec Pyramid
- 湖大训练赛第十场 Deepest Station
- 湖大训练赛第十场 Final Standings
- 日常训练-2016Multi-university第十场
- 【大渣】#11月训练赛第1场
- 【大渣】#11月训练赛第2场
- Electricity
- 第一场个人训练赛
- 第二场个人训练赛
- 第三场个人训练赛
- 第四场个人训练赛
- 第三场个人训练赛
- 第九场个人训练赛
- 训练赛第一场总结
- 训练赛第二场总结
- 第三场训练赛总结
- 湖大训练赛第十场 Final Standings
- Codeforces Round #261 (Div. 2) A. Pashmak and Garden【水】
- leetcode Balanced Binary Tree
- Bit Map
- 利用html5的本地存储功能实现登录用户信息保存
- 湖大训练赛第十场 Electricity
- OpenStack 之 nova-api 的代码结构图
- Http协议和HttpS协议的简介
- Add Two Numbers
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- poj 2431 Expedition (贪心+优先队列)
- 的通用天赋方法见附件
- 在MFC中类内部建立线程处理函数以便调用类的成员函数和变量
- linux二进制通用包安装mysql 5.6.20