F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in their maximum bandwidths and prices.
By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P.
Input
The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case starts with a line containing a single integer n (1 ≤ n ≤ 100), the number of devices in the communication system, followed by n lines in the following format: the i-th line (1 ≤ i ≤ n) starts with mi (1 ≤ mi ≤ 100), the number of manufacturers for the i-th device, followed by mi pairs of positive integers in the same line, each indicating the bandwidth and the price of the device respectively, corresponding to a manufacturer.
Output
Your program should produce a single line for each test case containing a single number which is the maximum possible B/P for the test case. Round the numbers in the output to 3 digits after decimal point.
Sample Input
1 3
3 100 25 150 35 80 25
2 120 80 155 40
2 100 100 120 110
Sample Output
0.649
题目要求所选d的最小值除以总p最大;
一开始的想法是从第一个开始选然后慢慢选后面的,但是发现有bug,这种方法做不了;
这题因为n,t都比较小,所以可以用暴力,把所有的情况都选一边,就是从d最小开始选择,然后把所有情况的d/p算出来,选最大的就好了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define cl clear()
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
const double pi=acos(-1.0);
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
struct qq
{
int num;
int a[105];
int b[105];
}q[105];
int dd[10005],d[10005];
double ans[10005];
using namespace std;
int main()
{
int re;
cin>>re;
while(re--)
{
mm(ans,0);
int ww=1;
int w=0;
mm(d,0);
mm(dd,0);
int n;
cin>>n;
double b=0,p=0;
for(int i=0;i<n;i++)
{
mm(q[i].a ,0);mm(q[i].b,0);
int m;
cin>>m;
q[i].num =m;
for(int j=0;j<m;j++)
{
sf("%d%d",&q[i].a[j],&q[i].b[j]);
dd[w++]=q[i].a[j];
}
}
sort(dd,dd+w);
d[0]=dd[0];
for(int i=1;i<w;i++)
{
if(dd[i]!=d[ww-1])
d[ww++]=dd[i];
}
int k;
for( k=0;k<ww;k++)
{
int pp=0,temp=0;
for(int i=0;i<n;i++)
{
int p=mod;
for(int j=0;j<q[i].num ;j++)
{
if(q[i].a[j]>=d[k])
if(q[i].b[j]<p)
p=q[i].b[j];
}
if(p==mod)
temp=1;
pp+=p;
}
if(temp)
break;
ans[k]=(double)d[k]/pp;
}
double max=ans[0];
for(int i=1;i<k;i++)
if(max<ans[i])
max=ans[i];
pf("%.3lf\n",max);
}
return 0;
}
F - Communication System的更多相关文章
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- POJ1018 Communication System
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26738 Accepted: 9546 Description We ...
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
随机推荐
- 第十八章 dubbo-monitor计数监控
监控总体图: 红色:监控中心 - dubbo-simple-monitor 黄色:provider 蓝色:consumer 统计总体流程: MonitorFilter向DubboMonitor发送数 ...
- 在 Visual Studio 2010 中配置SharpPcap
最近需要在C#下写一个抓取ARP包的程序,网上找来找去,在C#下只能用SharpPcap来做了.SharpPcap是作者把winPcap用C#重新封装而来的,详细信息见如下的链接. SharpPcap ...
- 从入门到精通Puppet的实践之路
本文有感于<精通Puppet配置管理工具>在豆瓣上的某些差评而顺手写的书评. 半路出家 故事要从12年初说起. 某天,部门老大让我所在team的老大调研一下当下业界的配置管理工具.于 ...
- php调试用的几个小方法
1.PHP把一个对象转化成json字符串 $json_string = json_encode($object, JSON_FORCE_OBJECT); json_encode($object); / ...
- synchronized和lock比较
一.synchronized的实现方案 1.synchronized能够把任何一个非null对象当成锁,实现由两种方式: a.当synchronized作用于非静态方法时,锁住的是当前对象的事例,当s ...
- 第一部分:开发前的准备-第三章 Application 基本原理
第3章 应用程序基本原理 首先我们需要强调一下Android 应用程序是用java写的.Android SDK工具编译代码并把资源文件和数据打包成一个文件.这个名字的扩展名是.APK.要在androi ...
- [svc]linux下网桥-docker网桥
网桥和交换机 2口交换机=网桥 交换机: 工作在数据链路层,根据源mac学习(控制层),目的mac转发(数据层). linux的网卡 vmware workstation中的桥接 参考: http:/ ...
- Docker基于已有的镜像制新的镜像-Docker for Web Developers(3)
1.根据运行的容器制作镜像 #查看所有的容器 docker ps #暂停当前容器 docker pause COTNAINER-ID #将容器运行当前状态提交 docker commit COTNAI ...
- golang:吐槽multipart的设计
最近在做邮件解析的工作,因此接触到multipart库,用了之后才发现golang的multipart有一点设计很诡异. 红线标出来的话意思是:当Content-Transfer-Encoding的值 ...
- Kaggle 自行车租赁预测比赛项目实现
作者:大树 更新时间:01.20 email:59888745@qq.com 数据处理,机器学习 回主目录:2017 年学习记录和总结 .caret, .dropup > .btn > . ...