You are given annxn2D matrix representing an
image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this
in-place?思路:先将矩阵转置,然后将第一列与最后...
分类:
其他好文 时间:
2014-05-14 03:09:35
阅读次数:
225
我觉得这个题好无聊啊,好端端一个数组,干嘛要跟比巴卜一样转一圈输出呢。。
思想很简单,每次从左到右,再从上到下,在从右到左,再从下到上。问题是每次到什么时候该改变方向。我的做法是用一个变量保存当前在第几层,这个层是相对于从外向内有几圈来说的。注意想清楚边界的话这个题一点也不难。有个细节,我的循环退出条件是访问的数跟矩阵总个数之间的关系,如果有一次在判断进入循环是条件是满足的,但是在循环内部不满足...
分类:
其他好文 时间:
2014-05-13 15:20:19
阅读次数:
229
Pat1044代码
题目描述:
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can...
分类:
其他好文 时间:
2014-05-13 14:33:08
阅读次数:
437
作图方法:
1. 先画出规则的圆环套圆环;
2. 然后把它们组合起来关于某个圆进行inversion操作,又叫反演,或者关于圆的反射;
图示为改变小圆的个数动态观察的结果....
分类:
其他好文 时间:
2014-05-13 07:56:52
阅读次数:
225
#include
//using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator+(Matrix &,Matrix &);
friend ostream& operator
friend istream& operator>>(istream&,Matri...
分类:
其他好文 时间:
2014-05-12 22:39:15
阅读次数:
387
Spiral MatrixGiven a matrix ofmxnelements
(mrows,ncolumns), return all elements of the matrix in spiral order.For
example,Given the following matrix:[...
分类:
其他好文 时间:
2014-05-12 20:04:43
阅读次数:
268
Given an integern, generate a square matrix
filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should
return the following matri...
分类:
其他好文 时间:
2014-05-12 19:53:23
阅读次数:
332
原文第22章 职责链模式(Chain of Responsibility)职责链模式
导读:职责链模式是一个既简单又复杂的设计模式,刚开始学习这个设计模式的时候光示例都看了好几遍。就为了理清里面的逻辑走向。是个值得慢慢品味的设计模式 概述:
使多个对象都有机会处理请求,从而避免请求的发送者和接...
分类:
其他好文 时间:
2014-05-12 08:23:52
阅读次数:
294
Given amxnmatrix, if an element is 0, set its
entire row and column to 0. Do it in place.click to show follow up.Follow up:Did
you use extra space?A s...
分类:
其他好文 时间:
2014-05-12 08:22:51
阅读次数:
255
这个题乍一看很简单,实际上还挺有技巧的。我最开始的想法是找一个特殊值标记,遇到一个0,把他所对应的行列中非零的元素标记成这个特殊值,0值保持不变,然后再从头遍历一次,碰到特殊值就转化成0。
问题是这个特殊值怎么确定,题目中没有把取值范围给出,我怀着侥幸的心理用了最大和最小的int,都被揪了出来。。如果找一个不存在于数组中的值,这个复杂度太高了。
有没有其他更好的方法呢?当然有。这个思想很巧妙,...
分类:
其他好文 时间:
2014-05-12 06:54:39
阅读次数:
193