codeforces 777C.Alyona and Spreadsheet 解题报告
题目链接: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 解题报告的更多相关文章
- Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- 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] ...
- Codeforces 777C - Alyona and Spreadsheet - [DP]
题目链接:http://codeforces.com/problemset/problem/777/C 题意: 给定 $n \times m$ 的一个数字表格,给定 $k$ 次查询,要你回答是否存在某 ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
随机推荐
- iOS 多线程之 GCD 的基本使用
什么是GCD 全称Grand Central Dispatch 中暑调度器 纯C语言 提供了很多强大的函数 GCD 的优势 GCD是苹果公司为多核的并行运算提出的解决方案 GCD会自动利用更多的CPU ...
- JavaScript获取地址栏内容
例如地址为:http://www.mazey.net/baby/blog/index.php?a=1&b=2#c var query = window.location.href; //htt ...
- http-proxy-middleware使用方法和实现原理(源码解读)
本文主要讲http-proxy-middleware用法和实现原理. 一 简介 http-proxy-middleware用于后台将请求转发给其它服务器. 例如:我们当前主机A为http://loca ...
- Vue表格中时间的处理
Vue中表格的数据应该来自后台数据库,然后从数据库中读取到的数据,时间格式可能有些不同,我们可以根据实际需要来对这个时间进行转化. 这里介绍一个js库,它提供了强大的日期处理功能,功能强大且只有2k大 ...
- 启动hadoop集群
1.配置core-site.xml(每个节点上都要配置) 路径: /usr/local/hadoop-2.7.3/etc/hadoop/core-site.xml 配置项1: name: fs.def ...
- springboot整合Ehcache
首先引入maven包: <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- Autonomous System
自治系统(Autonomous System).在互联网中,一个自治系统(AS)是一个有权自主地决定在本系统中应采用何种路由协 议的小型单位.这个网络单位可以是一个简单的网络也可以是一个由一个 ...
- django 查询
mail = UserProfile.objects.get(email = email) get如果没有查询到会抛出一个不存在的异常 ...
- render httprequest
render def my_view(request):# View code here... t = loader.get_template('myapp/index.html') c = Requ ...
- mtime、atime、ctime基本解释
不罗嗦 Access time.Modify time.Change time,也就是访问时间.修改时间和状态时间. >修改时间:文件的内容被最后一次修改的时间,我们经常用的ls -l命令显示出 ...