Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
47ms 257K 枚举方法是看网上的,自己独立写了一遍,并给出了优化:每次枚举时有一种设备无法选出,则这次枚举失败并跳出循环进行下一次枚举。不过效果不明显。QAQ 从小到大枚举整个情况的最小流量,再在每种设备中选出大于该最小流量并且在这个种类中选取最小费用的。每次枚举结尾更新最大值。 #include <stdio.h> #define MAXN 101 #define max(x,y) (x)>=(y)?(x):(y) #define min(x,y) (x)<=(y)?(x):(y) const int INF=0x3f3f3f3f; typedef struct { int width; int price; }Device; Device de[MAXN][MAXN]; int num[MAXN]; int main() { int t,n,i,j,k; int Min,Max; int sum,M; double ans; bool flag; scanf("%d",&t); while(t--) { scanf("%d",&n); Max=-1,Min=INF; ans=0; for(i=1;i<=n;++i) { scanf("%d",&num[i]); for(j=1;j<=num[i];++j) { scanf("%d %d",&de[i][j].width,&de[i][j].price); Max=max(Max,de[i][j].width); Min=min(Min,de[i][j].width); } } for(k=Min;k<=Max;++k) { sum=0,flag=true; for(i=1;i<=n;++i) { M=INF; for(j=1;j<=num[i];++j) if(de[i][j].width>=k&&de[i][j].price<M) M=de[i][j].price; if(M==INF) { flag=false; break; } sum+=M; } if(flag&&(double)k/sum>ans) ans=(double)k/sum; } printf("%.3lf\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator