A - Luggage Distribution
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87493#problem/A

Description

All provident tourists know about low-cost airlines. Those who used them at least once also know that their airfare usually includes neither lunch nor luggage.

Naturally, tourists don't want to overpay luggage fee, therefore they distribute their luggage so that it satisfies all airline requirements.

A certain tourist prepaid three luggage slots. Then he calculated the number of different ways K to distribute weight N among these three slots so that all luggage is packed, none of the slots are empty and all weights are integers. The order of the slots does not matter, so, for example, two distributions 2,  2,  1 and 2,  1,  2 are considered the same.

After landing, the tourist realised that the airline lost all his luggage! And while filling in a lost and found application, he found out that he does not remember the weight of each slot. He remembered only the fact that the number of ways K to pack the luggage was at least Land did not exceed R.

You need to calculate number of possible integer total weights N that could have been in the tourist's luggage.

 

Input

The single line of input holds two integer numbers L and R (1 ≤ L ≤ R ≤ 1017): the minimum and maximum number of ways to distribule the luggage in three slots.

Output

Output a single integer: the number of possible total weigths N that could have been carried by the tourist.

Sample Input

2 4

Sample Output

3

HINT

题意

对于一个数,分成三个数的不同分法有多少种。

但是题目并不问这个,而是问,给你L,R的方案数,问你分法为这么多的数有多少个

题解

先打表,然后推公式,推出来之后再二分就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef unsigned long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1005000
#define mod 10007
#define eps 1e-6
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll get1(ll x)
{
ll ans=(ceil)(((x-)*(x-)*1.0)/*1.0+(x-)*1.0/2.0);
if((x-)%==)
ans++;
return ans;
}
ll get(ll x)
{
ll ans=(x-)*(x+);
if(ans%12LL==) ans/=12LL;else ans=ans/12LL+1LL;
if((x-)%==)
ans++;
return ans;
} ll solve(ll x)
{
ll l=,r=0x7fffffffLL;
while(l<=r)
{
ll mid=(l+r)/;
ll G=get(mid);
if(G<x)
l=mid+;
else
r=mid-;
}
return l;
}
int main()
{
ll l,r;
cin>>l>>r;
ll a1=solve(l);
ll a2=solve(r);
if(get(a2)>r)
a2--;
if(r==)
a2++;
cout<<a2-a1+<<endl;
}

Codeforces Gym 100425A Luggage Distribution 二分 数学的更多相关文章

  1. Gym 100425A Luggage Distribution (组合数学,二分)

    一开始想着球盒模型,数据范围大,递推会GG. 用凑的方法来算方案.往n个小球之间插两个隔板,方案是(n-1)*(n-2)/2,不区分盒子,三个盒子小球数各不相同的方案数被算了6次(做排列), 两个相同 ...

  2. Codeforces Gym 100002 D"Decoding Task" 数学

    Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  3. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  4. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

  5. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  6. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  7. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  8. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  9. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

随机推荐

  1. Delphi 使用串口模拟工具进行串口程序开发调试

      版权声明:本文为博主原创文章,如需转载请注明出处及作者. 本文由小李专栏原创,转载需注明出处:[http://blog.csdn.net/softwave/article/details/8907 ...

  2. 读pomelo的教程-1

    pomelo教程的例子是一个聊天室,包括一个webserver客户端,和一个gameserver的pomelo服务器.这个例子挺好,一个聊天系统逻辑简单,还包括了用户管理,客户端request,服务器 ...

  3. 如何避免JavaScript的内存泄露及内存管理技巧

    发表于谷歌WebPerf(伦敦WebPerf集团),​​2014年8月26日. 高效的JavaScript Web应用必须流畅,快速.与用户交互的任何应用程序,都需要考虑如何确保内存有效使用,因为如果 ...

  4. ASP.NET MVC中的Json Binding和Validate

    引子:电子商务网站支付功能页面往往会有很多信息,对于这些信息的保存,往往是分步完成的,那么使用Ajax最合适不过了,比如其中的收货人信息模块.这些信息的新建和编辑保存都是用Ajax来完成的.那么有几种 ...

  5. 利用Javascript获取当前日期的农历日期

    来源:http://www.ido321.com/926.html JavaScript代码 1: /*设置农历日期*/ 2: var CalendarData=new Array(100); 3: ...

  6. linux进程调度函数浅析(基于3.16-rc4)

    众所周知,进程调度使用schedule()函数来完成,下面我们从分析该函数开始,代码如下(kernel/sched/core.c): asmlinkage __visible void __sched ...

  7. 单词计数WordCountApp.class

    public class WordCountApp { // 可以指定目录,目录下如果有二级目录的话,是不会执行的,只会执行一级目录. private static final String INPU ...

  8. HDU ACM Eight

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 解题背景: 看到八数码问题,没有任何的想法,偶然在翻看以前做的题的时候发现解决过类似的一道题,不 ...

  9. SAE 合并图片

    $domain = 'picleader'; //图片库的域名 $stgurl = 'http://lemonluoxing-picleader.stor.sinaapp.com/'; //绝对路径 ...

  10. (转)Http协议经典详解

    转自:http://blog.csdn.net/gueter/archive/2007/03/08/1524447.aspx Author :Jeffrey 引言 HTTP 是一个属于应用层的面向对象 ...