[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 ...
随机推荐
- Typeclassopedia
https://wiki.haskell.org/wikiupload/8/85/TMR-Issue13.pdf By Brent Yorgey, byorgey@gmail.com Original ...
- Spring 团队开源 nohttp,尽可能不用 HTTP
Spring 团队开源 nohttp 项目,用以查找.替换和阻止 http:// 的使用. 项目是为了在可能使用 https:// 的情况下不使用到 http://,确保不会发生中间人攻击.Sprin ...
- Postgresql_最新版11.2源码编译安装
pg官网:https://www.postgresql.org/ yum -y gcc gcc-c++ cmake ncurses-devel perl zlib* .去官网下载源码包. 下载地址:h ...
- HTTP 状态码之:301、302 重定向
转自:http://www.cnblogs.com/5207/p/5908354.html 概念 301 Moved Permanently 被请求的资源已永久移动到新位置,并且将来任何对此资源的引用 ...
- visual studio2017 创建Vue项目
1:打开Visual studio 2017后 按图片操作新建项目 也可以使用快捷键Ctrl+Shift+N 进入创建项目页面 2:选择JavaScript 里的Node.js创建对应的Vue项目 ...
- HDU 1241 Oil Deposits (DFS or BFS)
链接 : Here! 思路 : 搜索判断连通块个数, 所以 $DFS$ 或则 $BFS$ 都行喽...., 首先记录一下整个地图中所有$Oil$的个数, 然后遍历整个地图, 从油田开始搜索它所能连通多 ...
- lamp平台搭建论坛网站(Discuz论坛)
1. 安装Apache 1) 安装apr [root@www lamp]# yum install zlib-devel gcc gcc-c++ openssl-devel pcre-devel -y ...
- 【Zoj 4061】Magic Multiplication
[链接] 我是链接,点我呀:) [题意] [题解] /* for a[1] from 1~9 1*1=1 2*1=2 3*1=3 1*2=2 2*2=4 3*2=6 1*3=3 2*3=6 3*3=9 ...
- RabbitMQ学习总结(1)——基础概念详细介绍
一.基础概念详细介绍 1.引言 你是否遇到过两个(多个)系统间需要通过定时任务来同步某些数据?你是否在为异构系统的不同进程间相互调用.通讯的问题而苦恼.挣扎?如果是,那么恭喜你,消息服务让你可以很轻松 ...
- magento 在全站或者某页面增加外联js或者css的方法
1,在整站末尾增加外联资源 找到当前主题的布局文件cms.xml,在<default></default>添加如下代码: <reference name="be ...