考场源代码(WA on 22 ,70分):
#include<bits/stdc++.h>
using namespace std;
namespace io
{
const int L=1<<21|1;
char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];
int f,tp;
#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++)
inline void Flush(){
fwrite(obuf,1,oS-obuf,stdout);
oS=obuf;
}
inline void pc(char x){
*oS++=x;
if(oS==oT)Flush();
}
template<typename _Tp>
inline void gi(_Tp& x)
{ //get
for(c=gc();c<'0'||c>'9';c=gc());
for(x=0;c<='9'&&c>='0';c=gc())x=(x<<3)+(x<<1)+(c&15);
}
inline void pr(int x,char ch)
{
if(x<0)pc('-'),x=-x;tp=0;
st[++tp]=x%10^'0';
for(x/=10;x;x/=10)st[++tp]=x%10^'0';
while(tp)pc(st[tp--]);
pc(ch);
}
}; // namespace io
using namespace io;
#define ll long long
#define cn const
int a[7000001];
int n;
double gt(int m)
{
double v=0;
for(int i=1;i<=n;i++)v+=(double)a[i]/n;
double s=0;
for(int i=1;i<=n;i++)s+=(double)(a[i]-v)*(a[i]-v)/n*m*m;
return s;
}
double s1;
inline double get(int m){return s1*m*m;}
int main()
{
ios::sync_with_stdio(false);
gi(n);ll k;gi(k);
for(int i=1;i<=n;i++)gi(a[i]);
double c=gt(1);if(c<0.0000001){cout<<"No answer!";return 0;}
k/=c;
ll l=1,r=3000000000;
while(l!=r-1)
{
ll m=(l+r)>>1;
if((ll)m*m<k)l=m;else r=m;
}
if(r*r-k>=k-l*l)cout<<l;else cout<<r;
return 0;
}
其中判 No answer 时的那一句“c<0.0000001”改为“c<0.0001”就过了