Skip to content

Instantly share code, notes, and snippets.

View soulmachine's full-sized avatar

Frank Dai soulmachine

View GitHub Profile
/**
* https://www.hackerrank.com/challenges/pairs
*/
object Solution {
def main(args: Array[String]): Unit = {
val (n, k) = readNK(readLine())
val numbers = readNumbers(readLine())
var answer = 0
@soulmachine
soulmachine / heap.c
Last active December 16, 2015 13:19
堆的纯C实现,按照正常工程中的标准,不透明结构体,例如 apache apr中用的都是不透明结构体
/** @file heap.c
* @brief 小根堆.
* @author soulmachine@gmail.com
* @date 2010-8-1
* @version 0.1
* @note 小根堆的源代码文件
*/
#include "heap.h"
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcpy() */
/** @file single_list.c
* @brief 单链表
* @author soulmachine@gmail.com
* @date 2010-7-30
* @version 0.1
* @note 单链表的源文件
*/
#include <stdlib.h>
#include "single_list.h"
/** @file stack.c
* @brief 栈.
* @author soulmachine@gmail.com
* @date 2010-7-31
* @version 0.1
* @note 栈的源代码文件
*/
#include "stack.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define QUEENS 8 // 皇后的个数,也是棋盘的长和宽
static int total = 0; // 可行解的总数
static int C[QUEENS] = {0}; // C[i]表示第i行皇后所在的列编号
/**
* @brief 输出所有可行的棋局,按行打印.
@soulmachine
soulmachine / queue.c
Last active December 16, 2015 13:19
队列
/** @file queue.c
* @brief 队列.
* @author soulmachine@gmail.com
* @date 2010-7-30
* @version 0.1
* @note 实现了一个循环队列
*/
#include "queue.h"
#include <malloc.h> /* for malloc(), free() */
#include <string.h> /* for memcpy() */
@soulmachine
soulmachine / config.h
Created April 23, 2013 03:44
写纯C代码时用的公共头文件
/** @file config.h
* @brief 公共头文件
* @author soulmachine@gmail.com
* @date 2010-8-3
* @version 0.1
* @note 无
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
@soulmachine
soulmachine / POJ3253.cpp
Last active December 16, 2015 13:58
POJ 3253 - Fence Repair,http://poj.org/problem?id=3253
// POJ 3253 - Fence Repair,http://poj.org/problem?id=3253
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int64;
int main() {
int n;
@soulmachine
soulmachine / stone_merge.c
Last active December 20, 2015 21:09
WIKIOI 2298 石子合并, http://www.wikioi.com/problem/2298/ POJ 1738 An old Stone Game, http://poj.org/problem?id=1738
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
int N; /** 石头堆的个数. */
int *p; /** 第i堆石头的个数p[i]. */
int **d; /** 状态,d[i][j]表示合并第i堆到第j堆之间的石头的最小得分. */
int *S; /** S[i]表示从第0堆到第i堆的石头总数. */
@soulmachine
soulmachine / stone_merge.c
Created August 10, 2013 08:32
WIKIOI 2298 石子合并, http://www.wikioi.com/problem/2298/ POJ 1738 An old Stone Game, http://poj.org/problem?id=1738 Garsia-Wachs算法
#include <stdio.h>
#define MAXN 55555
int N, A[MAXN]; /* 堆数,每堆的石头个数 */
int num, result; /* 数组实际长度,结果 */
void combine(int k) { /* 前提 A[k-1] < A[k+1] */
int i, j;
/* 合并 k-1和k */