落絮飞雁

顺流而下,把梦做完

HDOJ1037:Keep on Truckin'

不开心?睡一觉冷静冷静……
READ MORE →

HDOJ1064:Financial Management

不开心?做几道水题冷静冷静……
READ MORE →

HDOJ2070:Fibbonacci Number——一道水题

不开心?写会儿代码冷静冷静……
READ MORE →

HDOJ1232:畅通工程——并查集简单应用

Problem Description
某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?

Input
测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( #include #include int father[1001]; int FindGF(int a)//找祖父节点 { while (father[a] != a) a = father[a]; return a; } void Branch(int a, int b)//合并不同的祖父节点 { int fx, fy; fx = FindGF(a); fy = FindGF(b); if (fx != fy) father[fx] = fy; } int main() { int n, m, i, x, y, ans; while (scanf(“%d”, &n) && n != 0) { for (i = 1; i

汇编语言数组练习题两则

题目一:在数组中查找某数,查到则返回下标,查不到则返回-1
data段提供如下:

area array, data, readwrite
src    dcd 2,4,3,8,14,1,5
length equ 6*4
num    equ 3
dst    dcd -1,-1,-1,-1,-1,-1,-1

参考解答:

area search, code, readonly
       entry
start  mov r5, #num
       ldr r1, =src
       add r6, r1, #length
       ldr r3, =dst
       mov r4, #0

loop   ldr r2, [r1]
       cmp r2, r5
       BEQ output
inner  add r4, r4, #1
       add r1, r1, #4
       cmp r1, r6
       BLE loop
       B stop

output str r4, [r3]
       add r3, r3, #4
       B inner

Stop    MOV r0,#0x18
    LDR r1,=0x20026
    SWI 0x123456

end


题目二:数组匹配,给两个各自无重复数据的数组,查找里面匹配到的数据,把数据保存到另一个数组里。
data段如下:

area array, data, readwrite
src    dcd 2,4,6,8,10,12,14
len    equ 6*4
dst    dcd 1,2,3,4,5,6,7,8
length equ 7*4
array  dcd 0,0,0,0,0,0,0

参考解答:

area match, code, readonly
       entry
start  ldr r1, =src
       add r5, r1, #len
       ldr r2, =dst
       add r6, r2, #length
       ldr r7, =array

inner  ldr r3, [r1]
       ldr r4, [r2]
       cmp r3, r4
       BEQ output
       add r2, r2, #4
       cmp r2, r6
       BLE inner
outer  add r1, r1, #4
       ldr r2, =dst
       cmp r1, r5
       BLE inner
       B stop

output str r3, [r7]
       add r7, r7, #4
       B outer

Stop    MOV r0,#0x18
    LDR r1,=0x20026
    SWI 0x123456

HDOJ3926:Hand in hand——并查集、同构图应用

Problem Description
In order to get rid of Conan, Kaitou KID disguises himself as a teacher in the kindergarten. He knows kids love games and works out a new game called “hand in hand”.

Initially kids run on the playground randomly. When Kid says “stop”, kids catch others’ hands immediately. One hand can catch any other hand randomly. It’s weird to have more than two hands get together so one hand grabs at most one other hand. After kids stop moving they form a graph.

Everybody takes a look at the graph and repeat the above steps again to form another graph. Now Kid has a question for his kids: “Are the two graph isomorphism?”

Input
The first line contains a single positive integer T( T D_Double同学的。
首先考虑到每个节点的度数最多只能是2(每人两只手)。最终这些学生可能会被分成多组,每组是一个环形圆圈,或者是一条链。

题目要判断两个已经连好的图是否是”同构图”,。这里所谓的同构图是指两个图组成的不同的圆圈,链条,他们各个所对应的数量都是相等的。

那么我们只需要用并查集把连这的都合并起来,如果发现有环,就进行标识。然后把两个图的并查集按照每颗树的节点个数大小排序,如果个数相同,那么有环的都放在前面。 然后,只要一一比较两个已排序的数组,只要发现有一个是不同的,就不是同构图。

代码:

#include
#include
#include
#include
#include
#include
using namespace std;
const int maxN = 10001;

int n, m, n2, m2;
int father[maxN], PT[maxN], isCircle[maxN];
//memset(0, isCircle, sizeof(isCircle));
struct node
{
    int num, isCircle;
    friend bool operator b.num;
        return a.isCircle>b.isCircle;
    }
}an[maxN], bn[maxN];

int findset(int x)
{
    if (x == father[x]) return x;
    return father[x] = findset(father[x]);
}
void Union(int x, int y)
{
    x = findset(x); y = findset(y);
    if (x == y)
    {
        isCircle[x] = 1;
        return;
    }
    if (PT[x]>PT[y])
    {
        father[y] = x;
        PT[x] += PT[y];
    }
    else
    {
        father[x] = y;
        PT[y] += PT[x];
    }
}

int main()
{
    int t, ncase = 1;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d%d", &n, &m);
        memset(isCircle, 0, sizeof(isCircle));
        for (int i = 1; i 

参考了一部分代码。心急火燎的赶去看谷歌IO了~

解决关闭笔记本盖子后SSH断开的问题-Ubuntu

旧笔记本拿来做了 Ubuntu Server。但是发现在合上笔记本盖子后SSH会断开,摸索了一下解决方案:
READ MORE →

SSH命令行下升级Ubuntu

写在前面:Ubuntu不推荐用SSH进行升级,因为『升级失败时较难恢复』,且在升级之前会创建一个SSH守护进程(1022端口)。因此建议在通过SSH升级之前先在防火墙上打开对应端口。

升级步骤:

1)先升级系统软件:

sudo apt-get update&&sudo apt-get upgrade

2)重启电脑后安装update-manager-core:

sudo apt-get install update-manager-core

3)然后编辑/etc/update-manager/release-upgrades

将Prompt=lts改成Prompt=normal

然后保存关闭

4)最后执行升级:

sudo do-release-upgrade -d

即可完成对Ubuntu的升级。

参考:纯命令行方式升级ubuntu系统| 佐井

移动宽带改造方案:解决百度云&网易云音乐访问慢的问题

寝室用的是移动宽带。优点是上下行对等、出口带宽大、还能多拨;缺点是网内网站访问各种慢、DNS污染严重等等。不断摸索之后终于找到的解决方案~
READ MORE →

稀疏矩阵转置之快速转置法

数据结构作业题目 = =
前情回顾:矩阵转置-简单代码

READ MORE →