USACO3.1 天梯-.-

26 篇文章 0 订阅

agrinet

krustra+并查过的..既然贪心,所以优先队列…

struct cmp{
    bool operator()(int& a,int& b){
        return a>b;
    }
};
struct path{
    int fr,to;
    int dis;
    bool operator<(const path &b)const{
        return dis>b.dis;
    }
}temp;
priority_queue<int,vector<int>,cmp>tmep;
priority_queue<path>pq;

尽管题解是这么说的…

Since the tree sizes are small enough, we don’t need any complicated data structures: we just consider every node each time.

inflate

完全背包,扫两遍就完了…注意扫的时候max

但是没想到的是

The array is always nondecreasing, so we simply output the last element of the array.

*humble

可怕..

第n个生成数 写出来最暴力算法(跪在第五个数据)后去nocow看题解

16A..

然后回来发现 官方题解居然也几乎是最暴力的

有一点概率算法的感觉 和OJ在拼空间和时间=.=

题目大概是 用set来得到第n个数(这样大概是O(n2))的感觉,但是要加一个优化,防止爆空间,加一点优化,防止溢出.(居然可以用double……).

不用set加一个数组保持每一次扫每一个质数只判一次

*contact

第一位补1的二进制hashnocow

/*边读边处理真是精彩*/
while((c = getc(fin)) != EOF) {
    if(c != '0' && c != '1')
        continue;

    bit <<= 1;
    if(c == '1')
        bit |= 1;

    if(nbit < b)
        nbit++;

    for(i=a; i<=nbit; i++)
        addseq(bit, i);
    }

/* increment the count for the n-bit sequence "bits" */
void
addseq(unsigned bits, int n)
{
    bits &= (1<<n)-1;
    bits |= 1<<n;
    assert(seq[bits].bits == bits);
    seq[bits].count++;
}

/* print the bit sequence, decoding the 1<<n stuff */
/* recurse to print the bits most significant bit first */
void
printbits(FILE *fout, unsigned bits)
{
    assert(bits >= 1);
    if(bits == 1)   /* zero-bit sequence */
    return;

    printbits(fout, bits>>1);
    fprintf(fout, "%d", bits&1);
}

*stamps

疑似多重背包 暴力做挂在第十个数据

缘由没有实践递推的思想,太多次扫整个数组了 要么爆空间,要么会爆时间

所以关键是降低每一个数的扩展或被扩展次数

方法是对每一个到达的数扩展一位

官方题解也是每次扩展一位 只是循环的顺序不同 需要初始化为inf

也可以这样

for (i=1;i<=2000000;i++)
    {
        f[i]=BIGNUM;
        for (j=0;j<m;j++)
            if (a[j]<=i) f[i]=min(f[i],f[i-a[j]]+1);
        if (f[i]>n) break;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值