hdu 2011
打表做的,需要注意的是打表时,没有用下标0,从1开始
#include<bits/stdc++.h> using namespace std; int main() { float a[1002]={0,1},sum[1002]={0,1}; for(int i = 2; i < 1001;i++){ a[i] = 1.0 / i; if(i%2==0) a[i] = (-1)*a[i]; //cout << a[i] << endl; sum[i] = sum[i-1] + a[i]; } int n; scanf("%d",&n); while(n--){ int t; scanf("%d",&t); printf("%.2f\n",sum[t]); } return 0; }