BZOJ2708: [Violet 1]木偶 贪心+dp
BZOJ2097: [Usaco2010 Dec]Exercise 奶牛健美操 二分答案+贪心+DP

BZOJ2796: [Poi2012]Fibonacci Representation 暴力

shinbokuow posted @ Sep 01, 2015 09:51:51 AM in BZOJ with tags 暴力 , 1242 阅读

 

题解:

感觉上暴力好像是卡不掉的,但是我并不知道为什么。

感觉有点虚于是预处理了500W的一个表。

于是就这样过了。

代码:

#include<cstdio>
#include<cctype>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

typedef long long ll;
ll f[110];

map<ll,int>M;

int c[5000010];
inline int solve(ll x){
	int n=upper_bound(f+1,f+89,x)-f;
	if(x==f[n-1])
		return 1;
	else
		return min(c[x-f[n-1]],c[f[n]-x])+1;
}
inline int Solve(ll x){
	if(x<=5000000)
		return c[x];
	int n=upper_bound(f+1,f+89,x)-f;
	if(x==f[n-1])
		return 1;
	else
		return min(Solve(x-f[n-1]),Solve(f[n]-x))+1;
}
int main(){
	int i,j;
	for(f[1]=1,f[2]=2,i=3;i<=88;++i)
		f[i]=f[i-1]+f[i-2];
	for(i=1;i<=5000000;++i)
		c[i]=solve(i);
	int T;
	cin>>T;
	ll n;
	while(T--){
		cin>>n;
		cout<<Solve(n)<<endl;
	}
	return 0;
}
Twan 说:
Jul 26, 2023 02:33:27 PM

What a delightful collection of codes! As a teacher myself, I can't help but smile at these that capture the essence of our profession. These blogs will surely add a touch of perfection to the classroom and create a positive atmosphere for both teachers and students. SEO experts Cochin The "Fibonacci Representation" is my personal favorite – it perfectly sums up our multitasking skills! I'll definitely check out this. Thank you for sharing these fantastic finds!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter