[hihocoder][Offer收割]编程练习赛44
扫雷游戏
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
void makedata() {
freopen("input.txt", "w", stdout);
cout << << endl; for(int i = ; i < ; i++) cout << << ' '; fclose(stdout);
} char a[][];
const int dx[] = { -, , , , -, , , - };
const int dy[] = { , , , -, , , -, - }; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n;
cin >> n; for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
cin >> a[i][j];
}
} for(int i = ; i <= n + ; i++) {
a[][i] = '.';
a[n + ][n + ] = '.';
a[i][] = '.';
a[i][n + ] = '.';
} for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
int tmp = ; for(int k = ; k < ; k++) {
if(a[i + dx[k]][j + dy[k]] == '*') tmp++;
} if(a[i][j] == '*') cout << a[i][j];
else cout << tmp;
} cout << endl;
} return ;
}
最大子矩阵2
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} lint a[][], s[][];
inline lint sum(int x1, int y1, int x2, int y2) {
if (x1 == && y1 == ) return s[x2][y2];
if (x1 != && y1 != ) return s[x2][y2] - s[x1 - ][y2] - s[x2][y1 - ] + s[x1 - ][y1 - ];
if (x1 == && y1 != ) return s[x2][y2] - s[x2][y1 - ];
if (x1 != && y1 == ) return s[x2][y2] - s[x1 - ][y2];
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, m;
lint k;
cin >> n >> m >> k;
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++) {
cin >> a[i][j];
}
}
memset(s, , sizeof(s));
s[][] = a[][];
for (int i = ; i < n; i++) s[i][] = a[i][] + s[i - ][];
for (int i = ; i < m; i++) s[][i] = a[][i] + s[][i - ];
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++) {
s[i][j] = s[i][j - ] + s[i - ][j] - s[i - ][j - ] + a[i][j];
}
}
int ans = -;
for (int x1 = ; x1 < n; x1++) {
for (int y1 = ; y1 < m; y1++) {
if ((n - x1) * (m - y1) <= ans) break;
for (int x2 = n - ; x2 >= x1 ; x2--) {
if ((x2 - x1 + ) * (m - y1) <= ans) break;
for (int y2 = m - ; y2 >= y1; y2--) {
if ((x2 - x1 + ) * (y2 - y1 + ) <= ans) break;
if (sum(x1, y1, x2, y2) <= k) ans = max(ans, (x2 - x1 + ) * (y2 - y1 + ));
}
}
}
}
cout << ans << endl;
return ;
}
[hihocoder][Offer收割]编程练习赛44的更多相关文章
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...
- hihocoder [Offer收割]编程练习赛61
[Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...
- ACM学习历程—Hihocoder [Offer收割]编程练习赛1
比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...
- hihocoder offer收割编程练习赛8 C 数组分拆
思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...
- hihocoder [Offer收割]编程练习赛18 C 最美和弦(dp)
题目链接:http://hihocoder.com/problemset/problem/1532 题解:一道基础的dp,设dp[i][j][k][l]表示处理到第几个数,当前是哪个和弦错了几次初始x ...
- hihoCoder [Offer收割]编程练习赛3 D子矩阵求和
子矩阵求和 http://hihocoder.com/discuss/question/3005 声明一下: n是和x一起的,m是和y一起的 x是横着的,y是纵着的,x往右为正,y往下为正 (非常反常 ...
- hihocoder [Offer收割]编程练习赛52 D 部门聚会
看了题目的讨论才会做的 首先一点,算每条边(u, v)对于n*(n+1)/2种[l, r]组合的贡献 正着算不如反着算 哪些[l, r]的组合没有包含这条边(u, v)呢 这个很好算 只需要统计u这半 ...
- hihocoder [Offer收割]编程练习赛14
A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...
- hihocoder [Offer收割]编程练习赛8
第一次做这种比赛,被自己坑的好惨... A.这道题的关键其实是如果有k和n满足kD+F>nL>kD则不能走无限远,分支看似难整理,其实比较简单,F>L根本就不用算了,明摆着就是Bsi ...
随机推荐
- 金蝶WAFII
- [luogu4162 SCOI2009] 最长距离(最短路)
传送门 Solution 题目是最长路,其实是最短路ヽ(ー_ー)ノ 把进入障碍点的边设为1,其他为0.枚举每个点为起点找距离<=T的点,更新答案 Code //By Menteur_Hxy #i ...
- [luogu 4886] 快递员
传送门 Solution 虽然不是点分治但用类似点分治的方法不断接近正确结果 Code // luogu-judger-enable-o2 #include <cstdio> #inclu ...
- 爬虫写法进阶:普通函数--->函数类--->Scrapy框架
本文转载自以下网站: 从 Class 类到 Scrapy https://www.makcyun.top/web_scraping_withpython12.html 普通函数爬虫: https:// ...
- vue.js 中 data, prop, computed, method,watch 介绍
vue.js 中 data, prop, computed, method,watch 介绍 data, prop, computed, method 的区别 类型 加载顺序 加载时间 写法 作用 备 ...
- 批量重命名B站下载文件
将B站下载的文件统一修改文件名 事情来由 事情是这样的,我在B站上发现一个教程,看了一下,非常不错,于是想下载下来(免得B站和谐). 问题就是这样来了,我手机没多少内存,下载后下发现文件在手机中都是以 ...
- Codeforces 892C/D
C. Pride 传送门:http://codeforces.com/contest/892/problem/C 本题是一个关于序列的数学问题——最大公约数(GCD). 对于一个长度为n的序列A={a ...
- 第一次训练 密码:acmore
#include <cstdio> #include <cstring> #define M 100010 #define INF 0x7FFFFFFF #define Min ...
- 洛谷 P2813 母舰
题目描述 在小A的星际大战游戏中,一艘强力的母舰往往决定了一场战争的胜负.一艘母舰的攻击力是普通的MA(Mobile Armor)无法比较的. 对于一艘母舰而言,它是由若干个攻击系统和若干个防御系统组 ...
- Spring事务的传播行为分析
前言 最近项目有涉及到Spring事务,所以工作之余,想认真了解学习下Spring事务,查阅了若干资料,做了一个demo(PS:参考了大牛的). 现分享总结如下: 1.Spring 事务的简介 理解事 ...