[USACO13FEB] Tractor
题目链接
大家的 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的更多相关文章
- 【题解】[USACO13FEB]Tractor S
题目戳我 \(\text{Solution:}\) 好久没写啥\(dfs\)了,借这个题整理下细节. 观察到答案具有二分性,所以先求出其差的最大最小值,\(\log val\)的复杂度不成问题. 考虑 ...
- USACO Tractor
洛谷 P3073 [USACO13FEB]拖拉机Tractor 洛谷传送门 JDOJ 2351: USACO 2013 Feb Silver 2.Tractor JDOJ传送门 题意翻译 题目描述 F ...
- [USACO13FEB]出租车Taxi
洛谷题目链接:[USACO13FEB]出租车Taxi 题目描述 Bessie is running a taxi service for the other cows on the farm. The ...
- 洛谷 P1849 [USACO12MAR]拖拉机Tractor
题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle ...
- 洛谷—— P1849 [USACO12MAR]拖拉机Tractor
https://www.luogu.org/problemnew/show/P1849 题目描述 After a long day of work, Farmer John completely fo ...
- [bzoj3061][Usaco13Feb]Partitioning the Farm_动态规划_状压dp
Partitioning the Farm bzoj-3061 Usaco13Feb 题目大意:给定一个n*n的方格图,用k条贯穿方格图的直线将整个方格图分割,使得每一块的权值和的最大值最小. 注释: ...
- [bzoj3062][Usaco13Feb]Taxi_贪心
Taxi bzoj-3062 Usaco13Feb 题目大意:有n个奶牛想坐出租车.第i头奶牛在起点a[i]等候,想坐出租车到b[i].Bessie从0出车,车上只能坐一头奶牛.她必须完成所有奶牛的要 ...
- Android有用的任务管理器—tractor
在平时的android开发工作中,我们常常须要运行耗时操作,有时为了用户体验还须要显示个等待框,我之前的做法都是开一个线程,然后用handler发消息进行显示和关闭等待框以及相关的ui操作.假设任务比 ...
- USACO 2012 March Silver Tractor /// 优先队列BFS oj21567
题目大意: 输入n,(x,y):n为阻挡的草堆数量,(x,y)为开始时拖拉机所在的位置 接下来n行每行一个坐标(a,b):为各个草堆的坐标 输出拖拉机要回到原点(0,0)需要移动的草堆数量 Sampl ...
随机推荐
- Lodop打印控件 打印‘接下一页’‘以下空白’
Lodop打印控件中,超文本超过设置的打印项高度 或超过纸张,就会自动分页,纯文本通过设置为多页项也可以根据打印项高度自动分页,Lodop中还提供了许多手动分页的方法,对于多页文档中(自动分页或手动分 ...
- linux读取Windows的txt文件问题
问题:Windows下生成的txt文件,在Linux下读取时会读取到多余字符(如: ^M) 原因:Windows和Linux下的换行符不一致 解决:在Linux代码中将多余字符去掉 ) buf = b ...
- 【NLP】自然语言处理:词向量和语言模型
声明: 这是转载自LICSTAR博士的牛文,原文载于此:http://licstar.net/archives/328 这篇博客是我看了半年的论文后,自己对 Deep Learning 在 NLP 领 ...
- Android系统启动概要
注:Java系统服务与本地系统服务标注反了 1.Linux内核 Android系统启动时,首先通过BootLoader(系统加载器)加载Linux内核,在Linux加载启动时,首先初始化内核,再调用i ...
- Vuex以及axios
Vuex 简介 vuex是一个专门为Vue.js设计的集中式状态管理架构. 状态? 我们把它理解为在data中需要共享给其他组件使用的部分. Vuex和单纯的全局对象有以下不同: 1.Vuex 的状态 ...
- 洛谷P2722总分题解
题目 这个题是一个裸的完全背包问题,但是数组需要开大, 代码 #include<iostream> using namespace std; int n,m,v,i; int c[1000 ...
- python列表解析式,字典解析式,集合解析式和生成器
一.列表解析式(列表推倒式): 功能:是提供一种方便的列表创建方法,所以,列表解析式返回的是一个列表. 1 lst = [1, 3, 5, 8, 10] 2 ll = [x+x for x in ls ...
- Codeforces Global Round 2 D. Frets On Fire (动态开点线段树,沙雕写法)
题目链接:D. Frets On Fire 思路:明明可以离散化+二分写,思路硬是歪到了线段树上,自闭了,真实弟弟,怪不得其他人过得那么快 只和查询的区间长度有关系,排完序如果相邻的两个点的差值小于等 ...
- MT【260】单调函数
设$f(x)$是定义在$(0,+\infty)$上的单调函数,且对定义域内的任意实数$x$,都有$f(f(x)-\log_2 x)=3$, 求$f(x)-f^{'}(x)=2$的解所在的区间.____ ...
- zabbix python 微信告警脚本
测试zabbix的微信告警耗费了大量时间,使用了开源工具(OneOaaS weixin-alert).shell脚本工具(手动执行正常,服务器调用失败),均没有实现相关功能以下是自己优化过的Pytho ...