zoukankan      html  css  js  c++  java
  • F

    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
    ",max);
    	}
    	return 0;
    }
    
  • 相关阅读:
    c#——树的深度,广度优先遍历与迭代器(IEnumerable<T>)的结合使用
    弱网下移动端网络连接处理策略
    弱网络环境下最优调度和优化传输层协议方案
    Wpf ToolTip 绑订
    minio配置
    使用本机映像优化 NET 桌面应用
    Linux内核内存管理:系统内存布局-内核空间和用户空间
    mysql 的 limit 与sql server 的 top n
    win 10 遇到某文件一直在占用导致无法关闭,或者去任务管理器找不到服务怎么办?具体解决
    sql server
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9350963.html
Copyright © 2011-2022 走看看