[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 ...
随机推荐
- Nginx 磁盘IO的优化
L:132
- Git秘钥生成以及Gitlab配置
安装Git:详见http://www.cnblogs.com/xiuxingzhe/p/9300905.html 开通gitlab(开通需要咨询所在公司的gitlab管理员)账号后,本地Git仓库和g ...
- StringBuffer作为参数传递的问题
public class Foo {2. public static void main (String [] args) {3. StringBuffer a = new Strin ...
- GitHub大佬:供计算机学习鉴黄功能的图片数据库
ps:学无止境 想要构建一套鉴黄系统,必须有大量的真实图片供计算机进行学习,以便于区分开正常图片和黄色图片. 近期有位加拿大程序员在Github上传了图片列表,里面包含了大量图片地址可以供计算机进行学 ...
- mysql 下载地址
新浪的镜像站 http://mirrors.sohu.com/mysql yum安装: 首先要到MySQL yum库的下载页面http://dev.mysql.com/downloads/repo/y ...
- 在 Activity 中实现 getContentView 操作
2017/9/8 17:17:03 前言 最近接到个需要优化Android原生系统设置APK的任务.这个任务里面有一个更换应用背景图片的需求.我手里的这个设备是一个平板设备,使用了一下这个 ...
- Vue——轻松实现vue底部点击加载更多
前言 需求总是不断改变的,好吧,今天就把vue如何实现逐步加载更多和分布加载更多说下,默认你知道如何去请求数据的哈 一次请求 页面 使用slice来进行限制展现从0,a的数据 <div v-fo ...
- reactNative 基础
参考:中文网,极客 一 . 基本程序: import React, { Component } from 'react'; import { Text } from 'react-native'; e ...
- Apache 安装及常用参数设置
禁用 selinux setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/confi ...
- Navicat Premium 12 破解(MySQL、MariaDB、MongoDB、SQL Server、SQLite)
打开注入到安装目录中的exe中 破解提示(还没好,继续看下去) 如果你安装的是中文版,选一下中文版(英文默认即可),获取一下key(名字和组织可以自定义) 打开Navicat,选择注册(第一次打开选注 ...