题目链接

大家的 Blog 里面都是做过的题目,只有我的里面什么都没有

那我也开始写一点吧

刷着刷着 DP 不知怎的就出来一道这个题……用时 2 hours 后怒而删两个文件重构……

然后过了……过了……

至今不知道前两遍错在哪里……

Code - first time:连通块染色 +建图,然后二分,广搜判断

Code - second time:连通块染色 +建图,并查集维护连通块大小,做伪 Kruskal

Code - third time:二分,广搜判断

 #include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = + ;
const int maxk = * + ;
int n, h[maxn][maxn], vis[maxn][maxn], flag;
int f[][] = { , , , , -, , , - }; inline int Abs(int x) { return x > ? x : -x; } inline bool Breath_fs(int sx, int sy, int c) {
queue<pair<int, int> > q;
q.push(make_pair(sx, sy)), vis[sx][sy] = ;
int cnt = ;
while( !q.empty() ) {
int x = q.front().first, y = q.front().second;
for(int i = ; i < ; ++i) {
int tx = x + f[i][], ty = y + f[i][];
if( tx < || tx > n || ty < || ty > n ) continue;
if( Abs(h[x][y] - h[tx][ty]) > c || vis[tx][ty] ) continue;
++cnt, vis[tx][ty] = , q.push(make_pair(tx, ty));
}
q.pop();
}
return cnt + > ((n * n) >> ) + ((n * n) & );
} inline bool Check(int x) {
memset(vis, , sizeof vis), flag = ;
for(int i = ; i <= n; ++i) {
for(int j = ; (!flag && j <= n); ++j)
if( !vis[i][j] ) flag = flag | Breath_fs(i, j, x);
if( flag ) break;
}
return flag;
} int main(int argc, char const *argv[])
{
freopen("nanjolno.in", "r", stdin);
freopen("nanjolno.out", "w", stdout); scanf("%d", &n);
for(int i = ; i <= n; ++i) for(int j = ; j <= n; ++j) scanf("%d", &h[i][j]);
int lef = , righ = , mid = (lef + righ) >> , ans = ;
for( ; lef <= righ; mid = (lef + righ) >> )
Check(mid) ? ans = mid, righ = mid - : lef = mid + ;
printf("%d\n", ans); fclose(stdin), fclose(stdout);
return ;
}

—— 晨意微寒秋渐深,侧畔无事俏佳人。

[USACO13FEB] Tractor的更多相关文章

  1. 【题解】[USACO13FEB]Tractor S

    题目戳我 \(\text{Solution:}\) 好久没写啥\(dfs\)了,借这个题整理下细节. 观察到答案具有二分性,所以先求出其差的最大最小值,\(\log val\)的复杂度不成问题. 考虑 ...

  2. USACO Tractor

    洛谷 P3073 [USACO13FEB]拖拉机Tractor 洛谷传送门 JDOJ 2351: USACO 2013 Feb Silver 2.Tractor JDOJ传送门 题意翻译 题目描述 F ...

  3. [USACO13FEB]出租车Taxi

    洛谷题目链接:[USACO13FEB]出租车Taxi 题目描述 Bessie is running a taxi service for the other cows on the farm. The ...

  4. 洛谷 P1849 [USACO12MAR]拖拉机Tractor

    题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle ...

  5. 洛谷—— P1849 [USACO12MAR]拖拉机Tractor

    https://www.luogu.org/problemnew/show/P1849 题目描述 After a long day of work, Farmer John completely fo ...

  6. [bzoj3061][Usaco13Feb]Partitioning the Farm_动态规划_状压dp

    Partitioning the Farm bzoj-3061 Usaco13Feb 题目大意:给定一个n*n的方格图,用k条贯穿方格图的直线将整个方格图分割,使得每一块的权值和的最大值最小. 注释: ...

  7. [bzoj3062][Usaco13Feb]Taxi_贪心

    Taxi bzoj-3062 Usaco13Feb 题目大意:有n个奶牛想坐出租车.第i头奶牛在起点a[i]等候,想坐出租车到b[i].Bessie从0出车,车上只能坐一头奶牛.她必须完成所有奶牛的要 ...

  8. Android有用的任务管理器—tractor

    在平时的android开发工作中,我们常常须要运行耗时操作,有时为了用户体验还须要显示个等待框,我之前的做法都是开一个线程,然后用handler发消息进行显示和关闭等待框以及相关的ui操作.假设任务比 ...

  9. USACO 2012 March Silver Tractor /// 优先队列BFS oj21567

    题目大意: 输入n,(x,y):n为阻挡的草堆数量,(x,y)为开始时拖拉机所在的位置 接下来n行每行一个坐标(a,b):为各个草堆的坐标 输出拖拉机要回到原点(0,0)需要移动的草堆数量 Sampl ...

随机推荐

  1. layui tips

  2. python---反射详解

    反射即想到4个内置函数分别为:getattr.hasattr.setattr.delattr  获取成员.检查成员.设置成员.删除成员 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  3. BZOJ1005 HNOI2008明明的烦恼(prufer+高精度)

    每个点的度数=prufer序列中的出现次数+1,所以即每次选一些位置放上某个点,答案即一堆组合数相乘.记一下每个因子的贡献分解一下质因数高精度乘起来即可. #include<iostream&g ...

  4. 微信小程序——demo合集及简单的文档解读【五】

    官方Demo https://github.com/wechat-miniprogram/miniprogram-demo 其他Demo https://www.cnblogs.com/ytkah/p ...

  5. 洛谷P3183食物链题解

    不得不说,这是道很难减少时间复杂度的题,且这个题有点像一道拓扑排序题,但是这个难度标签有点低. 我们应该可以想到拓扑排序可能是这个题的正解,但是题目中有输出总数,因此我们就可以造一个数组表示从这个点出 ...

  6. 「AC自动机」学习笔记

    AC自动机(Aho-Corasick Automaton),虽然不能够帮你自动AC,但是真的还是非常神奇的一个数据结构.AC自动机用来处理多模式串匹配问题,可以看做是KMP(单模式串匹配问题)的升级版 ...

  7. 各种MM(存储器)含义

    1.rom:read only memory 只读存储器 只能读,不能写. 2.ram:random access memory 随机存取存储器 可读可写. 3.fifo:first in first ...

  8. 【GZOI2015】石子游戏 博弈论 SG函数

    题目大意 有\(n\)堆石子,两个人可以轮流取石子.每次可以选择一堆石子,做出下列的其中一点操作: 1.移去整堆石子 2.设石子堆中有\(x\)个石子,取出\(y\)堆石子,其中\(1\leq y&l ...

  9. 【XSY1762】染色问题 网络流

    题目描述 给定一张\(n\)个点\(m\)条边的无向图.每个顶点有一个颜色,要么是黑,要么是白.我们想进行一些操作,使得最终每一条边的两个端点都是不同的颜色.每一次操作,你可以将一条边的两个端点交换颜 ...

  10. Ionic3在ts中获取html中值的方法

    我觉得有两种方法,都是Angular中的语法,一种是把值当做参数传递,另一种是使用ngModel实现双向绑定 还有一种很少用到的,Js的原生方法:document.getElementById('ch ...