算法与数据结构

每日一题:A Regular Expression Matcher

赵裕(vimerzhao)
每日一题:A Regular Expression Matcher 选自Beautiful Code第一章:A Regular Expression Matcher。 Task & Background (节选自Beautiful Code) In 1998, Rob Pike and I were writing The Practice of Programming (Addison-Wesley). The last chapter of the book, “Notation,” collected a number of examples where good notation led to better programs and better

每日一题:100 doors

赵裕(vimerzhao)
每日一题:100 doors 选自100 doors - Rosetta Code Task There are 100 doors in a row that are all initially closed.You make 100 passes by the doors.The first time through, visit every door and toggle the door (if the door is closed, open it;if it is open, close it).The second time, only visit every 2nd door(door #2, #4, #6, …),and toggle it.The third time, visit every 3rd door(door #3, #6, #9, …), etc,until you only visit the 100th door. Answer the question: what state are the doors in after the

时间复杂度计算类题目两则

赵裕(vimerzhao)
时间复杂度计算类题目两则 本文记录了两则具有代表性的算法复杂度计算题目。 题目1 分析以下代码的时间复杂度: for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { for (int k = 0; k < j; k++) { // operations } } } 注:以上代码只作示意,未详细

外排序

赵裕(vimerzhao)
外排序 初探如何对大规模数据进行排序。 问题 问题描述很简单,如何对大规模数据进行排序,比如说一个30G的文件。 分析 解决这个问题主要要解决两件事。第一件就是大文件显然无法一次读入内存,所以只能一次读入一部分

数学建模比赛论文的基本结构

赵裕(vimerzhao)
一、常用的三种结构 一 二 三 1.摘要 1.摘要 1.摘要 2.问题重述 2.问题的提出与重述、问题的分析 2.问题的叙述、背景的分析 3.问题的分析 3.变量假设 3.模型的假设、符号说明 4.模型假设 4.模型建立 4.模型

poj3484 Showstopper 二分

赵裕(vimerzhao)
题目地址 二分用的很是巧妙!关键是抽象出问题本质。 1 #include <cstdio> 2 #include <string> 3 #include <cstring> 4 const int maxn = 100000; 5 #define ull unsigned long long 6 ull X[maxn], Y[maxn], Z[maxn], C[maxn]; 7 ull N; 8 ull judge(const ull &mid) { 9 ull sum = 0; 10 for (int i = 0; i < N; i++) { 11 if (mid >= Y[i]) { 12 sum += C[i]; 13 } else if (mid >= X[i]) { 14 sum += ((mid-X[i])/Z[i]+1); 15 }

UVA1555-- Garland(推导+二分)

赵裕(vimerzhao)
题意:有n个灯,给定第一盏灯A的高度,接下去每盏灯的高度按照公式计算,求使所有灯都不会落在地上(允许碰触)的B的最低高度。 uva 输出 double 用 %f,这一波坑的! 1 #include <cstdio> 2 int n; 3 double A, B, a[1005]; 4 //h2的值 5 bool check(double x) { 6 a[2]

POJ 3662 Telephone Lines(二分+最短路)

赵裕(vimerzhao)
查看题目 最小化第K大值。 让我怀疑人生的一题目,我有这么笨? 1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <vector> 5 #include <functional> 6 using namespace std; 7 #define maxv 1010 8 #define maxl 1000000 9 struct edge 10 { 11 int to, cost; 12 edge(){} 13 edge(int to, int cost) : to(to), cost(cost){} 14 }; 15 typedef pair<int, int> P; 16 vector<edge> G[maxv]; 17 int d[maxv]; 18 int V, E; 19 int dij(int s, int x) { 20