2018/08/02 15:57

HDU2050 折线分割平面 （递推）

Sample Input

2
1
2


Sample Output

2
7


题解

思路

f(n)=f(n-1)+4(n-1)+1 n>=3*

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
int T =0;
const int MAXN=1e5+10;
const int MAX =1e8+10;
int ans[MAXN];
int a=0;

int line(){
ans[1]=2;
for(int j=2;j<MAXN+2;j++){
ans[j]=ans[j-1]+4*(j-1)+1;
}

return 1;
}

int main(void){
line();
scanf("%d",&T);
for(int i =0;i<T;i++){
scanf("%d",&a);
printf("%d\n",ans[a]);
}
return 0;

}


CSU2059 Water Problem（递推）

Sample Input

2
1
2


Sample Output

2
12


题解

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

int main(){
int T = 0;
scanf("%d",&T);
for(int i=0;i<T;i++){
ll h = 0;
scanf("%lld",&h);
ll ans = (long long )(4.5*(h+2)*(h-1)-8*(h-1)+2);
printf("%lld\n",ans);
}

return 0;
}


总结

https://blog.csdn.net/zhouhong1026/article/details/7854948

0
0 收藏

0 评论
0 收藏
0