题目链接:http://codeforces.com/problemset/problem/777/C

题目意思:给出一个 n * m 的矩阵,然后问 [l, r] 行之间是否存在至少一列是非递减序列

解析:

(1)原输入:

   ——》

(2)统计第 i 行里第 j 列 的最长非递减序列数

——》

(3)每列非递减序列在第 i 行的最长值

然后有两种方法:  二维数组 和 一维数组的处理。个人偏向一维数组

方法 一 (一维数组)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; /* 一维数组做法
(1)up[0-m]:上一行输入数,每输入一行更新一次
(2)cnt[0-m]: 如果当前输入数 a 与 up[0-m] 构成非递减序列,则cnt[0-m]累加1 (if a >= up[x], cnt[x]=cnt[x-1]+1 0 < x < n)
(3)max_row[j]:每列非递减序列在第 j 行的最长值
*/ const int maxn = 1e5 + ;
int up[maxn];
int cnt[maxn], max_row[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, m;
while (scanf("%d%d", &n, &m) !=EOF) {
memset(cnt, , sizeof(cnt));
memset(max_row, , sizeof(max_row)); for (int i = ; i < m; i++) { // 第 1 行
scanf("%d", &up[i]);
max_row[i] = cnt[i] = ;
} int a; // 第 2 行 ~ 第 n 行
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++) {
scanf("%d", &a);
cnt[j] = (a >= up[j] ? cnt[j]+ : );
up[j] = a; // 更新
max_row[i] = max(max_row[i], cnt[j]);
}
} int k, l, r;
scanf("%d", &k);
while (k--) {
scanf("%d%d", &l, &r);
printf("%s\n", max_row[r-] >= r-l+ ? "Yes" : "No");
}
}
return ;
}

方法二 (二维数组)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, m;
while (scanf("%d%d", &n, &m) !=EOF) {
vector<vector<int> > a, cnt;
a.resize(n);
cnt.resize(n);
for (int i = ; i < n; i++) {
a[i].resize(m);
cnt[i].resize(m);
for (int j = ; j < m; j++) {
scanf("%d", &a[i][j]);
}
} for (int i = ; i < m; i++) {
cnt[][i] = ;
for (int j = ; j < n; j++) {
cnt[j][i] = (a[j][i] >= a[j-][i] ? cnt[j-][i]+ : );
}
}
int maxr[];
for (int i = ; i < n; i++) {
maxr[i] = ;
for (int j = ; j < m; j++) {
maxr[i] = max(maxr[i], cnt[i][j]);
}
}
int k, l, r;
scanf("%d", &k);
for (int i = ; i < k; i++) {
scanf("%d%d", &l, &r);
printf("%s\n", r-l+ <= maxr[r-] ? "Yes" : "No");
}
}
return ;
}

codeforces 777C.Alyona and Spreadsheet 解题报告的更多相关文章

  1. Codeforces 777C Alyona and Spreadsheet

    C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  2. Codeforces 777C Alyona and Spreadsheet(思维)

    题目链接 Alyona and Spreadsheet 记a[i][j]为读入的矩阵,c[i][j]为满足a[i][j],a[i - 1][j], a[i - 2][j],......,a[k][j] ...

  3. Codeforces 777C - Alyona and Spreadsheet - [DP]

    题目链接:http://codeforces.com/problemset/problem/777/C 题意: 给定 $n \times m$ 的一个数字表格,给定 $k$ 次查询,要你回答是否存在某 ...

  4. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  5. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  6. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  7. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  8. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  9. codeforces B. Xenia and Ringroad 解题报告

    题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...

随机推荐

  1. 巨蟒python全栈开发linux之cento8

    1.复习路飞部署学习 2.mysql数据库远程访问 3.mysql主从复制 4.redis安全方式启动 5.redis数据类型 6.redis发布订阅 7.redis持久化 8.redis哨兵 9.r ...

  2. 通过less 计算 得出图片均分布局

    <style lang="less"> @import "../style/weui.wxss"; // WXSS · 小程序 https://de ...

  3. MFC重绘原理的关键理解

    // ====================Windows重绘消息与函数========================== 得到桌面窗口的句柄,然后再绘图HWND GetDesktopWindow ...

  4. Linux下源码安装redis,编译安装

    1.下载redis源码 [root@localhost opt]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz 2.解压缩 [ ...

  5. Mac开发环境配置 就喜欢折腾

    暑假放假,开始用自己的电脑配置开发环境进行学习. 虚拟机安装VMware tools也遇到一些问题.折腾之后解决,遇到各种问题,谷歌后都能解决. 折腾了几天虚拟机下的Ubuntu,发现mac带虚拟机太 ...

  6. nginx基础系列

    centos中搭建nginx环境 nginx开机启动 nginx配置文件说明 nginx负载均衡配置 nginx upstream模块 nginx配置ssl nginx日志切割 nginx平滑升级

  7. 解释*args和**kwargs的含义

    当我们不知道向函数传递多少参数时,比如我们向传递一个列表或元组,我们就使用*args def func(*args): for i in args: print(i) func(3,2,1,4,7) ...

  8. 正则表达式test match exec search

    (1)((2))(3)   $1  是第一个括号 $2  是第二个括号 $3  是第二个括号中的括号 $4  是第三个括号     http://www.jb51.net/article/28007. ...

  9. a各种状态

    hover   设置对象在其鼠标悬停时的样式表属性 active  设置对象在被用户激活(在鼠标点击与释放之间发生的事件)时的样式表属性.link  设置a对象在未被访问前的样式表属性.visited ...

  10. $ 用python处理Excel文档(1)——用xlrd模块读取xls/xlsx文档

    本文主要介绍xlrd模块读取Excel文档的基本用法,并以一个GDP数据的文档为例来进行操作. 1. 准备工作: 1. 安装xlrd:pip install xlrd 2. 准备数据集:从网上找到的1 ...