Skip to content

Instantly share code, notes, and snippets.

@amoshyc
amoshyc / uva11946.c
Last active August 29, 2015 14:11
uva11946.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int T;
scanf("%d\n", &T);
const char* map = "OIZEASGTBP";
@amoshyc
amoshyc / uva11356.c
Created December 8, 2014 16:34
uva11356.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* month[13] = {"", "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};
int is_leap_year(int year) {
if (year % 400 == 0)
return 1;
@amoshyc
amoshyc / DS_project5.md
Last active August 29, 2015 14:11
DS Project 5

DS Project 5: simple line editor (sled)

Suppose program name is sled and myfile.txt is a text file.
After the "myfile.txt" has been read in the memory and the data structure built, the program
will enter interactive mode by prompting '>' to let user enter commands. The program should
print '>' for prompting after the execution of each command.
> l
This is the first line.
@amoshyc
amoshyc / uva541.c
Created December 15, 2014 10:16
uva541.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int N;
while (scanf("%d", &N)) {
if (N == 0) break;
int row_sum[N];
@amoshyc
amoshyc / uva10706.c
Created December 18, 2014 09:29
uva10706.c (can be optimized by binary search)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
long long J[31268+1];
char S[145234+1];
int s_idx;
void init() {
@amoshyc
amoshyc / uva884.c
Created December 18, 2014 10:46
uva884.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int primes[168] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
@amoshyc
amoshyc / Combations.md
Last active August 29, 2015 14:12
Tutorial of finding all the C(n, m) combinations of an array

#組合

如何找出 C(N, M) (C N 取 M)的所有組合,我們的工具有 next_permutation ,但它只能用來做排列,所以我們需要一點小技巧。

考慮資料是 [4, 3, 6, 2, 1] 。我們想找出 C(5, 2) 的所有組合,我們可以設一個長度為 5 的零一陣列,其中前三項為 0 ,後二項為 1

[0, 0, 0, 1, 1]
@amoshyc
amoshyc / poker.c
Last active August 29, 2015 14:12
TODO: Test, AI
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include <unistd.h> // for sleep()
int min(const int a, const int b) {
return ((a > b) ? b : a);
}
@amoshyc
amoshyc / poj2431.md
Last active August 29, 2015 14:12
poj2431

Poj 2431

題目

卡車行駛在長度為 L 公里的道路上,一開始卡車有 P 公升的汽油。 汽油每一公升只能跑一公里,一旦汽油變為 0 ,卡車就會停下。 道路途中有 N 個加油站,分別位於 A[i] 處,加油量為 B[i]。 卡車的油箱大小沒有上限,請問卡車能行駛完道路嗎? 若不行,請輸出 -1;若可以,請輸出最少的加油次數。 ※ 假設 A[i] 是距起點的距離。

@amoshyc
amoshyc / explosion.md
Created January 8, 2015 02:22
大一程式實習課題目 Jan. 5 & 7, 2015

題目

Write a program to calculate the damage of a bomb explosion. We assume that when a bomb explodes, it will create an N by N square explosion around its center. In addition, an N by N explosion will create four smaller N/2 by N/2 explosions around its boundary. The four new explosions will be next to the original explosion, and align with the original explosion at the midpoints of the four sides. Please refer to the following figure for an illustration. This "chain-reaction" explosion will stop when the size of explosion is no more than 2. Explosion causes damage. If a location (x, y) is within or at the boundary of an N by N explosion, it will sustain N damage. If a location (x, y) is within multiple explosions,