(帖子已被作者删除)(bushi

#include<bits/stdc++.h>
using namespace std;
int a[100010],t,n,ans;
void f(int x){
	if(x<2)return;
	int l=0,r=100010;
	while(l<r){
		int mid=(l+r)/2;
		if(a[mid]>=x)r=mid-1; 
		else l=mid;
	}ans++;
	f(x-a[l]);
}long long cnt=0,tmp=2,idx=-1;
int main(){
	while(cnt<=1e9){
		cnt+=tmp;
		tmp+=3;
		idx++;
		a[idx]=cnt;
	}cin>>t;
	while(t--){
		ans=0;
		cin>>n;
		f(n);
		cout<<ans<<endl;
	}
	return 0;
}
4 个赞

不会

3 个赞

题号/题面?

2 个赞

是不是 5. NOIP2015-S-DAY2-1-跳石头这题

3 个赞

3 个赞

二分+预处理

3 个赞

核心代码如下:

while(t--){
		cin>>n;
		ans=0;
		while(1){
			if(n<2)break;
			for(long long i=1;;i++){
				if(a[i]>n){
					ans++;
					n-=a[i-1];
					break;
				}
			}	
		}
		cout<<ans<<"\n";
	}
2 个赞

先打个表,求出小于1e9的塔需要的牌数,然后二分即可

2 个赞

预处理代码如下

while(an<100000){
		if((3*cnt*cnt+cnt)/2>=1000000000){
			a[++an]=(3*cnt*cnt+cnt)/2;
			break;
		}
		a[++an]=(3*cnt*cnt+cnt)/2;
		cnt++;
	}
···
**不要脸求个解决方案**
2 个赞

AC了

2 个赞

如果对你有帮助,请给个解决方案

2 个赞

bushi,你是懂解决方案的

2 个赞

好的

1 个赞
while(an<100000){
		if((3*cnt*cnt+cnt)/2>=1000000000){
			a[++an]=(3*cnt*cnt+cnt)/2;
			break;
		}
		a[++an]=(3*cnt*cnt+cnt)/2;
		cnt++;
	}
···
**不要脸求个解决方案**

但吧这个删掉

1 个赞

https://discourse.xinyoudui.com/t/topic/13966
我得到了一个解决方案,给你一个

1 个赞

没删掉,不给了

2 个赞