这一次是做练习,主要了解了两个算法,最大子矩阵和,最长上升子序列。

先看题好啦。

A - To The Max

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.

As an example, the maximal sub-rectangle of the array:

0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2

is in the lower left corner:

9 2
-4 1
-1 8

and has a sum of 15.

 

Input

The input consists of an N x N array of integers. The input begins with a single positive integer N on a line by itself, indicating the size of the square two-dimensional array. This is followed by N 2 integers separated by whitespace (spaces and newlines). These are the N 2 integers of the array, presented in row-major order. That is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. N may be as large as 100. The numbers in the array will be in the range [-127,127].
 

Output

Output the sum of the maximal sub-rectangle.
 

Sample Input

4
0 -2  -7  0
9  2 -6  2
-4  1 -4  1
-1  8  0  -2 

Sample Output

15
 找最大子矩阵和,方法就是将矩阵按行压缩为一维矩阵,在该一维矩阵中找最大子段和,具体实施过程是(4 *4矩阵)第一行最大子段和记录,1 2 行压缩后找出最大子段和,与前面找到的比较留下较大的。1 2 3行  1 2 3 4行  第2行  2 3  行2 3 4 行。。。。。。依次遍历整个矩阵。
#include<stdio.h>
#include<string.h>
int a[][];
int b[];
int f(int a[],int n);
int main()
{ int i,j,k,n,temp,ans ;
while(scanf("%d",&n) != EOF)
{
for(i = ;i < n;i++)
{
for(j = ;j < n;j++)
scanf("%d",&a[i][j]);
}
temp=ans=-0x7fffff;
for(i = ;i < n;i++)
{
memset(b,,sizeof(b));
for(j = i;j < n;j++)
{
for(k = ;k < n;k++)
{
b[k] += a[j][k];
}
temp = f(b,n);
if(ans < temp) ans =temp;
}
}
printf("%d\n",ans);
} return ;
}
int f(int a[],int n)
{
int max = a[],ans,i,j;
for(i = ;i < n;i++)
{
if(max < a[i])max = a[i];
}
if(max < )return max;
else
{
int sum = ;
for(i = ;i < n;i++)
{
sum += a[i];
if(sum > max)max = sum;
else if(sum < )sum = ;
}
}
return max;
}
B - Stock Exchange

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for rising trends. Given a sequence of numbers p1, p2,...,pn representing stock prices, a rising trend is a subsequence pi1 < pi2 < ... < pik, with i1 < i2 < ... < ik. John’s problem is to find very quickly the longest rising trend.

Input

Each data set in the file stands for a particular set of stock prices. A data set starts with the length L (L ≤ 100000) of the sequence of numbers, followed by the numbers (a number fits a long integer). 
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.

Output

The program prints the length of the longest rising trend. 
For each set of data the program prints the result to the standard output from the beginning of a line.

Sample Input

6
5 2 1 4 5 3
3
1 1 1
4
4 3 2 1

Sample Output

3

1

1

Hint

There are three data sets. In the first case, the length L of the sequence is 6. The sequence is 5, 2, 1, 4, 5, 3. The result for the data set is the length of the longest rising trend: 3.
这个题就是最长上升子序列,只输出长度就好了,做法是:从前向后遍历数组(字符串)。先将第一个数放入结果数组里,然后遇见一个数如果比结果数组中最大的数还要大就直接放在最大的数的后面,如果不是,从前向后遍历数组知道找到一个比该数大的数为止,用这个数替换结果数组中第一个比他大的数。这里用的是二分法。
#include <iostream>
#include<stdio.h>
using namespace std;
int a[],b[],t;
void dog(int z)
{
int x,y,mid;
x=;
y=t;
while(x<=y)
{
mid=(x+y)/;
if (b[mid]==z) return ;//这里可以不return,令x = mid +1 即可
else
if (b[mid]>z) y=mid-;
else
x=mid+;
}
if (x==t+)//这里就是最大的直接放在后面
{
t++;
b[t]=z;
}
else
b[x]=z;
}
int main() {
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<=n;i++)
scanf("%d",&a[i]);
t=;
b[]=a[];
for(i=;i<=n;i++)
{
dog(a[i]);
}
printf("%d\n",t);
}
return ;
}
 
 

OUC_Summer Training_ DIV2_#12(DP1) 723的更多相关文章

  1. OUC_Summer Training_ DIV2_#13 723afternoon

    A - Shaass and Oskols Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  2. OUC_Summer Training_ DIV2_#9 719

    其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念. B - B Time L ...

  3. OUC_Summer Training_ DIV2_#5

    这是做的最好的一次了一共做了4道题  嘻嘻~ A - Game Outcome Time Limit:2000MS     Memory Limit:262144KB     64bit IO For ...

  4. OUC_Summer Training_ DIV2_#16 725

    今天做了这两道题真的好高兴啊!!我一直知道自己很渣,又贪玩不像别人那样用功,又没有别人有天赋.所以感觉在ACM也没有学到什么东西,没有多少进步.但是今天的B题告诉我,进步虽然不明显,但是只要坚持努力的 ...

  5. OUC_Summer Training_ DIV2_#14 724

    又落下好多题解啊...先把今天的写上好了. A - Snow Footprints Time Limit:1000MS     Memory Limit:262144KB     64bit IO F ...

  6. OUC_Summer Training_ DIV2_#2之解题策略 715

    这是第一天的CF,是的,我拖到了现在.恩忽视掉这个细节,其实这一篇只有一道题,因为这次一共做了3道题,只对了一道就是这一道,还有一道理解了的就是第一篇博客丑数那道,还有一道因为英语实在太拙计理解错了题 ...

  7. OUC_Summer Training_ DIV2_#7 718

    是18号做的题啦,现在才把报告补上是以前不重视报告的原因吧,不过现在真的很喜欢写报告,也希望能写一些有意义的东西出来. A - Dragons Time Limit:2000MS     Memory ...

  8. OUC_Summer Training_ DIV2_#11 722

    企鹅很忙系列~(可惜只会做3道题T_T) A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d &am ...

  9. OUC_Summer Training_ DIV2_#4之数据结构

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26100#problem/A A - A Time Limit:1000MS     Me ...

随机推荐

  1. 三种定位+堆叠+li小黑点变图片

    定位: 定位分为三种: position:static(默认值) relation(相对定位):进行较小偏移,不会脱离文档流,原位置保留 absolute(绝对定位):脱离文档流,不占据页面空间,变成 ...

  2. Dubbo 配置参数

    关闭启动检查 在dubbo多模块项目启动的时候为了并行启动多个服务,缩短启动时间,需要解除模块之间的依赖检测 dubbo.consumer.check=false @Reference(check = ...

  3. 使用LaTeX和KnitR自动生成报告

    扩展名为.Rnw(Rtex)的文件就是包含了R代码的LaTeX文档.编译的时候,先用Rscript调用Knitr处理,生成.TeX文档,然后用pdfLaTeX/XeLaTeX编译成PDF. 最方便的编 ...

  4. 使用jMeter构造大量并发HTTP请求进行微服务性能测试

    比如我开发好了一个微服务,想测试其在大并发请求下的性能表现如何. 比较方便的一个做法是使用工具jMeter来构造这些请求. 创建一个新的工程: 创建一个新的Thread Group,下图意思是这个工程 ...

  5. 如何正确清理C盘?

    Windows电脑操作系统一般是安装在磁盘驱动器的C盘中,一旦运行,便会产生许多垃圾文件,C盘空间在一定程度上都会越来越小.伴随着电脑工作的时间越久,C盘常常会提示显示其内存已不足.那么C盘容量不足对 ...

  6. eclipse新建jsp模版设置

    第一步:找到JSP模板 eclipse -- >perferences - >Web -> jsp files -Editor ->templates: 第二步:准备编辑JSP ...

  7. mysql大数据解决方案--分表分库(0)

    引言 对于一个大型的互联网应用,海量数据的存储和访问成为了系统设计的瓶颈问题,对于系统的稳定性和扩展性造成了极大的问题.通过数据切分来提高网站性能,横向扩展数据层已经成为架构研发人员首选的方式. •水 ...

  8. C# 委托、lambda表达式和事件 (7) 持续更新

    引用方法 在C++,函数指针只不过是一个指向内存位置的指针,它不是类型安全的. C# 委托 定义了返回类型和参数的类型.委托类包含对方法的引用,还可以包含多个方法引用. 定义委托 public del ...

  9. Xftp6 和 Xshell 6 下载与安装使用

    官网地址:https://www.netsarang.com/zh/all-downloads/ 然后进行安装吧,基本没有什么配置. 打开 xftp 连接 Linux,进行文件操作. 然后 名称:随意 ...

  10. oracle之约束-主键、非空、唯一、check、外键、默认

    --首先添加主键约束alter table studentadd constraint PK_student_sno primary key(sno) --删除约束alter table studen ...