diff options
author | Darren Yao | 2020-07-20 12:53:08 -0700 |
---|---|---|
committer | GitHub | 2020-07-20 12:53:08 -0700 |
commit | 723e9f75bd83146a8fa5f76108491ede984e8269 (patch) | |
tree | eb29b9b453f73a4a46922c6deafae4131e282337 | |
parent | 8399c7dbcd15b9f80975028ce09849ff603e3f28 (diff) |
added info abt 32 bit integers, abs/rel error
-rw-r--r-- | content/1_Intro/Data_Types.mdx | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/content/1_Intro/Data_Types.mdx b/content/1_Intro/Data_Types.mdx index 89cc29b..7e092b8 100644 --- a/content/1_Intro/Data_Types.mdx +++ b/content/1_Intro/Data_Types.mdx @@ -19,25 +19,27 @@ prerequisites: There are several main **data types** that are used in contests: integers, floating point numbers, booleans, characters, and strings. Assuming that you are familiar with the language you are using, this should be mostly review. -Some problems require you to use **64-bit integers** (`long long` in C++ and `long` in Java) instead of 32-bit integers (`int`). 64-bit integers are less likely to have overflow issues, since they can store any number between $-9\,223\,372\,036\,854\,775\,808$ and $9\,223\,372\,036\,854\,775\,807$ which is roughly equal to $\pm 9 \times 10^{18}$. - -<IncompleteSection> - -- missing 32-bit integer explanation +The normal **32-bit integer** data type (`int` in C++ and Java) supports values between $−2\,147\,483\,648 and 2\,147\,483\,647, which is +roughly equal to $\pm 2 \cdot 10^9$. -</IncompleteSection> +Some problems require you to use **64-bit integers** (`long long` in C++ and `long` in Java) instead of 32-bit integers (`int`). 64-bit integers are less likely to have overflow issues, since they can store any number between $-9\,223\,372\,036\,854\,775\,808$ and $9\,223\,372\,036\,854\,775\,807$ which is roughly equal to $\pm 9 \times 10^{18}$. Sometimes (but not always) a USACO problem statement (ex. [Haircut](http://www.usaco.org/index.php?page=viewproblem2&cpid=1041)) will contain a warning such as the following: > Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++). -Contest problems are usually set such that the 64-bit integer is sufficient, so it might be a good idea to use 64-bit integers in place of 32-bit integers everywhere. Of course, you shouldn't do this when time and/or memory limits are tight, which may be the case in higher divisions of USACO. Also note that in Java, you may need to cast `long` back to `int` when accessing array indices. +Contest problems are usually set such that the 64-bit integer is sufficient, so it might be a good idea to use 64-bit integers in place of 32-bit integers everywhere. Of course, you shouldn't do this when time and/or memory limits are tight, which may be the case in higher divisions of USACO. Also note that in Java, you will need to cast `long` back to `int` when accessing array indices. + +**Floating point numbers** are used to store decimal values. It is important to know that floating point numbers are not exact, because the binary architecture of computers can only store decimals to a certain precision. Hence, we should always expect that floating point numbers are slightly off. It's generally a bad idea to compare two floating-point numbers for exact equality (`==`); instead, check if their absolute difference is less than some small constant like $10^{-9}$. + +Contest problems will accommodate the inaccuracy of floating point numbers in two different ways. -**Floating point numbers** are used to store decimal values. It is important to know that floating point numbers are not exact, because the binary architecture of computers can only store decimals to a certain precision. Hence, we should always expect that floating point numbers are slightly off. It's generally a bad idea to compare two floating-point numbers for exact equality (`==`); instead, check if their absolute difference is less than some small constant like $10^{-9}$. Contest problems will accommodate this by either asking for the greatest integer less than $10^k$ times the value, or will mark as correct any output that is within a certain $\epsilon$ of the judge's answer. +USACO problems generally have a unique answer, so when floating point is necessary, the output format will be something along the lines of "Print $10^6$ times the maximum probability of receiving exactly one accepted invitation, rounded down to the nearest integer." See [USACO Cow Dating](http://www.usaco.org/index.php?page=viewproblem2&cpid=924). -(define absolute / relative error? USACO problems will generally have a unique answer.) +In CodeForces or other contests, your output will be marked as correct if its absolute or relative difference from the actual answer is less than a given $\epsilon$. -<IncompleteSection /> +- If your output is x and the answer is y, the absolute difference is $|x-y|$. +- If your output is x and the answer is y, the relative difference is $\frac{|x-y|}{y}$. **Boolean** variables have two possible states: `true` and `false`. We'll usually use booleans to mark whether a certain process is done, and arrays of booleans to mark which components of an algorithm have finished. |