码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #639 (Div. 2) B - Card Constructions 二分

时间:2020-05-07 13:19:09      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:map   space   using   algo   cin   def   --   lse   main   

#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
map<ll,ll>mp1;
int cnt;
void init()
{
	cnt=2;
	mp1[1]=2;
	mp1[2]=7;
	while(mp1[cnt]<=1e9)
	{
		cnt++;
		mp1[cnt]=mp1[cnt-1]+cnt*2+cnt-1;
	}
}
void solve()
{
	int n; 
	cin>>n;
	int ans=0;
	while(n>=2)
	{
		int l=1,r=cnt;
		while(l<r)
		{
			int mid=l+r+1>>1;
			if(mp1[mid]<=n)
				l=mid;
			else
				r=mid-1;
		}
		ans++;
		n-=mp1[r];
	}
	cout<<ans<<endl;
}
int main()
{
	init();
	int t;
	cin>>t; 
	while(t--)
		solve();
	return 0;
}

Codeforces Round #639 (Div. 2) B - Card Constructions 二分

标签:map   space   using   algo   cin   def   --   lse   main   

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12842248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!