14997: [Usaco2017 Feb]Why Did the Cow Cross the Road III

目录

特别提示

网址

题目(一本通版)

    【题目描述】

    【输入】

    【输出】

    【输入样例】

    【输出样例】

能过的解法

    题目理解

    解题策略

          1. 初始化网格与道路:

           2. 处理道路信息:

           3. 应用并查集:

            4. 计算“遥远”对:

    代码

有趣的解法


特别提示

本人有两种解法,第一种比较笨,第二种一秒即可。

网址

一本通:点此进入

bzoj:没找到这题,服了

洛谷:点此进入

题目(一本通版)


时间限制: 1000 ms         内存限制: 262144 KB
提交数: 27     通过数: 9

    【题目描述】

Why did the cow cross the road? Well, one reason is that Farmer John's farm simply has a lot of roads, making it impossible for his cows to travel around without crossing many of them.

FJ's farm is arranged as an N×N square grid of fields (2 <= N <= 100), Certain pairs of adjacent fields (e.g., north-south or east-west) are separated by roads, and a tall fence runs around the external perimeter of the entire grid, preventing cows from leaving the farm. Cows can move freely from any field to any other adjacent field (north, east, south, or west), although they prefer not to cross roads unless absolutely necessary.

There are K cows (1 <= K <= 100, K <= N^2) on FJ's farm, each located in a different field. A pair of cows is said to be "distant" if, in order for one cow to visit the other, it is necessary to cross at least one road. Please help FJ count the number of distant pairs of cows.

    【输入】

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值