USACO2.2 Data Structure&Dynamic Programming&读书笔记

26 篇文章 0 订阅

Data Structure
Dynamic Programing

tree

> 或许可以random数据后再输入

hash

> NHASH to be prime.

tries

> 当对pre询问要求较高时候,考虑trie
> 当结尾相似时候,可以使用``special'' nodes
> It sometimes helps to keep the linked list of children in sorted order. This increases the time to build the trie, but decreases the time to search it.

heap

A heap makes it very easy to ask the question “What’s the smallest thing?” in a collection of dynamic values. It’s a compact representation and quick to compute. An example of a location where this can be helpful is Dijkstra’s algorithm.

  • 如果树几乎是满的,可以考虑数组存储

    In this representation, the children of the node at position x are 2x and 2x+1 (assuming 1 based indexing), and the parent of x is truncate(x/2).

  • 1

notes

  • Can I Debug It?
    • What makes a data structure easy to debug? That is basically determined by the following two properties.
      • State Is Easy To Examine
        • The smaller
        • more compact the representation
        • statically allocated arrays
      • State can Be Displayed
        • to write a small routine to output the data.
        • structures like trees and graphs are going to be difficult to examine.
  • Conclusion

    正确比逼格更重要.

  • Starting At The End

  • 最长下降子序列:存一个数组保持到某个数为止,长n的最大值

罗马数字递推

写个add函数..递归处理
然后…为什么4A呢…….
因为一排else if 中间有一个写成了if
因为/逻辑写成了%…

Sublime Text 无敌棒
觉得本应该用前10甚至前100的数组来直接优化速度的

另外..本来想发邮件问rob的

BTW,I have a question that i cannot use

 enum pre{'I','V','X','L','C','D','M'};

to describe the numbers

然后发现两种解决方案:
1. map类映射函数,处理符号成对应数字.
2. 开大点数组= =

subset

好开心..这道纠结一个星期(其实是因为莫名其妙的优先队列看别的东西去了的)题.在周日发现是一道背包.然后过了
long long WA一次
DP的核心是寻找子问题是什么,可以通过观察上一步已知寻找子问题

runround

纯模拟……居然5A也是有点醉…
话说每一次tos不如模拟进位快..

lamp

点灯,注意最多也就十几种情况..动两次等于没动
又是一道爆搜题QAQ一开始没去重..

void dfs(int beg,int cent){
    if (cent==tottrans||cent==tottrans-2||cent==tottrans-4) {
        test();
    }//多个test条件需要去重...
    if (beg<4&&cent<tottrans) {
        trans[beg]=true;
        dfs(beg+1, cent+1);
        trans[beg]=false;
        dfs(beg+1, cent);
    }
}

然后令人惊喜而且没发现的是可以只考虑前六盏
然后就可以愉快位运算了~!!

#define MAXLAMP 6
#define LAMPMASK    ((1<<MAXLAMP)-1)

int flip[4] = {
    LAMPMASK,       /* flip all lights */
    LAMPMASK & 0xAA,    /* flip odd lights */
    LAMPMASK & 0x55,    /* flip even lights */
    LAMPMASK & ((1<<(MAXLAMP-1))|(1<<(MAXLAMP-4)))  /* lights 1, 4 */
};

for(i=0; i<nlamp; i++)
    s[i] = (lights & (1<<(MAXLAMP-1 - i%MAXLAMP))) ? '1' : '0';
    s[nlamp] = '\0';
    fprintf(fout, "%s\n", s);

数据结构与算法分析读书笔记

  • 联机算法.(可以边读入边处理)
  • for二层循环是n*n算O时候算平方因子
  • while 循环消除尾递归(但是并查集里边这样就实现不了路径压缩了)
  • queue防止右溢可以循环数组
List ReverseList( List L ) 
{
    Position CurrentPos, NextPos, PreviousPos;
    PreviousPos = NULL;
    CurrentPos = L;
    NextPos = L->Next; 
    //remember where cur->next will be next 
    //because cur->next will be changed to reversed ordering 
    while( NextPos != NULL ) {
        CurrentPos->Next = PreviousPos; 
        PreviousPos = CurrentPos; 
        CurrentPos = NextPos;   
        NextPos = NextPos->Next;
    }
    CurrentPos->Next = PreviousPos;
    return CurrentPos;
}
  • lazy deletion
  • h
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值