This commit is contained in:
Benjamin Qi 2020-06-28 21:18:02 -04:00
commit 773aade089
5 changed files with 60 additions and 29 deletions

View file

@ -18,7 +18,7 @@ There are several main **data types** that are used in contests: 64-bit integers
It's a good idea to use 64-bit integers (`long long` in C++) 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}$. Contest problems are usually set such that the 64-bit integer is sufficient. 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.
**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. 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. (what's epsilon?)
**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. Never try 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. (what's epsilon?)
**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.

View file

@ -33,6 +33,32 @@ int main() {
}
```
Alternatively, you can use the [<cstdio\>](http://www.cplusplus.com/reference/cstdio/) library's `scanf` anf `printf` functions, which are slightly more complicated to use, but are significantly faster (generally only an issue with large input sizes):
```cpp
#include <cstdio>
using namespace std;
int main() {
int x, y;
// %d specifies that a value of type int is being input.
// Use %lld (a few judging platforms might need %I64d)
// to input a long long (64-bit) integer.
// Many other specifiers are also available; see link for more details.
// Be sure to add a & character (address-of operator) when using
// scanf, UNLESS you are inputing a string with %s.
// It is possible to input multiple values at a time as shown below.
scanf("%d%d", &x, &y);
// Specifiers for printf are mostly the same as those used
// by scanf, with the notable exception of floating-point numbers.
// Use a backslash character followed by the lowercase
// letter n to denote a newline.
// The address-of operator, &, is not used here.
printf("Found %d and %d\n", x, y);
}
```
### Java
In your CS classes, you've probably implemented input and output using standard input and standard output, or using [`Scanner`](https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html) to read input and `System.out.print` to print output. These methods work, but `Scanner` and `System.out.print` are slow when we have to handle inputting and outputting tens of thousands of lines. Thus, we use `BufferedReader` and `PrintWriter` instead, which are faster because they buffer the input and output and handle it all at once as opposed to parsing each line individually.

View file

@ -24,6 +24,7 @@ export const metadata = {
new Problem("HR", "Subtrees & Paths", "https://www.hackerrank.com/challenges/subtrees-and-paths", "Easy", false, ["HLD"], ""),
new Problem("CF", "Tree Queries", "contest/1254/problem/D", "Normal", false, ["HLD"], ""),
new Problem("ojuz", "JOI - Cats or Dogs", "https://oj.uz/problem/view/JOI18_catdog", "Hard", false, ["HLD"], ""),
new Problem("wcipeg", "COI 08-Otoci", "https://wcipeg.com/problem/coi08p2", "Hard", false, ["HLD"], "editorial available online"),
],
}
};

View file

@ -2,31 +2,33 @@ import * as React from 'react';
import Dots from '../Dots';
export function ResourcesListComponent(props) {
const embedded = props.embedded;
return (
<div className="flex flex-col">
<div className="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div className="align-middle inline-block min-w-full shadow overflow-hidden sm:rounded-lg border border-purple-400">
<div
className={`overflow-x-auto ${
embedded
? '-mx-4 sm:-mx-6'
: 'sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8 -my-2 py-2'
}`}
>
<div
className={`align-middle inline-block min-w-full overflow-hidden shadow ${
!embedded && 'rounded-lg border border-purple-400'
}`}
>
<table className="min-w-full">
<thead>
<tr>
<th
colSpan={4}
className="px-6 py-4 border-b border-purple-200 bg-purple-50 text-left font-medium text-purple-500 uppercase"
className={`px-6 border-b text-left font-medium uppercase ${
embedded
? 'text-sm py-2 border-gray-200 bg-gray-50 text-gray-500'
: 'py-3 border-purple-200 bg-purple-50 text-purple-500'
}`}
>
<div className="flex items-center">
<svg
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
stroke="currentColor"
className="h-6 w-6 mr-3"
>
<path d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z" />
</svg>
Resources{props.title ? `: ${props.title}` : ''}
</div>
</th>
</tr>
</thead>
@ -70,10 +72,12 @@ export function ResourceComponent(props) {
}
return (
<tr>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
{props.source && (
<td className="pl-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
{props.source}
</td>
<td className="py-4 whitespace-no-wrap text-sm leading-5 text-gray-500 w-6">
)}
<td className="pl-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500 w-6">
{props.starred && (
<svg
className="h-6 w-6 text-blue-700"
@ -87,7 +91,7 @@ export function ResourceComponent(props) {
<td className="pl-3 pr-6 py-4 whitespace-no-wrap text-sm leading-5 font-medium text-gray-900">
<a href={url}>{props.title}</a>
</td>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
<td className="w-100 px-6 py-4 text-sm leading-5 text-gray-500">
{props.children}
</td>
</tr>