题目链接: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. Grafana-----Singlestat Panel

    singlestat面板允许你显示a SINGLE series的主要的汇总统计的一系列.它将series 简化为单个数(通过查看序列中的最大值.最小值.平均值或总和).singlestat还提供阈值 ...

  2. coursera 《现代操作系统》

    什么是独占设备技术?为什么说 “SPOOLing不是独占设备的”? 百度百科没有解释,从教材中找到了:  第二章 取数指令 load To load a value from memory, you ...

  3. 设计一个算法,採用BFS方式输出图G中从顶点u到v的最短路径(不带权的无向连通图G採用邻接表存储)

    思想:图G是不带权的无向连通图.一条边的长度计为1,因此,求带顶点u和顶点v的最短的路径即求顶点u和顶点v的边数最少的顶点序列.利用广度优先遍历算法,从u出发进行广度遍历,类似于从顶点u出发一层一层地 ...

  4. (4.7)怎么捕获和记录SQL Server中发生的死锁?

    转自:https://blog.csdn.net/c_enhui/article/details/19498327 怎么捕获和记录SQL Server中发生的死锁? 关键词:死锁记录,死锁捕获 sql ...

  5. Spring学习笔记1—依赖注入(构造器注入、set注入和注解注入)

    什么是依赖注入 在以前的java开发中,某个类中需要依赖其它类的方法时,通常是new一个依赖类再调用类实例的方法,这种方法耦合度太高并且不容易测试,spring提出了依赖注入的思想,即依赖类不由程序员 ...

  6. PyQt4 UI设计和调用 使用eric6

    使用工具eric6 安装包地址: http://eric-ide.python-projects.org/eric-download.html 1.需要安装python和pyqt为前提,然后安装eri ...

  7. 剑指offer 面试10题

    面试10题: 题目:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.n<=39 n=0时,f(n)=0 n=1时,f(n)=1 n>1时,f(n)=f(n-1 ...

  8. 前端基础之jquery_mouse相关操作与不同

    jquery中mouse相关操作与不同 mousedown() //当鼠标指针移动到元素上方,并按下鼠标左键时,会发生 mousedown 事件 mouseup() //当鼠标指针移动到元素上方,并松 ...

  9. Python基础(17)_面向对象程序设计(抽象类、继承原理、封装、多态,绑定方法)

    一.抽象类 抽象类是一个特殊的类,它的特殊之处在于只能被继承,不能被实例化 1.在python中实现抽象类 import abc #利用abc模块实现抽象类 class All_file(metacl ...

  10. 如何修改Eclipse中的快捷键

    首先打开Eclipse,Windows->Preferences ↓ 进入Preferences界面后,选择General->Keys ↓ 接下来你就会看到: 接下来点击OK就可以生效了.