2017.5.1日的总结

来源:互联网 发布:vivo手机虚拟网络设置 编辑:程序博客网 时间:2024/05/21 20:22

2017 5.1
noip2013 day2 的题
再回首【现在看到这三个字都不好了
上次写博客俨然是上个世纪的事了……实在觉得自己刚不出第三题的正解,所以干脆来写博客了。
1。积木大赛
这道题真的超级坑!!!其实挺简单的,然而考试的时候把题目读错了……【最近怎么老干这种事 心累 所以导致全部WA掉了。。。
以后一定要更认真一点,谨记氢氟酸的教导,老老实实读题
还是心累
真的超级简单【好多年没写过这么短的代码了】

#include<cstdio>using namespace std;int const N = 100010;int n;int h[N];int tot=0;int main(){    freopen("block.in","r",stdin);    freopen("block.out","w",stdout);    scanf("%d",&n);    scanf("%d",&h[1]);    tot=h[1];    for(int i=2;i<=n;i++){        scanf("%d",&h[i]);        if(h[i]>h[i-1]) tot+=h[i]-h[i-1];    }    printf("%d",tot);    return 0;}

第2题 花匠
当时想的是dp【而且最开始还特别脑残地想的区间dp 好奇自己的脑回路】结果不仅想的复杂了,而且还过不完点,心累。。。正解其实也非常简单
【但考试的时候就是没想到】
【就是它们最后排列的方式是山峰【或者锯齿状?】这样立一个flag 记录下每次转折的位置,线性O(n)的复杂度来扫一遍,最后输入ans就可】
【居然没有把考试时候写的dp代码保存下来】
【考试时大概是分奇偶存最大值,然后再判断】

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int const N = 100010;int n;int h[N];int ans=0;int main(){    freopen("flower.in","r",stdin);    freopen("flower.out","w",stdout);    scanf("%d",&n);    int flag=-1;    for(int i=1;i<=n;i++){        scanf("%d",&h[i]);        if(i!=1&&h[i]>h[i-1]&&flag!=0){//flag 为 0 表示上升             ans++;            flag=0;        }        if(i!=1&&h[i]<h[i-1]&&flag!=1){            ans++;            flag=1;        }    }    printf("%d",ans+1);    return 0;}

【代码也很短】

3。华容道
【总感觉我似乎玩过这个游戏,考试的时候对样例各种亲切】
【扯远了。。。】
【这道题就是拿来拉高平均代码量的口亨】
正解似乎是先bfs再spfa
然而蒟蒻的我连暴力的bfs都茫然。。。所以。。。
先附上暴力代码吧【大概能过60分】

#include<cstdio>#include<cstring>#define ms(x,y) memset(x,y,sizeof(x))using namespace std;int const N = 35;int const M = 100010;int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};int n,m,q;int a[N][N];int ex,ey,sx,sy,tx,ty;int state[M][4],father[M],tot=0;bool vis[N][N][N][N];void search(int x){    if(father[x]==0) return;    else search(father[x]);    tot++;}void bfs(){    int h=0,tail=1;    state[1][0]=ex,state[1][1]=ey;    state[1][2]=sx,state[1][3]=sy;    do{        h++;        for(int i=0;i<4;i++){            int x=state[h][2],y=state[h][3];            int kx=state[h][0]+dx[i],ky=state[h][1]+dy[i];            if(x==kx&&y==ky){                x=state[h][0],y=state[h][1];            }            if(x>=1&&y>=1&&x<=n&&y<=m&&kx>=1&&ky>=1&&kx<=n&&ky<=m&&a[kx][ky]!=0&&vis[kx][ky][x][y]==false){                vis[kx][ky][x][y]=true;                tail++;                state[tail][0]=kx;state[tail][1]=ky;                state[tail][2]=x;state[tail][3]=y;                father[tail]=h;                if(x==tx&&y==ty){                    search(tail);                    printf("%d\n",tot);                    return ;                }            }        }    }    while(h<tail);    printf("-1\n");}void update(){    ms(state,0);ms(vis,0);ms(father,0);tot=0;}int main(){    freopen("puzzle.in","r",stdin);    freopen("puzzle.out","w",stdout);    scanf("%d%d%d",&n,&m,&q);    for(int i=1;i<=n;i++)        for(int j=1;j<=m;j++)           scanf("%d",&a[i][j]);    if(q<=10){       while(q--){          update();          scanf("%d%d",&ex,&ey);          scanf("%d%d",&sx,&sy);          scanf("%d%d",&tx,&ty);          if(sx==tx&&sy==ty) printf("0\n");          else bfs();       }    }    else{        while(q--){           printf("-1\n");        }    }    return 0;}

有时间信息课再来刚正解,可以把最后一道题单独写一篇博客。。
【主要自己的博客数太少了,而且刚才通读了一遍好水啊。。。】
【这篇大概是不算注释外字数最多的一篇了】

0 0
原创粉丝点击