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是询问次数

&代码:

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <vector>
  7. using namespace std;
  8. const int maxn= 1e3 +9,INF=0x3f3f3f3f;
  9. int n,m;
  10. vector<vector<int> > a,b;
  11. vector<int> c;
  12. int main()
  13. {
  14. ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  15. // freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);
  16. cin>>n>>m;
  17. a.resize(n);
  18. for(int i=0;i<n;i++)
  19. for(int j=0;j<m;j++){
  20. int t;
  21. cin>>t;
  22. a[i].push_back(t);
  23. }
  24. b=a;
  25. for(int i=0;i<m;i++) b[0][i]=0;
  26. for(int i=0;i<m;i++)
  27. for(int j=1;j<n;j++){
  28. if(a[j][i]>=a[j-1][i]){
  29. b[j][i]=b[j-1][i];
  30. }
  31. else{
  32. b[j][i]=j;
  33. }
  34. }
  35. c.resize(n);
  36. for(int i=0;i<n;i++){
  37. c[i]=INF;
  38. for(int j=0;j<m;j++){
  39. c[i]=min(c[i],b[i][j]);
  40. }
  41. }
  42. int T;
  43. cin>>T;
  44. for(int i=0;i<T;i++){
  45. int r1,r2;
  46. cin>>r1>>r2;
  47. if(c[r2-1]<=r1-1)
  48. puts("Yes");
  49. else
  50. puts("No");
  51. }
  52. return 0;
  53. }

C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)的更多相关文章

  1. Codeforces Round #401 (Div. 2) 离翻身就差2分钟

    Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...

  2. 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 ...

  3. Codeforces Round #401 (Div. 2)

    和FallDream dalao一起从学长那借了个小号打Div2,他切ABE我做CD,我这里就写下CD题解,剩下的戳这里 AC:All Rank:33 小号Rating:1539+217->17 ...

  4. 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 ...

  5. 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 ...

  6. 【离线】【递推】【multiset】 Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet

    对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少. 用multiset维护,取个最小值,看是否小于等于该询问的左端点. #include<cstdio> #inc ...

  7. Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 字符串

    题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...

  8. D Cloud of Hashtags Codeforces Round #401 (Div. 2)

    Cloud of Hashtags [题目链接]Cloud of Hashtags &题意: 给你一个n,之后给出n个串,这些串的总长度不超过5e5,你要删除最少的单词(并且只能是后缀),使得 ...

  9. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

随机推荐

  1. [No0000DD]C# StringEx 扩展字符串类 类封装

    using System; using System.Text.RegularExpressions; namespace Helpers { /// <summary> /// 包含常用 ...

  2. 网上常用免费WebServices集合

    天气预报Web服务,数据来源于中国气象局 公用事业http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 中国股票行情分时走势预览缩略图 ...

  3. day13: 迭代器和生成器

    1,思考所有可以被for循环的:list,tuple,set,dict,range,enumerate,f,str,差不多了,为何这些数据类型可以被for循环呢? 2,一个标准的装饰器函数 from ...

  4. 一种比较简单的实现ping的方式

    <span style="font-family: Arial, Helvetica, sans-serif;">头文件</span> <span s ...

  5. day5_函数_判断小数

    def check_float(s): ''' #这个函数的作用就是判断传入的字符串是否是合法的消失 :param s: 传入一个字符串 :return: True/False ''' s = str ...

  6. 2018/04/14 理解oAuth2.0

    最近都近没有更新博客了,卡在 oAuth 上了. 之前公司做统一身份的认证,不了解 oAuth 的我在这卡了两天. 于是决定仔细研究原理,理论指导实践. -- 什么是 oAuth ? 简单来说 oAu ...

  7. Java之旅_高级教程_序列化

    摘自 :http://www.runoob.com/java/java-serialization.html  Java序列化 Java提供了一种对象序列化的机制,该机制中,一个对象可以被表示为一个字 ...

  8. 使用Git,如何忽略不需要上传的文件(配置文件)

    步骤1:在目录下,选择GIt Bash Here 2.输入命令 : git update-index --assume-unchanged 文件名 3.再输入指令 git  status 查看修改文件 ...

  9. Centos6.5+Redmine

    花了两天时间,基于centos6.5操作系统,搭建了redmine环境,在这里记录下过程中遇到的问题以及搭建流程. centos6.5; redmine2.5.0; Ruby1.9.3; step 1 ...

  10. state访问状态对象

    状态对象赋值给内部对象,也就是把stroe.js中的值,赋值给我们模板里data中的值.我们有三种赋值方式: 1.通过computed的计算属性直接赋值 Count.vue {count} <s ...