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 |
杭电和poj区别相同的时间限制,相同的代码,杭电上AC而poj上竟然超时了!!!!! 而杭电上WA的代码poj上竟然AC了!!!! #include<iostream> #include<stdio.h> #include <algorithm> #include <cstdlib> #include<cmath> #include<string.h> using namespace std; double a[10009]; double pi=acos(-1.0); int main() {//杭电上AC而POJ上超时的代码 int t; scanf("%d",&t); while(t--) { int n,f; cin>>n>>f; f++; double min=0,max=0; for(int i=1;i<=n;i++) { int tem; scanf("%d",&tem); a[i]=pow(tem,2.0); //min=min<a[i]?min:a[i]; max+=a[i]; } double mid=(max+min)/2; int sum=0; //cout<<"aa"<<max<<"bb"<<mid<<endl; while((max-mid)>0.00000001) {//cout<<"ok"<<endl; sum=0; for(int i=1;i<=n;i++) { sum+=(int)(a[i]/mid); } if(sum>=f){min=mid;mid=(max+min)/2;} else{max=mid;mid=(max+min)/2;} } //cout<<sum<<endl; double s=mid*pi; printf("%.4lf\n",s); } return 0; } ======================= #include<iostream> #include<stdio.h> #include <algorithm> #include <cstdlib> #include<cmath> #include<string.h> using namespace std; int a[10009]; double pi=acos(-1.0); int main() {//杭电上WA而POJ上AC的代码,,郁闷 int t; scanf("%d",&t); while(t--) { int n,f; cin>>n>>f; f++; double min=0,max=0; for(int i=1;i<=n;i++) { int tem; scanf("%d",&tem); a[i]=pow(tem,2.0); max+=a[i]; } double mid=(max+min)/2; int sum=0; while((max-mid)>0.000001) { sum=0; for(int i=1;i<=n;i++) { sum+=(int)(a[i]/mid); } if(sum>=f){min=mid;mid=(max+min)/2;} else{max=mid;mid=(max+min)/2;} } double s=mid*pi; printf("%.4lf\n",s); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator