
算法&数据结构
文章平均质量分 83
CSLDBLYDX
这个作者很懒,什么都没留下…
展开
-
uva 11078 Open Credit System
#include #include #include #include using namespace std;const int MAX = 100000+5; const int MIN = -32767;int a[MAX];int main(int argc, char *argv[]){ int t,n; scanf("%d",&t);原创 2014-04-30 16:36:57 · 409 阅读 · 0 评论 -
poj 3141Distant Galaxy
#include #include #include #include using namespace std;const int MAX = 100+5;struct P{ int x,y; bool operator <(const P& point) const { return x < point.x; }原创 2014-07-22 20:54:19 · 604 阅读 · 0 评论 -
uva10755 - Garbage Heap
#include #include #include #define FOR(i,s,t) for(int i = ( s); i < (t); i++)#define max(i,j) (i > j ? i : j)#define min(i,j) (i < j ? i : j)using namespace std;const int MAX = 20 + 3; cons原创 2014-07-24 00:09:01 · 482 阅读 · 0 评论 -
素数筛选法
用高效的方法筛选小于n的素数原创 2014-07-11 20:06:47 · 355 阅读 · 0 评论 -
uva 1197K Smallest Sums
// UVA 1197 K Smallest Sums.cpp: 主项目文件。#include "stdafx.h"#include "stdio.h"#include #include using namespace std;const int MAX = 750+10;struct data{ int sum,x; data(int a, int b):sum(原创 2014-09-16 23:10:11 · 442 阅读 · 0 评论 -
LA 3135 argus
#include #include "stdio.h"#include using namespace std;const int MAX = 1000 +10;struct rgst{ int q_num,t,p; bool operator <(const rgst& r)const { return t == r.t ? q_num > r原创 2014-09-19 22:31:41 · 426 阅读 · 0 评论 -
UVA 1329 corporative NetWork
#include #include "stdio.h"#include #include "string.h"using namespace std;const int MAX = 20000 +10;struct node{ int r,dtr;};void set_r(node *ns,int u,int v){ ns[u].r = ns[v].r;原创 2014-09-20 12:59:27 · 484 阅读 · 0 评论 -
Broken Keyboard (a.k.a. Beiju Text)
#include #include "stdio.h"#include "string"using namespace std;struct chr{ char val; chr *next ;};chr head,*end;int main(){ chr *cur; char c; int flag; while(scanf(原创 2014-09-23 13:22:49 · 494 阅读 · 0 评论 -
UVA 11987 - Almost Union-Find
#include #include "stdio.h"using namespace std;const int MAX = 2000000+10;int r[MAX],id[MAX/2],size[MAX],sum[MAX],cnt;int find_r(int p){ if(r[p] == p)return p; return r[p] = find_r(原创 2014-09-26 21:50:39 · 299 阅读 · 0 评论 -
1401 - Remember the Word
Neal is very curious about combinatorial problems, and now here comes a problem about words. Knowing that Ray has a photographic memory and this may not trouble him, Neal gives it to Jiejie.Since原创 2014-10-28 21:14:35 · 491 阅读 · 0 评论 -
POJ 3630 --Trie
#include #include #include using namespace std;const int PHON_LNG = 10 + 2,MAX_SIZE = 10000 * (10 + 2) + 5,NUMS = 10 + 2;int num[MAX_SIZE][NUMS],val[MAX_SIZE],flag;int size;int idx(char c)原创 2014-10-31 23:04:37 · 370 阅读 · 0 评论 -
UVA11992 - Fast Matrix Operations
#include #include "stdio.h"#include #include const int MAX = 2000000 + 10,MAX_R = 20+5,MAX_SUM = 1000000000 + 10;int set[MAX_R][MAX],add[MAX_R][MAX],sum[MAX_R][MAX],mmax[MAX_R][MAX],mmin[MAX_R][原创 2014-10-17 01:05:37 · 366 阅读 · 0 评论 -
Poj 1964 City Game
City GameTime Limit: 3000MS Memory Limit: 30000KTotal Submissions: 4730 Accepted: 1876DescriptionBob is a strategy game programming specialist. In his new city buil原创 2014-05-26 12:21:32 · 408 阅读 · 0 评论 -
UVA 11729 Commando War
vector 放到循环里,否则每次排序都是在原有的数据基础上。原创 2014-04-13 17:41:34 · 371 阅读 · 0 评论 -
uva 11929The Dragon of Loowater
#include #include #include using namespace std;const int MAX_SIZE=20000;int main(){ int n,m; int heads[MAX_SIZE],soldiers[MAX_SIZE]; while(scanf("%d%d",&n,&m)==2)原创 2014-04-09 21:33:13 · 498 阅读 · 0 评论 -
Poj 3154Graveyard
#include #include #include using namespace std;int main(int argc, char *argv[]){ int n,m; while(scanf("%d%d",&n,&m)!= -1) { double total = 0,pos; for(int i = 1; i原创 2014-04-15 15:55:34 · 534 阅读 · 0 评论 -
Uva10881 Piotr's Ants
#include #include #include #include using namespace std;const int MAX = 10000+5;struct Ant{ int id,pos,dirc; bool operator < (const Ant& a)const { return pos < a.pos; }};int main原创 2014-04-18 12:16:57 · 517 阅读 · 0 评论 -
UVa 11300 Spreading the Wealth
本题是数学题数学题关键在于建立数学模型。 #include #include #include #include using namespace std;const int MAX = 1000000+5;long long p[MAX],c[MAX],sum;int main(int argc, char *argv[]){原创 2014-04-18 20:14:27 · 458 阅读 · 0 评论 -
UVA 11549 Calculator Conundrum
#include #include #include using namespace std;long long m;long long for_ward(int n,long long k,int step){ long long pos = k; long len = 1; for(int i = 1; i < n; i++)len *= 10;原创 2014-05-06 22:09:26 · 450 阅读 · 0 评论 -
Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space? 给定链表,若存在环返回环的起点,否则返回null。 貌似网易面原创 2014-02-19 23:54:56 · 759 阅读 · 0 评论 -
从floyd算法学习动态规划
从floyd算法学习动态规划 2010-06-06 22:402824人阅读评论(1)收藏举报算法语言iniooc floyd的相关概念看这里。 floyd的代码实现其实很简单: [cpp] view plaincopyprint?void floyd() { for(k=0;k f转载 2014-03-22 14:30:52 · 795 阅读 · 0 评论 -
Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 判断链表有环交了两次才AC,判断two==null后应该直接返回false,即two指空应当马上返回false. /** * Definition f原创 2014-02-20 11:43:27 · 618 阅读 · 0 评论 -
Sort List
[思路]就是简单的归并排序。 其实算法还可以优化,因为用链表进行归并,无法像数组那样直接取中间位置,进行遍历获取中间的话效率会降低挺多。可以定义一个全局变量notSortedStart,记录当前的无序位段的起始位,作为right的起点。当串长为1时将notSortedStart 右移,则notSortedStarted记录的是中间位置。只要保证递归的顺序是先左后右,即可保证当前节点一定原创 2014-02-20 18:08:12 · 500 阅读 · 0 评论 -
Uva 1121 Subsequence
#include #include #include #include using namespace std;const int MAX = 100000 + 5; const long MAX_VAL = 1000000000 + 5;long arr[MAX]; int main(int argc, char *argv[]){ int n,s;原创 2014-05-07 20:26:12 · 444 阅读 · 0 评论 -
Poj 2741Colored Cubes(贪心&枚举)
本题属于贪心+枚举;#include #include #include #include #include #include #include using namespace std;const int INF = 24;//int all_rots[24][6]={{3,1,0,5,4,2},{1,2,0,5,3,4},{2,4,0,原创 2014-04-22 16:31:50 · 448 阅读 · 0 评论 -
11384 Help is needed for Dexter
用中位数可证明正确性! #include #include #include using namespace std;long f(long n){ return n == 1? 1: f(n/2) +1;}int main(int argc, char *argv[]){ long n; while(scanf("%ld",&n) !=原创 2014-04-24 12:20:01 · 543 阅读 · 0 评论 -
poj 2418 Hardwood Species--tire
#include #include #include #include using namespace std;const int MAX_SIZE = 1000 * 22,CHARS = 256+ 2,NAME_LEN = 30 + 2;int spc[MAX_SIZE][CHARS],val[MAX_SIZE];int count;int size ,f,r;st原创 2014-11-02 21:22:24 · 336 阅读 · 0 评论