1.并查集求最小生成树

Code:

 #include <stdio.h>
#include <stdlib.h>
 
struct node
{
    long x,y,c;
}road[];
 
long fa[];
 
int cmp(const void *a,const void *b)
{
    if ((*(struct node *)a).c < (*(struct node *)b).c)
        return -;
    else
        return ;
}
 
long getfather(long d)
{
    if (fa[d]==d)
        return d;
    fa[d]=getfather(fa[d]);
    return fa[d];
}
 
int main()
{
    long n,m,t,xx,yy,x,y,i,cnt;
    long long cost=;
    scanf("%ld%ld",&n,&m);
    cnt=n-;
    for (i=;i<=n;i++)
        fa[i]=i;
    for (i=;i<=m;i++)
    {
        scanf("%ld%ld",&x,&y);
        xx=getfather(x);
        yy=getfather(y);
        if (xx!=yy)
        {
            fa[xx]=yy;
            cnt--;
            if (cnt==)
            {
                printf("0\n");
                return ;
            }
        }
 
    }
    scanf("%ld",&t);
    for (i=;i<t;i++)
        scanf("%ld%ld%ld",&road[i].x,&road[i].y,&road[i].c);
    qsort(road,t,sizeof(struct node),cmp);
    for (i=;i<t;i++)
    {
        xx=getfather(road[i].x);
        yy=getfather(road[i].y);
        if (xx!=yy)
        {
            fa[xx]=yy;
            cost+=road[i].c;
            cnt--;
            if (cnt==)
            {
                printf("%lld\n",cost);
                return ;
            }
        }
    }
    printf("-1\n");
    return ;
}

2.点有权值,spfa

 #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
 
struct node
{
    long c;
    struct node *next;
}*city[];
 
long q[],pre[],m;
 
long min(long a,long b)
{
    if (a>b)
        return b;
    else
        return a;
}
 
void print(long d)
{
    if (d!=m)
        print(pre[d]);
    printf("%ld",d);
    if (d!=)
        printf("->");
    else
        printf("\n");
}
 
int main()
{
    long i,j,s,t,b,e,n,ren,g[],head,tail,sum[];
    bool vis[];
    struct node *p;
    scanf("%ld%ld%ld",&n,&m,&ren);
    for (i=;i<=n;i++)
    {
        scanf("%ld",&g[i]);
        scanf("%ld",&s);
        for (j=;j<=s;j++)
        {
            scanf("%ld",&t);
            p=(struct node *) malloc (sizeof(struct node));
            p->c=t;
            p->next=city[i];
            city[i]=p;
        }
    }
    for (i=;i<=n;i++)
    {
        vis[i]=true;
        sum[i]=;
    }
    sum[m]=g[m];
    head=;
    tail=;
    q[]=m;
 
    do
    {
        head=(head+)%;
//        head++;
        b=q[head];
        p=city[b];
        while (p)
        {
            e=p->c;
            if (sum[b]+g[e]<sum[e])
            {
                sum[e]=sum[b]+g[e];
                pre[e]=b;
                if (vis[e])
                {
                    tail=(tail+)%;
//                    tail++;
                    q[tail]=e;
                    vis[e]=false;
                }
            }
            p=p->next;
        }
        vis[b]=true;
    }
    while (head!=tail);
 
    if (sum[]<=ren*)
    {
        print();
        printf("%ld\n",ren-sum[]/);
    }
    else
        printf("No way!");
    return ;
}

3.

地图bfs

U10278 Cx的金字塔 _ 落谷1126机器人搬重物 解题报告

I.哪个是行,哪个是列,行列从哪边开始

II.一次操作

1.前移1,2,3!步

2.转90度

III.边界范围 1~n-1 1~m-1

IV.起始点不可用

V.起始点=终止点

Code:

 #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
 
struct node
{
    long x,y,c,step;
}q[];
 
bool vis[][][];
 
long head,tail,s,t;
 
void add(long x,long y,long c)
{
    tail++;
    q[tail].x=x;
    q[tail].y=y;
    q[tail].c=c;
    q[tail].step=q[head].step+;
    vis[x][y][c]=false;
    if (x==s && y==t)
    {
        printf("%ld\n",q[tail].step);
        exit();
    }
}
 
int main()
{
    long n,m,i,j,k,x,y,c;
    long map[][];
    char ccs,cs;
    scanf("%ld%ld",&n,&m);
    for (i=;i<=n;i++)
        for (j=;j<=m;j++)
            for (k=;k<;k++)
                vis[i][j][k]=true;
 
    for (i=;i<=n;i++)
        for (j=;j<=m;j++)
            scanf("%ld",&map[i][j]);
    scanf("%ld%ld%ld%ld%c%c",&x,&y,&s,&t,&ccs,&cs);
 
    if (x== || x==n || y== || y==m || map[x][y]== || map[x+][y]== || map[x][y+]== || map[x+][y+]==)
    {
        printf("-1");
        return ;
    }
 
    if (x==s && y==t)
    {
        printf("0\n");
        return ;
    }
 
    head=;
    tail=;
    q[].x=x;
    q[].y=y;
    if (cs=='E')
        c=;
    else if (cs=='S')
        c=;
    else if (cs=='W')
        c=;
    else
        c=;
    q[].c=c;
    q[].step=;
    vis[x][y][c]=false;
    //上:0 下:1 左:2 右:3
    head=;
    tail=;
    do
    {
        head++;
        x=q[head].x;
        y=q[head].y;
        c=q[head].c;
        //上
        if (c==)
        {
            if (x> && map[x-][y]== && map[x-][y+]==)
            {
                if (vis[x-][y][c])
                    add(x-,y,c);
                if (x> && map[x-][y]== && map[x-][y+]==)
                {
                    if (vis[x-][y][c])
                        add(x-,y,c);
                    if (x> && map[x-][y]== && map[x-][y+]== && vis[x-][y][c])
                        add(x-,y,c);
                }
            }
        }
        //下
        else if (c==)
        {
            if (x<n- && map[x+][y]== && map[x+][y+]==)
            {
                if (vis[x+][y][c])
                    add(x+,y,c);
                if (x<n- && map[x+][y]== && map[x+][y+]==)
                {
                    if (vis[x+][y][c])
                        add(x+,y,c);
                    if (x<n- && map[x+][y]== && map[x+][y+]== && vis[x+][y][c])
                        add(x+,y,c);
                }
            }
 
        }
        //左
        else if (c==)
        {
            if (y> && map[x][y-]== && map[x+][y-]==)
            {
                if (vis[x][y-][c])
                    add(x,y-,c);
                if (y> && map[x][y-]== && map[x+][y-]==)
                {
                    if (vis[x][y-][c])
                        add(x,y-,c);
                    if (y> && map[x][y-]== && map[x+][y-]== && vis[x][y-][c])
                        add(x,y-,c);
                }
            }
        }
        //右
        else
        {
            if (y<m- && map[x][y+]== && map[x+][y+]==)
            {
                if (vis[x][y+][c])
                    add(x,y+,c);
                if (y<m- && map[x][y+]== && map[x+][y+]==)
                {
                    if (vis[x][y+][c])
                        add(x,y+,c);
                    if (y<m- && map[x][y+]== && map[x+][y+]== && vis[x][y+][c])
                        add(x,y+,c);
                }
            }
        }
        if (c== || c==)
        {
            if (vis[x][y][])
                add(x,y,);
            if (vis[x][y][])
                add(x,y,);
        }
        else
        {
            if (vis[x][y][])
                add(x,y,);
            if (vis[x][y][])
                add(x,y,);
        }
    }
    while (head<tail);
    printf("-1\n");
 
    return ;
}

4.

对于70%的数据:

2<=a<=250

对于100%的数据:

2<=a<=2^60

对于70%的数据:

初始:

现有一个花坛(A坛)装满了白蛇根草,还有两个空花坛(B坛,C坛),

三个花坛共有250*250*250=15625000种

(x,y,z)->其它状态

当有其中两个花坛的数目为|A|/2时结束

by lzu_cgb
share & spread ideas

洛谷_Cx的故事_解题报告_第四题70的更多相关文章

  1. 洛谷 P2317 [HNOI2005]星际贸易 解题报告

    P2317 [HNOI2005]星际贸易 题目描述 输入输出格式 输入格式: 输出格式: 如果可以找到这样的方案,那么输出文件output.txt中包含两个整数X和Y.X表示贸易额,Y表示净利润并且两 ...

  2. 洛谷 P3802 小魔女帕琪 解题报告

    P3802 小魔女帕琪 题目背景 从前有一个聪明的小魔女帕琪,兴趣是狩猎吸血鬼. 帕琪能熟练使用七种属性(金.木.水.火.土.日.月)的魔法,除了能使用这么多种属性魔法外,她还能将两种以上属性组合,从 ...

  3. 洛谷 P2606 [ZJOI2010]排列计数 解题报告

    P2606 [ZJOI2010]排列计数 题目描述 称一个\(1,2,...,N\)的排列\(P_1,P_2...,P_n\)是\(Magic\)的,当且仅当对所以的\(2<=i<=N\) ...

  4. 洛谷1303 A*B Problem 解题报告

    洛谷1303 A*B Problem 本题地址:http://www.luogu.org/problem/show?pid=1303 题目描述 求两数的积. 输入输出格式 输入格式: 两个数 输出格式 ...

  5. 洛谷 P2466 Sue的小球 解题报告

    P2466 [SDOI2008]Sue的小球 题目描述 Sue和Sandy最近迷上了一个电脑游戏,这个游戏的故事发在美丽神秘并且充满刺激的大海上,Sue有一支轻便小巧的小船.然而,Sue的目标并不是当 ...

  6. 洛谷 P1310 表达式的值 解题报告

    P1310 表达式的值 题目描述 对于1 位二进制变量定义两种运算: 运算的优先级是: 先计算括号内的,再计算括号外的. "× "运算优先于"⊕"运算,即计算表 ...

  7. 洛谷 P4292 [WC2010]重建计划 解题报告

    P4292 [WC2010]重建计划 题目描述 \(X\)国遭受了地震的重创, 导致全国的交通近乎瘫痪,重建家园的计划迫在眉睫.\(X\)国由\(N\)个城市组成, 重建小组提出,仅需建立\(N-1\ ...

  8. 洛谷 P3084 [USACO13OPEN]照片Photo 解题报告

    [USACO13OPEN]照片Photo 题目描述 农夫约翰决定给站在一条线上的\(N(1 \le N \le 200,000)\)头奶牛制作一张全家福照片,\(N\)头奶牛编号\(1\)到\(N\) ...

  9. 洛谷 P1379 八数码难题 解题报告

    P1379 八数码难题 题目描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0来表示.空格周围的棋子可以移到空格中.要求解的问题是:给出一种初始布局(初 ...

随机推荐

  1. 汇编 浮点指令FLD,FSTP,FADD与FPU寄存器

    知识点:  浮点数的存放方式  st0至st7  FLD,FST,FADD指令 一.浮点数的存放方式 00401000 /$ 55 PUSH EBP 00401001 |. 8BEC MOV E ...

  2. python 回溯法 子集树模板 系列 —— 12、选排问题

    问题 从n个元素中挑选m个元素进行排列,每个元素最多可重复r次.其中m∈[2,n],r∈[1,m]. 如:从4个元素中挑选3个元素进行排列,每个元素最多可重复r次. 分析 解x的长度是固定的,为m. ...

  3. Nginx日常报错处理总结

    在Nginx错误日志中,有大量的下列信息: Upstream timed out (110: Connection timed out) while reading response header f ...

  4. Flask学习-Flask app接受第一个HTTP请求

    一.__call__() 在Flask app启动后,一旦uwsgi收到来自web server的请求,就会调用后端app,其实此时就是调用app的__call__(environ,start_res ...

  5. 【2017年9月10日更新】ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发

    ABP代码生成器介绍 ABP Code Generator 针对abp这个框架做了一个代码生成器,功能强大.分为两大功能点,一个是数据层,一个是视图层. 数据服务层:通过它,可以实现表设计.领域层初始 ...

  6. Vue全家桶介绍

    一直不清楚全家桶是什么玩意,上网搜了一下,才知道就是平时项目中使用的几个依赖包,下面分享一下 Vue 全家桶介绍 Vue有著名的全家桶系列,包含了vue-router(http://router.vu ...

  7. PAT甲题题解-1053. Path of Equal Weight (30)-dfs

    由于最后输出的路径排序是降序输出,相当于dfs的时候应该先遍历w最大的子节点. 链式前向星的遍历是从最后add的子节点开始,最后添加的应该是w最大的子节点, 因此建树的时候先对child按w从小到大排 ...

  8. thinkphp在wamp 配置去掉url中index.php方法

    http://blog.csdn.net/youmypig/article/details/45008971

  9. c# 简易绘制C语言头文件包含关系图

    最近在做一个项目的移植工作,项目很大,光c文件大约有1800多.由于某些需要,想要对某些代码文件引用的.h文件进行分析. 网上找了好久,暂无发现类似的工具. 正好,今天放假,就做了这么个工具. 好了, ...

  10. 第二阶段冲刺——three

    个人任务: 王金萱:优化统计个人博客结果页面的显示. 司宇航:绘制logo. 季方:合并程序(优化统计个人博客界面). 马佳慧:选择功能界面的选择框排版设计. 站立会议: 任务看板和燃尽图: