zoj 1409 Communication System
/*如果要一个物体的多种属性,最好用结构体,不要用二维数组或者多维数组。用多维数组进行关键字排序很不稳定 */
/*给每个设备的所有价格排序,每个设备选取恰好比已知带宽大的价格(这个时候的比例最大) 循环每个设备就得到所有价格综合 然后得到该带宽下的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的更多相关文章
- ZOJ 1409 communication system 双变量型的DP
这个题目一开始不知道如何下手,感觉很像背包,里面有两个变量,一个带宽B,一个价格P,有n个设备,每个设备有k个可选的器材(只需选一个),每个器材都有自己的B和P, n个设备选n个器材,最终,FB=所有 ...
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- 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 ...
- F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The 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: ...
随机推荐
- sim卡中电话本(ADN)的简要格式
ADN的格式 ADN存放于sim卡下面3f00/7f10/6f3a,记录文件格式,其最小记录格式为14,最长为255(?),记录个数最大为255(?) 其后数14个字节是必有的,其前12个字节是电话号 ...
- 微软 Office 2010 SP2 正式版下载大全(含简中)
7月24日消息,微软正式为 Office 2010 和 SharePoint 2010 系列产品发布 SP 2服务包,带来重要更新和修复.除了提供产品补丁,SP2服务包还将提升产品的稳定性.性能以及安 ...
- 关于ajax中async参数的感悟
async,这个参数默认为true. 就是异步去处理信息. 当把它设置为false的时候,就是同步去处理数据了. var current_lead_id = '<?php echo $curre ...
- 分析Ext2文件系统结构。
1. 目的 分析Ext2文件系统结构. 使用 debugfs 应该跟容易分析 Ext2文件系统结构 了解ext2的hole的 2. 准备工作 预习文件系统基本知识: http://www.doc88. ...
- 轻奢当道业绩逆势增长 Kate Spade联手韩国衣恋开拓中国市场_商场报道_中国时尚品牌网
轻奢当道业绩逆势增长 Kate Spade联手韩国衣恋开拓中国市场_商场报道_中国时尚品牌网 轻奢当道业绩逆势增长 Kate Spade联手韩国衣恋开拓中国市场
- UI_拖动View
方法一 在touchesMoved中 // 获取到触摸的手指 UITouch *touch = [touches anyObject]; // 获取集合中对象 // 获取開始时的触摸点 CGPoint ...
- js 数组,字符串,JSON,bind, Name
/** * Created by W.J.Chang on 2014/5/23. */ // 判读是否是数组的方法 console.log(Array.isArray(new Array)); con ...
- SharePoint 2013 Designer 自己定义操作菜单
众所周知,我们在SharePoint的二次开发中,常常会加入ECB菜单或者Ribbon菜单,通常我们会採取Feature的方式去加入一个Xml,或者採取JavaScript的方式.当然.除此之外,还能 ...
- 自学JQuery Mobile的几个例子
JQuery Mobile是一个用于构建移动Web应用程序的框架,适用于主流的移动设备(智能手机.平板电脑),该框架利用了HTML5和CSS3技术减少了额外的脚本文件的编写.具体JQuery Mobi ...
- Couldn't load libPassword from loader:NDK开发中C文件编译成cpu对应的so类库时,找不到类库报错的原因之一
LogCat输出: 03-03 12:42:32.665: E/AndroidRuntime(32432): FATAL EXCEPTION: main03-03 12:42:32.665: E/An ...