智商题,如果没有0就很简单,一半加一半减,恒定的,和选择无关。有0的话就可以选择和某些配对,于是就可以更改加减次数。而枚举加减次数即可,比赛时就没想清楚这一点。具体见代码
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> using namespace std; int abs(int a) { return a>0?a:-a; } int main() { int n,N; while(~scanf("%d",&n)) { N=n<<1; int i,j,t,sum=0,zero=0; for(i=0;i<N;i++) { scanf("%*d.%d",&t); sum-=t; zero+=(t==0); } sum+=1000*n; int mi=max(0,zero-n),ma=min(zero,n); int ans=1000000000; for(int i=mi;i<=ma;i++) { ans=min(ans,abs(sum-i*1000)); } printf("%.3f\n",ans/1000.0); } }