算法
文章平均质量分 67
yllfever
游戏开发程序员,从事3d游戏引擎开发工作,对算法、3d图形学等感兴趣
展开
-
ZOJ 1128
#include #include #include using namespace std;struct Rect{ double up, left, right, bottom; Rect* next; void insert(double u, double l, double r, double b);原创 2008-07-07 11:00:00 · 481 阅读 · 0 评论 -
ZOJ 1025 Wooden sticks
#include #include using namespace std;struct node{ int len, wt; node* nxt;};node* list=NULL;void Insert(node* lst, int l, int w){原创 2008-06-24 14:23:00 · 564 阅读 · 0 评论 -
zoj1028 图
原创 2008-06-25 09:32:00 · 482 阅读 · 0 评论 -
zoj 1028 Flip and Shift
/**证明: 首先, 若n为奇数,则必然可以完成任务 将n个球遍号为1,2,...,n 若从1位置开始,进行 n-1次连续的 (flip, shift, shift), 则 除了球1外, 所有球的位置都 减了2, 而球1最后到达原来球n-1的位置。(见图, 可以知道, 相当于交换球1和2的位置)原创 2008-06-25 09:21:00 · 1342 阅读 · 0 评论 -
zoj 1111 Poker Hands
#include #include using namespace std;struct Card{ char type; int value; Card* next;};void Insert(Card* hand, Card* c){ Card* p =原创 2008-07-01 17:31:00 · 679 阅读 · 0 评论 -
zoj 1711 Sum It Up
#include #include #include using namespace std;struct Num{ int v, q;}num[12];int t, n;int qty[12];int cnt, j;void Test(int p){ if (p =原创 2008-07-03 13:38:00 · 455 阅读 · 0 评论 -
zoj1119 SPF
#include #include #include #include using namespace std;struct Edge{ int to; Edge*next; void insert(Edge* e) { e->nex原创 2008-07-04 11:10:00 · 753 阅读 · 1 评论 -
ZOJ 1102 Phylogenetic Trees Inherited (My algorithm , Time limit exeeded)
#include #include using namespace std;int n, l;string s[1025];int cnt[1025][26];string result;inline bool input(){ cin>>n>>l; if ( !n && !l ) return false; for原创 2008-10-30 10:09:00 · 774 阅读 · 0 评论 -
zoj 1095 Humble Numbers
#include #include using namespace std;const int factors[] = { 2, 3, 5, 7 };const int m = 2000000000;const int mm[] = { m/2, m/3, m/5, m/7 };const char* st = "st", *nd = "nd", *rd =原创 2008-10-31 12:41:00 · 599 阅读 · 0 评论 -
POJ1097 Roads Scholar
#include #include #include #include using namespace std;const int MAXN = 30;const int MAXDIST = 100000000;int distanc[MAXN][MAXN];//从交点a到b的最短距离 int dist[MAXN][MAXN];//从原创 2009-01-08 12:45:00 · 1096 阅读 · 0 评论 -
google codejam 2008 APAC local onsites , Problem A What are Birds?
题目在这里http://code.google.com/codejam/contest/dashboard?c=32005# 这题先把问题转化一下, 相当于: 在平面上有一个矩形, 现在知道有一些点于这个矩形的关系。 请根据这些信息, 判断能否确定另一些点与这个矩形的关系 代码如下: #include #include #include using原创 2009-08-28 13:08:00 · 490 阅读 · 0 评论 -
计算 高次幂相对某个模数的余( (a ^ n)mod p, n 很大 )
在做google codejam 2008 round 1A problem C 的 时候, 从别人代码里学到的 假如 要计算 (a ^ n) , n很大, 直接计算的话, 是个 O(n)的方法有 O(log (n))的方法,如下: 把n表示成2进制, n = n0 * 1 + n1 * 2 + n2 * 4 + ... + nk * (2^k)则 a^n =[原创 2009-09-10 13:27:00 · 1154 阅读 · 1 评论 -
ZOJ 1093 Monkey and banana
#include #include #define MAXN 30#define MAX(a, b) a>b?a:b#define MIN(a, b) a>b?b:ausing namespace std;struct Block{ int w, l, h;}blks[3*MAXN];int n;原创 2008-06-24 12:54:00 · 740 阅读 · 0 评论 -
ZOJ 1039 尚未解决
#include #include #include #define MAX (1024*512)using namespace std;int BIT[19];int win[MAX];void PrintBit(int a){ int k = 1; for原创 2008-06-20 11:25:00 · 460 阅读 · 0 评论 -
Google code jam 2008 beta B The Price is Wrong
#include #include #include #include #include using namespace std;struct Prod{ char name[30]; int id;}prod[64], temp[64];int ord[64];int pric原创 2008-07-10 09:32:00 · 537 阅读 · 0 评论 -
zoj 1134
#include #include #include #include using namespace std;struct node{ vector children; int name; int mSoldiers[2]; int getMin(int i);} no原创 2008-07-10 14:03:00 · 413 阅读 · 0 评论 -
zoj 1144 Robbery
#include #include using namespace std;int a[100][100][100];int b[100];int bx[100], by[100];int W, H, T;int main(int argc, char *argv[]){ int n;原创 2008-07-11 14:07:00 · 670 阅读 · 0 评论 -
Google code jam 2008 beta A Triangle Trilemma
#include #include #define X 0#define Y 1using namespace std;typedef int pointi[2];int AreaSign(pointi a, pointi b, pointi c){ double x1 = b[X]-a[X], x2 = c[X]-a[原创 2008-07-09 08:51:00 · 456 阅读 · 0 评论 -
zoj1301 The New Villa
The New VillaTime limit: 1 Seconds Memory limit: 32768K Special JudgeTotal Submit: 1036 Accepted Submit: 331 Mr. Black recently bought a villa in the countryside. Only one thing原创 2008-07-25 08:35:00 · 583 阅读 · 0 评论 -
zoj1155 triangle war
/**DP 对状态编号, 18条边, 每条边可能实线, 也可能虚线, 有2^18种MaxScore(x) = max { StepScore(rCode, selectedEdgeNum) > 0 ? StepScore + MaxScore(rCode) //选择的边成三角行原创 2008-08-01 17:23:00 · 918 阅读 · 0 评论 -
zoj 1166 Anagram Checker
/**A seach problem.**/#include #include #include #include #include using namespace std;/**dictionary words**/string word[2000];/**Word in phrase**/string swo原创 2008-08-07 10:23:00 · 799 阅读 · 0 评论 -
zoj1163 The Staircases 解法1 O(n^3)
#include #include using namespace std;int main(int argc, char *argv[]){ long long a[501][501], b[501]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (int原创 2008-08-06 11:33:00 · 712 阅读 · 5 评论 -
zoj 1038 T9 mobile input method
#include #include #include using namespace std;struct Key{ int num; char ch[4];};const Key keys[10] = { {}, {}, {3, {a, b,原创 2008-06-17 13:20:00 · 794 阅读 · 0 评论 -
zoj1014 不使用表达式树 ac
#include #include using namespace std;void getSubExpr( const string& expr, int idx, string& res);int main(){ char name; string expr; string query;原创 2008-06-17 18:02:00 · 453 阅读 · 0 评论 -
zoj 1011NTA
//#include #include #define MAXN 15 #define MAXK 10#define MAXL 10using namespace std;int m, n, k;struct mypair{ int a, b; mypair *next;原创 2008-06-19 15:54:00 · 1403 阅读 · 1 评论 -
Topcoder SRM 505 Div 2 hard
这题解法非常巧妙。最关键的一点是, 先由题目想到这个:要知道整个矩形的面积,必须知道所有 X[i] /X[j]的值,同时也必须知道X[i] * Y[j] (0然后就是用UnionFind来做了原创 2011-09-21 20:37:29 · 405 阅读 · 0 评论