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: ...
随机推荐
- SQL Server 缓存清理的一些原因
1.dbcc freeproccache; 2.dbcc freesystemcache('all') | dbcc freesystemcache('pool_name'); 3.declare @ ...
- System.DateTime的一些格式
//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.To ...
- J2SE知识点摘记(二十四)
覆写hashCode() 在明白了HashMap具有哪些功能,以及实现原理后,了解如何写一个hashCode()方法就更有意义了.当然,在HashMap中存取一个键值对涉及到的另外一个方法为equa ...
- Android updater-scripts(Edify Script)各函数详细说明(转)
这是Android系统来运行updater-scripts的Edify语言的基本介绍. 大部分的Edify命名都是函数,当调用这些函数结束的时候,会返回数据给脚本.当然,你也可以使用这些函数的返回值来 ...
- openstack 开发step-by-step
Set up your Open Stack There are several ways to deploy openstack, Devstack is easily for developer ...
- Android NDK 编译FFmpeg(不需要复杂的环境变量设置)
环境: CentOS6.2——64位 借鉴:https://vec.io/posts/how-to-build-ffmpeg-with-android-ndk 在根目录下创建work文件夹:cd / ...
- How to Type(dp)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Ghost Button制作教程及设计趋势分析
概述:Ghost Button(虚拟按钮)是网页设计中一个非常实用的按钮样式,特别是图片背景中,有出色的效果.今天我们一起来研究Ghost Button的各种效果的制作方法,并对Ghost Butto ...
- gulp使用心得
本文假设你之前没有用过任何任务脚本(task runner)和命令行工具,一步步教你上手Gulp.不要怕,它其实很简单,我会分为五步向你介绍gulp并帮助你完成一些惊人的事情.那就直接开始吧. 第一步 ...
- 使用分析函数实现Oracle 10G提供的CONNECT_BY_ISLEAF和CONNECT_BY_ROOT的功能(转载)
文章转载至:http://blog.csdn.net/wzy0623/article/details/1644049 如果,有侵犯您权益的地方,烦请及时的告知我,我会即刻停止侵权行为 Oracle 1 ...