David Lu
Software Developer
Yung-Sheng Lu
FEB 02, 2015
@NCKU-CSIE
Lecture 1
UVa Online Judge (UVa)
PKU Online Judge (POJ) - 北京大學線上程式解題系統
CodeForces - 線上程式競賽
ACM-ICPC Live Archive
ZeroJudge (ZOJ) - 高中生程式解題系統
ZeroJudge2 (ZOJ2) - 國際大專院校程式競賽推廣與培訓
線上協作平台
NCKU Online Judge
Timus Online Judge
PTC 程式設計競賽 - 月賽
CPE 大學生程式能力檢定 - 每學期二次
Google Code Jam
Facebook Hacker Cup
問題限制 (Limits)
時間限制 (Time Limit)
記憶體限制 (Memory Limit)
參考資訊
Total Submissions
Accepted
問題描述 (Description)
輸入格式 (Input)
輸出格式 (Output)
輸入範例 (Sample Input)
輸出範例 (Sample Output)
Big O Notation - 至多
Big θ Notation - 恰巧
Big Ω Notation - 至少
Constant Time -
Logarithmic Time -
Linear Time -
Quadratic Time -
Quasilinear Time -
Factorial Time -
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
a[i][j] = i * j;
}
}
/* Maximum n = m */
int two(int n) {
if (n < 2)
return 1 << n;
return two(n - 1) + two(n - 1);
}
Input functions
Output functions
int scanf(const char *format, ...);
int sscanf(char *s, const char *format, ...);
int getchar(void);
char *gets(char *s);
int printf(const char *format, ...);
int sprintf(char *s, const char *format, ...);
int putchar(int c);
int puts(const char *s);
#include <cstdio>
using namespace std;
Input functions
Output functions
#include <iostream>
using namespace std;
// Extract formatted input
istream::operator>>
// Get characters
istream::get
// Get line
istream::getline
// Get character count
istream::gcount
// Read block of data
istream::read
// Insert formatted output
ostream::operator<<
// Put characters
ostream::put
// Write block of data
ostream::write
// Flush output stream buffer
ostream::flush
File open
FILE *fopen(const char *filename, const char *mode);
int fclose(FILE *stream);
#include <cstdio>
using namespace std;
int fscanf(FILE *stream, const char *format, ...);
int fgetc(FILE *stream);
char *fgets(char *s, int n, FILE *stream);
int fprintf(FILE *stream, const char *format, ...);
int fputs(const char *s, FILE *stream);
int fputs(const char *s, FILE *stream);
/* Sample code */
fPtr = fopen("filename.txt", "r");
if (!fPtr) {
printf("File open failed.\n");
exit(1);
}
fscanf(fPtr, "%s%d%s", c1, &c3, c4);
fprintf(fPtr, "%d\n", y);
fclose(fPtr);
File open
void open (const char* filename,
ios_base::openmode mode = ios_base::in | ios_base::out);
void open (const string& filename,
ios_base::openmode mode = ios_base::in | ios_base::out);
bool is_open() const;
#include <fstream>
using namespace std;
void close();
void swap (fstream& x);
/* Sample code */
fs.open ("test.txt");
if (fs.is_open())
fs.close();
else
cout << "Error opening file";
Containers
Containers are used to manage collections of objects of a certain kind. There are several different types of containers like deque, list, vector, map etc.
Algorithms
Algorithms act on containers. They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers.
Iterators
Iterators are used to step through the elements of collections of objects. These collections may be containers or subsets of containers.
template < class T, size_t N > class array;
Vectors are sequence containers representing arrays that can change in size.
Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays.
But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.
template < class T, class Alloc = allocator<T> > class vector;
template < class T, class Alloc = allocator<T> > class vector;
template < class Alloc > class vector < bool, Alloc >;
template < class T, class Alloc = allocator<T> > class list;
template < class T, class Alloc = allocator<T> > class forward_list;
template < class T, class Container = deque<T> > class stack;
Priority queues are a type of container adaptors, specifically designed such that its first element is always the greatest of the elements it contains, according to some strict weak ordering criterion.
template < class T, class Container = deque<T> > class queue;
template < class T, class Container = vector<T>,
class Compare = less < typename Container::value_type > > class priority_queue;
template < class T, class Alloc = allocator<T> > class deque;
Multi-sets are containers that store elements following a specific order, and where multiple elements can have equivalent values.
template < class T, class Compare = less<T>, class Alloc = allocator<T> > class set;
template < class T, class Compare = less<T>, class Alloc = allocator<T> > class multiset;
Multi-maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order, and where multiple elements can have equivalent keys.
template < class Key, class T,
class Compare = less<Key>,
class Alloc = allocator < pair < const Key, T > > > class map;
template < class Key, class T,
class Compare = less<Key>,
class Alloc = allocator < pair<const Key, T > > > class multimap;
By David Lu
Competitive Programming - Lecture 1