HDU 5753 Permutation Bo
计算每个c[i]对答案做出的贡献,累加即可。手算一下会发现是:c[1]/2+(c[2]+....c[n-1])/3+c[n]/2。注意:一个数的时候直接输出那个数。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi = acos(-1.0), eps = 1e-8; void File() { freopen("D:\\in.txt", "r", stdin); freopen("D:\\out.txt", "w", stdout); } inline int read() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } int main() { int n; while(~scanf("%d",&n)) { if(n==1) { int x; scanf("%d",&x); printf("%d\n",x); } else { double ans=0; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); if(i==1||i==n) ans=ans+1.0*x/2; else ans=ans+1.0*x/3; } printf("%lf\n",ans); } } return 0; }