Astar Round2B

来源:互联网 发布:plc编程实例 编辑:程序博客网 时间:2024/05/16 07:22

放在前面..

傻逼呵呵还继续做百度之星..


比赛感悟啦啦啦..

因为上一场傻逼呵呵rank610.. 所以这一场还来.. 说实话还是很想要T恤哒..

今天又和HWizard大神一起打啦啦啦.. 照样的naive啊..

这次服务器没有卡爆啊..

这一次全部题都先看一遍.. 以免像上一场一样最水的1003还没看就炸了..

一看,这场1003好像也挺水的.. 找规律嘛.. 然后就进入乱来找规律的time了.. 找着找着,就听到了HWizard来了一句,杨辉三角!然后一看我的规律表,对啊杨辉三角..

10min后第一次提交.. WA了.. 检查代码.. 我擦算错了,改啊改.. 改对了..

又浏览一次题目.. 哎1006不是原题吗.. 好像某次在某牛做过诶.. 只是数据大了点5000.. 码代码,自信提交.. 我擦这数据怎么改8000了啊.. 啊改改改.. AC了..

继续看题.. 群上说1005是普及水平题.. ahhh来算算.. 哎贪心一下好像行的样子.. 继续码代码..

10min后提交.. WA.. 改long long再交.. 还WA.. 卧槽这什么鬼.. 这个做法绝对没错啊.. 哎不对.. 这个freopen是smg.. AC了.. 成功罚了2次时..

看了一下排名.. rank25.. 好开森..

剩下1h了.. 看下别的题.. 没思路.. 教一下wohenshuai1005

啊啊啊别的题都不会啊.. 算了死磕1001..

参考了下省队队长的想法.. 好像有道理.. 开始码代码..

15min后打完.. 就要结束了啊!! 交交交!!

还是超时了.. 没交成功.. 后面在hdu官网交了.. AC了.. 就差那么点啊!!

最后rank90.. 还算好吧.. 起码比上一场好.. rating又涨了.. 成功紫名.. rp--


题解一发..

1001

省队队长的题解:
1

我觉得讲的很清晰.. 补充一下就是找第一个比它大(小)的时候就是把这个当做最大(小)值..

code

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#define LL long longusing namespace std;const LL Maxn = 110000;LL mx[Maxn], mn[Maxn];LL n;LL a[Maxn];LL ans[Maxn];LL _min ( LL x, LL y ){ return x < y ? x : y; }LL _max ( LL x, LL y ){ return x > y ? x : y; }int main (){    LL i, j, k;    while ( scanf ( "%I64d", &n ) != EOF ){        for ( i = 1; i <= n; i ++ ) scanf ( "%I64d", &a[i] );        for ( i = 1; i <= n; i ++ ){            mx[i] = mn[i] = n+1;            for ( j = i+1; j <= n; j ++ ){                if ( a[j] < a[i] ){                    mn[i] = j;                    break;                }            }            for ( j = i+1; j <= n; j ++ ){                if ( a[j] > a[i] ){                    mx[i] = j;                    break;                }            }        }        memset ( ans, 0, sizeof (ans) );        for ( i = 1; i <= n; i ++ ){            LL mmx = i, mmn = i;            while ( mx[mmx] != n+1 || mn[mmn] != n+1 ){                LL tmp = _min ( mx[mmx], mn[mmn] );                ans[tmp-i] = _max ( ans[tmp-i], a[mmx]*a[mmn] );                if ( mx[mmx] == tmp ) mmx = mx[mmx];                else mmn = mn[mmn];            }            ans[n-i+1] = _max ( ans[n-i+1], a[mmx]*a[mmn] );        }        for ( i = n; i >= 1; i -- ) ans[i] = _max ( ans[i], ans[i+1] );        for ( i = 1; i <= n; i ++ ) printf ( "%I64d\n", ans[i] );    }    return 0;}

1002

暂时还不会..

1003

推一下dp数组..

1 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 2 3 4 5 6 0 1 3 6 10 15 21 0 1 4 10 20 35 56 0 1 5 15 35 70 126 0 1 6 21 56 126 252

可以看出f[i][j]=f[i-1][j]+f[i][j-1].. 很符合杨辉三角的特性啊..

那么答案就是(n+m4n2),来个逆元就好啦..

code

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#define LL long longusing namespace std;const LL Mod = 1000000007;LL n, m;LL A, B, X, Y;LL exgcd ( LL a, LL b, LL &x, LL &y ){    if ( a == 0 ){        x = 0; y = 1;        return b;    }    LL fx, fy;    LL d = exgcd ( b%a, a, fx, fy );    y = fx;    x = fy-(b/a)*fx;    return d;}LL ant ( LL x ){    A = x;    B = Mod;    LL d = exgcd ( A, B, X, Y );    return (X%B+B)%B;}LL C ( LL x, LL y ){    LL fz = 1;    LL i;    for ( i = y; i >= y-x+1; i -- ) fz = (fz*i)%Mod;    for ( i = 1; i <= x; i ++ ) fz = (fz*ant(i))%Mod;    return fz;}int main (){    LL i, j, k;    while ( scanf ( "%I64d%I64d", &n, &m ) != EOF ){        n --; m --;        printf ( "%I64d\n", C ( n-1, n+m-2 ) );    }    return 0;}

1004

暂时还不会做..

1005

首先我们先把这些区间按照左端点排个序,那么我们就可以很容易算出某k段区间的左端点了,那么只要在这些区间中找一个最左的右端点作为这k段区间的右端点.. 那么当当前存的区间数大于k时,就把右端点最靠左的给扔出去.. 这东西用堆维护就好啦..

code

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#define LL long longusing namespace std;const LL Maxn = 110000;struct node {    LL l, r;}list[Maxn];LL a[Maxn], s[Maxn];LL n, K, m;bool cmp ( node x, node y ){    if ( x.l != y.l ) return x.l < y.l;    return x.r < y.r;}priority_queue < LL, vector<LL>, greater<LL> > q;LL _max ( LL x, LL y ){ return x > y ? x : y; }int main (){    LL i, j, k;    while ( scanf ( "%I64d%I64d%I64d", &n, &K, &m ) != EOF ){        s[0] = 0;        for ( i = 1; i <= n; i ++ ){            scanf ( "%I64d", &a[i] );            s[i] = s[i-1]+a[i];        }        for ( i = 1; i <= m; i ++ ) scanf ( "%I64d%I64d", &list[i].l, &list[i].r );        sort ( list+1, list+m+1, cmp );        while ( !q.empty () ) q.pop ();        LL ans = 0;        for ( i = 1; i <= m; i ++ ){            q.push (list[i].r);            if ( i > K ) q.pop ();            if ( i >= K ){                LL r = q.top ();                ans = _max ( ans, s[r]-s[list[i].l-1] );            }        }        printf ( "%I64d\n", ans );    }    return 0;}

1006

对于当前某一个数a[i],我们把整个数列比它大的标为1,比它小的标为-1,那么符合条件的区间即为区间和为0的..

那么就根据这个就算咯.. 啦啦啦..

code

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>using namespace std;const int Maxn = 17000;int sum[Maxn], a[Maxn];int n, ans[Maxn];int main (){    int i, j, k;    while ( scanf ( "%d", &n ) != EOF ){        for ( i = 1; i <= n; i ++ ){            scanf ( "%d", &a[i] );        }        for ( i = 1; i <= n; i ++ ){            memset ( sum, 0, sizeof (sum) );            int s = 0;            for ( j = i; j <= n; j ++ ){                if ( a[j] > a[i] ) s ++;                else if ( a[j] < a[i] ) s --;                sum[s+8000] ++;            }            ans[i] = 0;            s = 0;            for ( j = i; j >= 1; j -- ){                if ( a[j] > a[i] ) s ++;                else if ( a[j] < a[i] ) s --;                ans[i] += sum[8000-s];            }        }        for ( i = 1; i < n; i ++ ) printf ( "%d ", ans[i] );        printf ( "%d\n", ans[n] );    }    return 0;}

最后再说几句..

那么这场比赛还是挺好的.. 但还是有很多地方自己做的不好(比如说对随机数据的处理).. 还需要继续做多点题多积累点经验啊..

啦啦啦.. rank90还是很开森的..

0 0
原创粉丝点击