/*如果要一个物体的多种属性,最好用结构体,不要用二维数组或者多维数组。用多维数组进行关键字排序很不稳定 */
/*给每个设备的所有价格排序,每个设备选取恰好比已知带宽大的价格(这个时候的比例最大) 循环每个设备就得到所有价格综合 然后得到该带宽下的B/P
比较所有带宽的B/P 选取最大的就是所求的*/
#include <stdlib.h>
#include <stdio.h>
#define true 1
#define false 0
typedef struct
{ int b, p;
}SYS;
SYS sys[][];
int cmp(const void * a, const void * b)
{
SYS * c = (SYS *) a;
SYS * d = (SYS *) b;
return c -> p - d -> p;
} int main()
{
int n,i,j,sum,k,could,t;
int m[], bc;
int b[];/*记录每种带宽*/
double max,temp;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
bc = ;
for( i = ; i < n; i++)
{
scanf("%d",&m[i]);
for( j = ; j < m[i]; j++)
{
scanf("%d%d",&sys[i][j].b,&sys[i][j].p) ;
b[bc++] = sys[i][j].b;/*记录所有带宽的值,然后排序 */
}
qsort(sys[i], m[i], sizeof(SYS), cmp);
}
max = ;
for( k = ; k < bc; k++)/*循环每个带宽 */
{
sum = ;
could = true;
for(i = ; i < n; i++)/*每个设备 */
{
for(j = ; j < m[i]; j++)/*每个具体情况 */
if(sys[i][j].b >= b[k])/*从小到大,贪心 如果刚好比他大 */
{
sum += sys[i][j].p;/*就记录这个设备的价格,然后跳到下一个设备 */
break;
}
if(j == m[i])/*如果是循环到最后就证明是这个带宽是最大的就不用处理 */
{
could = false;
break;
}
}
if(could)/*如果这个带宽是可行的 */
{
temp = 1.0*b[k]/ sum;
max = max > temp ? max : temp;
}
}
printf("%.3lf\n",max); }
return ;
}
/*
1
3
2 120 80 155 40
3 100 25 150 35 80 25
2 100 100 120 110
*/

zoj 1409 Communication System的更多相关文章

  1. ZOJ 1409 communication system 双变量型的DP

    这个题目一开始不知道如何下手,感觉很像背包,里面有两个变量,一个带宽B,一个价格P,有n个设备,每个设备有k个可选的器材(只需选一个),每个器材都有自己的B和P, n个设备选n个器材,最终,FB=所有 ...

  2. Communication System(dp)

    Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...

  3. poj 1018 Communication System

    点击打开链接 Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21007   Acc ...

  4. poj 1018 Communication System 枚举 VS 贪心

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted:  ...

  5. POJ 1018 Communication System(贪心)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  6. F - Communication System

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  7. POJ 1018 Communication System (动态规划)

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  8. POJ 1018 Communication System(树形DP)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  9. poj 1018 Communication System (枚举)

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22380   Accepted:  ...

随机推荐

  1. SQL Server 一些重要视图2

    1. sys.dm_tran_session_transactions 为每一个没有关闭的事务返回一行.session_id 可以与sys.dm_exec_connections.session_id ...

  2. Red Hat Enterprise Linux Release Dates

    Red Hat Enterprise Linux Release Dates UpdatedMay 10 2016 at 10:57 PM - English The tables below lis ...

  3. rsyslog 传输mysql 日志

    在另外一种环境中,让我们假定你已经在机器上安装了一个名为"foobar"的应用程序,它会在/var/log下生成foobar.log日志文件.现在,你想要将它的日志定向到rsysl ...

  4. vagrant打造自己的开发环境

    vagrant打造自己的开发环境 缘由: 在网上看到斌哥,爽神都写了关于vagrant的博客,都在说很强大,所以很好奇这玩意怎么个强大,然后也就自己来一发玩玩看看. 真实缘由: 说实话是电脑配置太低, ...

  5. C#动态编译、执行代码

    在开始之前,先熟悉几个类及部分属性.方法:CSharpCodeProvider.ICodeCompiler.CompilerParameters.CompilerResults.Assembly. 一 ...

  6. kvm中运行kvm

    如何在 KVM 虚拟机上运行 KVM 上次讨论了如何在 VMware ESXi 虚拟机上运行 KVM 问题,前不久有读者想 “在 kvm 上面创建个虚拟机安装 rackspace 的 openstac ...

  7. NSFileHandle编写json数据格式

    代码如下: + (void)writeToFile:(NSDictionary *)params filePath:(NSString *)path { NSData *jsonData = [sel ...

  8. [Ext JS 4] Grid 实战之分页功能

    前言 分页功能的实现有两种途径: 一种是服务端分页方式, 也就是web客户端传递页码参数给服务端,服务端根据页面参数返回指定条数的数据.也就是要多少取多少.这种方式比较适合Grid  的数据量很大,需 ...

  9. JS isArray记录

    var isArray=Function.isArray||function(0){ return typeof o === "object" && Object. ...

  10. HDU 3466 Proud Merchants(01背包)

    这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...