Fibonaccharsis+We Were Both Children

Fibonaccharsis(1853b)

题意:第数n是斐波那契的第k个数,让你求有多少满足这个的序列(成员非负,不下降)

思路:

1          2          3           4         5           6         7
0          1          1           2         3           5         8
fib(1)    fib(2)    fib(3)  fib(4)     fib(5)      fib(6)    fib(7)
0a+1b  0a+1b   1a+1b   1a+2b      2a+3b       3a+5b     5a+8b
a的系数是fib(i-1),b的系数是fib(i)

代码:

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
#include<stack>
#include<set>
#include<queue>

#define maxn 500
//#define ll long long
#define int long long

int n;
int a, b;
int minn = 0, maxx = 0x3f3f3f3f3f;
int x, y;
using namespace std;
int f(int x)
{
	if (x == 1)
		return 0;
	if (x == 2)
		return 1;
	return f(x - 1) + f(x - 2);
}
void solve()
{
	int n, k;
	cin >> n >> k;
	int a=0, b=1, c=0;
	//for (int i = 1; i <= 100; i++)//我们会发现第二十九个就超出了2*10^5即给的n最大值。
	//	//
	//{
	//	if (f(i) > 200000)
	//	{
	//		cout << "     " << i << endl;
	//		break;
	//	}
	//}
	if (k > 29)//注意特判
	{
		cout << 0 << endl;
		return;
	}
	for (int i = 1; i <= k; i++)//fib
	{
		if (i == 1)
		{
			c = 0;
			continue;
		}
		if (i == 2)
		{
			c=1;
			continue;
		}
		c = a + b;
		a = b;
		b = c;
	}
	int ans = 0;
	//a*x+b*y=n->y=(n-ax)/b&&int
	for (int i = 0; i <= n/2; i++)
	{
		if ((n - a * i) % b == 0 && ((n - a * i) / b) >= i)
			ans++;
	}
	cout << ans<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
	return 0;
}

 We Were Both Children(1850f)

题意:已知n个青蛙,他们最大能跳a[i]步。现在他们在一个线上,从0开始跳,哪一步经过的青蛙最多。就像样例那个.

思路:找出一个数,他能整除的a[i]最多。

代码

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
#include<stack>
#include<set>
#include<queue>
using namespace std;
#define maxn 200010
//#define ll long long
#define int long long

void solve()
{
	int n;
	int s[maxn];
	map<int, int>m;
	int a[maxn];
	memset(a, 0, sizeof(a));
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> s[i];
		m[s[i]]++;
	}
	//iter->first代表下标;
    //iter->second 代表值;
	for (auto iter = m.begin(); iter != m.end(); ++iter) {
		int x=iter->first;
		for (int i = x; i <= n; i += x)
			a[i] += iter->second;
	}
	int maxx = 0;
	for (int i=1;i<=n;i++)
	{
		if (a[i] > maxx)
			maxx = a[i];
	}
	cout << maxx << endl;

}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值