http://ac.jobdu.com/problem.php?pid=1386
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。
这个题不就是求数组最小值吗?跟旋转有什么关系?
#include <stdio.h>
#define N 1000000
int main()
{
int i,n;
int a[N];
int result;
while(scanf("%d", &n) != EOF)
{
for (i=0; i<n; i++)
scanf("%d", &a[i]);
if (n == 1)
{
printf("%d\n", a[0]);
continue;
}
for (i=1; i<n; i++)
{
if (a[i] < a[i-1])
break;
}
if (i==n)
result = a[0];
else
result = a[i];
printf("%d\n", result);
}
return 0;
}
/************************************************************** Problem: 1386 User: liangrx06 Language: C Result: Accepted Time:700 ms Memory:4748 kb ****************************************************************/
http://ac.jobdu.com/problem.php?pid=1387
求第n项斐波那契数列的值。
用数组递归。
#include <stdio.h>
int main(void)
{
int n, i;
long long a[71];
while (scanf("%d", &n) != EOF)
{
a[0] = 0;
a[1] = 1;
for (i=2; i<=n; i++)
a[i] = a[i-1] + a[i-2];
printf("%lld\n", a[n]);
}
return 0;
}
/**************************************************************
Problem: 1387
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/
http://ac.jobdu.com/problem.php?pid=1388
实际上是求斐波那契数列。
数组递归。
#include <stdio.h>
int main()
{
int i,n;
long long a[71];
while(scanf("%d", &n) != EOF)
{
a[0] = a[1] = 1;
for (i=2; i<=n; i++)
a[i] = a[i-1] + a[i-2];
printf("%lld\n", a[n]);
}
return 0;
}
/**************************************************************
Problem: 1388
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/
http://ac.jobdu.com/problem.php?pid=1389
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
已经不是斐波那契数列,但仍然用数组递归来求。
#include <stdio.h>
int main()
{
int i, j, n;
long long a[71];
while(scanf("%d", &n) != EOF)
{
a[0] = a[1] = 1;
for (i=2; i<=n; i++)
{
j = i-1;
a[i] = 0;
while (j>=0)
{
a[i] += a[j];
j--;
}
}
printf("%lld\n", a[n]);
}
return 0;
}
/**************************************************************
Problem: 1389
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/
http://ac.jobdu.com/problem.php?pid=1390
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
实际上是斐波那契数列。
#include <stdio.h>
int main()
{
int i,n;
long long a[71];
while(scanf("%d", &n) != EOF)
{
a[0] = a[1] = 1;
for (i=2; i<=n; i++)
a[i] = a[i-1] + a[i-2];
printf("%lld\n", a[n]);
}
return 0;
}
/**************************************************************
Problem: 1390
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/