问题描述
我一直在寻找一些在谷歌code果酱的解决方案,而有些人用这个东西,我以前从未见过。例如,
2LL * R + 1LL
这是什么2LL和1LL意思?
他们包括如下:
的#include<&math.h中GT;
#包括LT&;&算法GT;
#定义_USE_MATH_DEFINES
或
的#include<&CMATH GT;
的 LL
使得整数文字类型的长长
。
所以 2LL
,类型为2 长长
。
如果没有 LL
,字面只会类型的 INT
。
这时候你在做这样的东西很重要:
1 LT;< 40
1LL<< 40
通过只是字面 1
,(假设 INT
是32位的,你转移超出大小整型 - >未定义行为)。
随着 1LL
,你的类型设置为长长
前手,现在将正确返回2 ^ 40。
I was looking at some of the solutions in Google Code Jam and some people used this things that I had never seen before. For example,
2LL*r+1LL
What does 2LL and 1LL mean?
Their includes look like this:
#include <math.h>
#include <algorithm>
#define _USE_MATH_DEFINES
or
#include <cmath>
The LL
makes the integer literal of type long long
.
So 2LL
, is a 2 of type long long
.
Without the LL
, the literal would only be of type int
.
This matters when you're doing stuff like this:
1 << 40
1LL << 40
With just the literal 1
, (assuming int
to be 32-bits, you shift beyond the size of the integer type -> undefined behavior).With 1LL
, you set the type to long long
before hand and now it will properly return 2^40.
这篇关于什么是1LL或2LL在C和C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!