Codeforces Gym 100425A Luggage Distribution 二分 数学
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
Output
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 二分 数学的更多相关文章
- Gym 100425A Luggage Distribution (组合数学,二分)
一开始想着球盒模型,数据范围大,递推会GG. 用凑的方法来算方案.往n个小球之间插两个隔板,方案是(n-1)*(n-2)/2,不区分盒子,三个盒子小球数各不相同的方案数被算了6次(做排列), 两个相同 ...
- Codeforces Gym 100002 D"Decoding Task" 数学
Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 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 ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
随机推荐
- 在web.config里使用configSource分隔各类配置
转:http://www.yongfa365.com/Item/using-configSource-Split-Configs.html 大型项目中,可能有多个Service,也就是会有一堆配置,而 ...
- winfrom dataGridView 自定义分页实现
Winfrom 基本处于忘光的阶段.先需要做个winfrom 的软件.然后自己扩展了DataGridView带分页的控件.废话不多说 上图先 现在一步步实现其效果. 1.添加用户控件 上图即可知道 ...
- hdu 2457(ac自动机+dp)
题意:容易理解... 分析:这是一道比较简单的ac自动机+dp的题了,直接上代码. 代码实现: #include<stdio.h> #include<string.h> #in ...
- Multiple View Geometry in Computer Vision Second Edition by Richard Hartley 读书笔记(一)
var bdots = "../" var sequence = [ 'l1', 'l2', 'l3', 'l4' ]; Chapter1是个总览,引出了射影几何的概念,通过在欧式 ...
- python os.walk()和os.path.walk()
一.os.walk() 函数声明:os.walk(top,topdown=True,onerror=None) (1)参数top表示需要遍历的顶级目录的路径. (2)参数topdown的默认值是“Tr ...
- Min Edit Distance
Min Edit Distance ----两字符串之间的最小距离 PPT原稿参见Stanford:http://www.stanford.edu/class/cs124/lec/med.pdf Ti ...
- Azure终于支持大容量虚拟机了-最高32核,448G内存
Azure终于支持大容量虚拟机了-最高32核,448G内存 最近微软Azure虚拟机旗下的大容量G系列虚拟机通用版本正式上线.G系列虚拟机方案提供公有云领域最大的内存容量.最强处理能力以及空间可观的本 ...
- sys.check_constraints
每个用作 CHECK 约束(sys.objects.type = C)的对象都在表中占一行. SELECT name FROM sys.check_constraints -- equal to SE ...
- dfs.datanode.max.xcievers参数导致hbase集群报错
2013/08/09 转发自http://bkeep.blog.163.com/blog/static/123414290201272644422987/ [案例]dfs.datanode.max.x ...
- Unity中的单实例
static GUIManager myInstance; public static GUIManager Instance { get { if (myInstance == null) myIn ...