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 |
样例过了。。。但是WA,求大牛看看是不是算法不对数组dpmax是记录每输入一组设备后得到的最优解, #include<iostream> #include<stdio.h> using namespace std; typedef struct bandwidth_price { int bandwidth,price; }bp ; bp dp[110],dpmax[110]; int main() { int t,n,m,i,j,bw,pr; double bpmax; scanf("%d",&t); while(t--) { for(i=0;i<110;i++) { dpmax[i].bandwidth=0; dpmax[i].price=0; } scanf("%d",&n); while(n--) { scanf("%d",&m); for(i=0;i<m;i++) { scanf("%d %d",&(dp[i].bandwidth),&(dp[i].price)); } for(i=0;i<m;i++) { bpmax=0.0;bw=pr=0; for(j=0;dpmax[j].bandwidth!=0;j++) { int a,b; a=dpmax[j].bandwidth>dp[i].bandwidth?dp[i].bandwidth:dpmax[j].bandwidth; b=dpmax[j].price+dp[i].price; if(a/(b*1.0)>bpmax) { bpmax=a/(b*1.0); bw=a; pr=b; } } if(bw!=0) {dp[i].bandwidth=bw; dp[i].price=pr;} } for(i=0;i<m;i++) { dpmax[i].bandwidth=dp[i].bandwidth; dpmax[i].price=dp[i].price; } } bpmax=0.0; for(i=0;i<m;i++) { if(dpmax[i].bandwidth/(dpmax[i].price*1.0)>bpmax) { bpmax=dpmax[i].bandwidth/(dpmax[i].price*1.0); } } printf("%.3f\n",bpmax); }return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator