题目链接: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. docker desktop

    https://github.com/rogaha/docker-desktop http://blog.csdn.net/tinylab/article/details/45443563

  2. 提交cookie登录

    # coding:utf-8import requests # 先打开登录首页,获取部分cookieurl = "https://passport.cnblogs.com/user/sign ...

  3. HAProxy配置参数说明

    一.全局配置"global"配置中的参数为进程级别的参数,且通常与其运行的OS相关.1.进程管理及安全相关的参数chroot <jail dir>修改haproxy的工 ...

  4. ajax发送js类型的数据

    一.如图所示 var ids = [1,2,3,4,5,6,7] $.ajax({ url: requestUrl, type: 'delete', data: JSON.stringify(ids) ...

  5. LR controller 参数化

    我在这里写的是在controller设置了vuser后的运行结果. 对于select Next Row和Update Value On的理解都是个人根据运行结果分析得出的理解. 而且主要写的unuqu ...

  6. css样式之补充

    css常用的一些属性: 1.去掉下划线 :text-decoration:none ;2.加上下划线: text-decoration: underline; 3.调整文本和图片的位置(也就是设置元素 ...

  7. JavaScript:学习笔记(3)——正则表达式的应用

    JavaScript:正则表达式的应用 应用正则表达式对象RegExp 创建正则表达式 JavaScript中使用RegExp对象来表述一个正则表达式.使用正则表达式之前首先要创建一个RegExp对象 ...

  8. BIO,NIO和AIO

    BIO:同步阻塞式IO,服务器实现模式为一个连接一个线程,即客户端有连接请求时服务器端就需要启动一个线程进行处理,如果这个连接不做任何事情会造成不必要的线程开销,当然可以通过线程池机制改善. NIO: ...

  9. win32调试——OutputDebugString

    win32下开发console程序可以直接用printf打印到控制台. 开发图形界面程序时,可以调用OutputDebugString将字符串输出到Debug窗口, 注意是要调试运行才能看到Debug ...

  10. 实用篇如何使用github(本地、远程)满足基本需求

    一.结构:    |--工作区    |--版本库        |--stage——add,可以每个添加到暂存区        |--master——commit        一次性提交到版本库 ...