zoj 1409 Communication System
来源:互联网 发布:python 程序 编辑:程序博客网 时间:2024/05/01 12:10
对每一个带宽求最大的B/P值:把每一种设备的各种厂家产品按价格从低到高排序,对每一种设备,最先满足要求的即为最优。。。。。。。算是贪心吧
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
#define E 1e-3
#define M 105
struct data{
int b,p;
}c[M][M];
int num[M],n,cnt,x[105*105];
int cmp(const data &a,const data &b){
if(a.p<b.p) return 1;
else if(a.p==b.p){
if(a.b>b.b)return 1;
else return 0;
}else return 0;
}
int main(){
int T,i,j,k,sum,flag; double max,now;
scanf("%d",&T);
while(T--){
cnt=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&num[i]);
for(j=0;j<num[i];j++){
scanf("%d %d",&c[i][j].b,&c[i][j].p);
x[cnt++]=c[i][j].b;
}
sort(c[i],c[i]+num[i],cmp);
}
max=0;
for(k=0;k<cnt;k++){
sum=0;flag=1;
for(i=0;i<n;i++){
for(j=0;j<num[i];j++)
if(c[i][j].b>=x[k]){
sum+=c[i][j].p; break;
}
if(j==num[i]){flag=0; break;}
}
now=x[k]*1.0/(sum*1.0);
if(flag==1){
if(now-max>=E)max=now;
}
}
printf("%.3f\n",max);
}
return 0;
}
- zoj 1409 Communication System
- ZOJ 1409 Communication System
- ZOJ 1409 Communication System
- ZOJ 1409 Communication System(枚举 + 贪心)
- ZOJ 1409 Communication System(枚举 + 贪心)
- Communication System
- Communication System
- Communication System
- Communication System
- Communication System
- zoj 3500 island communication
- zoj 3509 Island Communication
- 1018 Communication System - 贪心
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- 1018 Communication System
- POJ 1018 Communication System
- 使用Vitamio打造自己的Android万能播放器(4)——本地播放(快捷搜索、数据存储)
- PHP导出excel
- 什么是ORM及ORM的详解
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- zoj 1409 Communication System
- 基于工作流的煤矿企业综合信息管理系统
- httpClient中文乱码问题解决(wap提交)
- 记录下:在html中利用JavaScript动态的显示日期和时间
- 程序员成功面试技巧
- Flex程序与html通信方法大全
- 怎么更好使用google
- vim 如何在不同编辑器(VIM~gedit~firefox~etc.)之间复制粘贴
- Android ListView从网络获取图片及文字显示