HDU 4355 – Party All the Time

來源:互聯網
上載者:User

 

題目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4355

 

三分~~ 

 

比賽時沒看到 題目輸出那裡寫的 四捨五入·~~   WA了幾次~~  當時是GSS寫的~~~。

 

這裡我自己重新做了一下~~~

 

#include<iostream>#include<cstdio>#define mul(x,y) ((x)*(x)*(x)*(y))#define abs(x) ((x)<0?0-(x):(x))using namespace std;const int maxn=50010;const double eps = 1e-6;double x[maxn],w[maxn];int n;double res(double s){double sum=0,p;for(int i=0;i<n;i++){p=abs(x[i]-s);sum+=mul(p,w[i]);}return sum;} int main(){int t,tt;double sum;scanf("%d",&t);for(tt=1;tt<=t;tt++){scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lf%lf",&x[i],&w[i]);double sum1,sum2,mid1,mid2,l=x[0],r=x[n-1];while(l<=r){mid1=(l+r)/2;mid2=(l+mid1)/2;sum1=res(mid1);sum2=res(mid2);if(mid2-eps<mid1 && mid1<mid2+eps) break;if(sum1>sum2) r=mid1; else l=mid2;}printf("Case #%d: %.0lf\n",tt,min(sum1,sum2));}return 0;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.