Merge branch 'master' of https://github.com/thecodingwizard/usaco-guide
This commit is contained in:
commit
773aade089
5 changed files with 60 additions and 29 deletions
|
@ -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.
|
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.
|
**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.
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ In most websites (such as CodeForces and CSES), input and output are **standard*
|
||||||
|
|
||||||
### C++
|
### C++
|
||||||
|
|
||||||
The [<iostream\>](http://www.cplusplus.com/reference/iostream/) library suffices.
|
The [<iostream\>](http://www.cplusplus.com/reference/iostream/) library suffices.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -33,9 +33,35 @@ 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
|
### 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.
|
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.
|
||||||
|
|
||||||
Here is a Java template for input and output, which is effectively a faster Scanner. We import the entire `util` and `io` libraries for ease of use.
|
Here is a Java template for input and output, which is effectively a faster Scanner. We import the entire `util` and `io` libraries for ease of use.
|
||||||
|
|
||||||
|
@ -114,11 +140,11 @@ In order to test a program, create a file called `problemname.in`, and then run
|
||||||
|
|
||||||
## C++
|
## C++
|
||||||
|
|
||||||
You will need the [<cstdio\>](http://www.cplusplus.com/reference/cstdio/) or the [<fstream\>](http://www.cplusplus.com/reference/fstream/) library. Essentially, replace every instance of the word `problemname` in the word below with the input/output file name, which should be given in the problem.
|
You will need the [<cstdio\>](http://www.cplusplus.com/reference/cstdio/) or the [<fstream\>](http://www.cplusplus.com/reference/fstream/) library. Essentially, replace every instance of the word `problemname` in the word below with the input/output file name, which should be given in the problem.
|
||||||
|
|
||||||
Below, we have included C++ templates for input and output. We use `using namespace std;` so that we don't have to preface standard library functions with `std::` each time we use them.
|
Below, we have included C++ templates for input and output. We use `using namespace std;` so that we don't have to preface standard library functions with `std::` each time we use them.
|
||||||
|
|
||||||
If `<cstdio>` is used:
|
If `<cstdio>` is used:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -131,7 +157,7 @@ int main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If `<fstream>` is used: (Note that you cannot use C-style I/O (`scanf`, `printf`) with this method):
|
If `<fstream>` is used: (Note that you cannot use C-style I/O (`scanf`, `printf`) with this method):
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -194,7 +220,7 @@ public class template {
|
||||||
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
|
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("template.out")));
|
||||||
|
|
||||||
// YOUR CODE HERE
|
// YOUR CODE HERE
|
||||||
|
|
||||||
pw.close(); // flushes the output once printing is done
|
pw.close(); // flushes the output once printing is done
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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("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("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("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"),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,31 +2,33 @@ import * as React from 'react';
|
||||||
import Dots from '../Dots';
|
import Dots from '../Dots';
|
||||||
|
|
||||||
export function ResourcesListComponent(props) {
|
export function ResourcesListComponent(props) {
|
||||||
|
const embedded = props.embedded;
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<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
|
||||||
<div className="align-middle inline-block min-w-full shadow overflow-hidden sm:rounded-lg border border-purple-400">
|
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">
|
<table className="min-w-full">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th
|
<th
|
||||||
colSpan={4}
|
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">
|
Resources{props.title ? `: ${props.title}` : ''}
|
||||||
<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>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -70,10 +72,12 @@ export function ResourceComponent(props) {
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
|
{props.source && (
|
||||||
{props.source}
|
<td className="pl-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
|
||||||
</td>
|
{props.source}
|
||||||
<td className="py-4 whitespace-no-wrap text-sm leading-5 text-gray-500 w-6">
|
</td>
|
||||||
|
)}
|
||||||
|
<td className="pl-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500 w-6">
|
||||||
{props.starred && (
|
{props.starred && (
|
||||||
<svg
|
<svg
|
||||||
className="h-6 w-6 text-blue-700"
|
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">
|
<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>
|
<a href={url}>{props.title}</a>
|
||||||
</td>
|
</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}
|
{props.children}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Reference in a new issue