C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)
Alyona and Spreadsheet
这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢?
【题目链接】Alyona and Spreadsheet
&题意:
给一n*m的表,之后给T个询问,每个询问是r1和r2,问从r1行到r2行(包括这2行)是否至少有一列是非递减的?
&题解:
可以把给的n*m表处理一下,处理成b[i][j]数组,存的是第j列递增开始的位置是第几行.
这样,只有b中第r2行最小的小于r1就行了,否则就是No
【时间复杂度】\(O(max(q,n*m))\)q是询问次数
&代码:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn= 1e3 +9,INF=0x3f3f3f3f;
int n,m;
vector<vector<int> > a,b;
vector<int> c;
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);
cin>>n>>m;
a.resize(n);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
int t;
cin>>t;
a[i].push_back(t);
}
b=a;
for(int i=0;i<m;i++) b[0][i]=0;
for(int i=0;i<m;i++)
for(int j=1;j<n;j++){
if(a[j][i]>=a[j-1][i]){
b[j][i]=b[j-1][i];
}
else{
b[j][i]=j;
}
}
c.resize(n);
for(int i=0;i<n;i++){
c[i]=INF;
for(int j=0;j<m;j++){
c[i]=min(c[i],b[i][j]);
}
}
int T;
cin>>T;
for(int i=0;i<T;i++){
int r1,r2;
cin>>r1>>r2;
if(c[r2-1]<=r1-1)
puts("Yes");
else
puts("No");
}
return 0;
}
C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)的更多相关文章
- Codeforces Round #401 (Div. 2) 离翻身就差2分钟
Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...
- Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表
题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 sec ...
- Codeforces Round #401 (Div. 2)
和FallDream dalao一起从学长那借了个小号打Div2,他切ABE我做CD,我这里就写下CD题解,剩下的戳这里 AC:All Rank:33 小号Rating:1539+217->17 ...
- Codeforces Round #401 (Div. 2) A,B,C,D,E
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- 【离线】【递推】【multiset】 Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet
对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少. 用multiset维护,取个最小值,看是否小于等于该询问的左端点. #include<cstdio> #inc ...
- Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 字符串
题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...
- D Cloud of Hashtags Codeforces Round #401 (Div. 2)
Cloud of Hashtags [题目链接]Cloud of Hashtags &题意: 给你一个n,之后给出n个串,这些串的总长度不超过5e5,你要删除最少的单词(并且只能是后缀),使得 ...
- Codeforces Round #401 (Div. 1) C(set+树状数组)
题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...
随机推荐
- [No0000DD]C# StringEx 扩展字符串类 类封装
using System; using System.Text.RegularExpressions; namespace Helpers { /// <summary> /// 包含常用 ...
- 网上常用免费WebServices集合
天气预报Web服务,数据来源于中国气象局 公用事业http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 中国股票行情分时走势预览缩略图 ...
- day13: 迭代器和生成器
1,思考所有可以被for循环的:list,tuple,set,dict,range,enumerate,f,str,差不多了,为何这些数据类型可以被for循环呢? 2,一个标准的装饰器函数 from ...
- 一种比较简单的实现ping的方式
<span style="font-family: Arial, Helvetica, sans-serif;">头文件</span> <span s ...
- day5_函数_判断小数
def check_float(s): ''' #这个函数的作用就是判断传入的字符串是否是合法的消失 :param s: 传入一个字符串 :return: True/False ''' s = str ...
- 2018/04/14 理解oAuth2.0
最近都近没有更新博客了,卡在 oAuth 上了. 之前公司做统一身份的认证,不了解 oAuth 的我在这卡了两天. 于是决定仔细研究原理,理论指导实践. -- 什么是 oAuth ? 简单来说 oAu ...
- Java之旅_高级教程_序列化
摘自 :http://www.runoob.com/java/java-serialization.html Java序列化 Java提供了一种对象序列化的机制,该机制中,一个对象可以被表示为一个字 ...
- 使用Git,如何忽略不需要上传的文件(配置文件)
步骤1:在目录下,选择GIt Bash Here 2.输入命令 : git update-index --assume-unchanged 文件名 3.再输入指令 git status 查看修改文件 ...
- Centos6.5+Redmine
花了两天时间,基于centos6.5操作系统,搭建了redmine环境,在这里记录下过程中遇到的问题以及搭建流程. centos6.5; redmine2.5.0; Ruby1.9.3; step 1 ...
- state访问状态对象
状态对象赋值给内部对象,也就是把stroe.js中的值,赋值给我们模板里data中的值.我们有三种赋值方式: 1.通过computed的计算属性直接赋值 Count.vue {count} <s ...