poj 1018 Communication System
来源:互联网 发布:parsley.js 手册 编辑:程序博客网 时间:2024/05/21 14:51
首先,把所有元素按照带宽从小到大排序,然后枚举每一个带宽,并把它当做所选带宽中的最小值。
#include <iostream>#include<cstring>#include<stdio.h>#include<algorithm>#include<math.h>#define INF 100000000using namespace std;typedef struct{ int group; double b,p;}device;device de[10010];int num[110],re[110];double mini[110];int cmp(const void * x,const void * y){ return((*(device *)y).b>(*(device *)x).b)?-1:1;}int main(){ int t,ok; double min_b; double sum; scanf("%d",&t); while(t--){ int n; //n组设备 scanf("%d",&n); int count=0; double ans=0; for(int i=1;i<=n;i++){ scanf("%d",&num[i]); //记录每组设备有多少个 mini[i]=INF; //记录每组满足情况的最小价格 for(int j=1;j<=num[i];j++){ double temp_1,temp_2; scanf("%lf %lf",&temp_1,&temp_2); de[count].group=i; //第几组 de[count].b=temp_1; //带宽 de[count++].p=temp_2; //价格 } } int len=count; qsort(de,len,sizeof(device),cmp); for(int i=0;i<len;i++){ min_b=de[i].b; //最小的带宽 memset(re,0,sizeof(re)); sum=0; ok=1; //每一组都有满足情况的 re[de[i].group]=1; for(int m=1;m<=n;m++) mini[m]=INF; mini[de[i].group]=de[i].p; for(int j=1;j<len;j++){ if(de[j].group!=de[i].group&&de[j].b>=min_b&&de[j].p<mini[de[j].group]) { re[de[j].group]=1; mini[de[j].group]=de[j].p; //记录每一组价格最小值 } } for(int k=1;k<=n;k++){ sum+=mini[k]; if(re[k]==0) { ok=0; sum=-1; break; } } if(ok==1&&(min_b/sum)>ans){ ans=min_b/sum; } if(ok==0) break; } double temp=ans*1000+0.5; if(temp-floor(temp)<0) ans+=0.001; printf("%.3lf\n",ans); } return 0;}
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- poj 1018 Communication System
- poj-1018 Communication System
- POJ-1018 Communication System
- [POJ][1018]Communication System
- poj 1018Communication System
- poj 1018:Communication System
- hdu 2084 数塔
- hdu 2094 产生冠军
- hdu 2647 Reward
- hdu 1811 Rank of Tetris
- hdu 1158 Employment Planning
- poj 1018 Communication System
- hdu 1827 Summer Holiday
- hdu 1295 Move Move Look
- poj 2367 Genealogical tree
- poj 3660 Cow Contest
- poj 3553 Task schedule
- C++ 简单实现HTTP GET/POST 请求
- poj 2488 A Knight's Journey
- 问题集2