一个N*N(1
C x1,y1,x2,y2 表示从x1行y1列到x2行y2列的元素全部反转(0变成1,1变成0);
Q x y表示询问x行y列的元素是0还是1。
题目乍一看感觉还是很难,如果能记录每一个元素的状态值,那答案是显而易见的,但是元素过多,如果每次都对每一个元素进行更新状态的话,复杂度太高。实际上只要记录边界的特定坐标的反转次数,最好的选择那就是二维树状数组了。
...
分类:
其他好文 时间:
2014-07-27 11:17:02
阅读次数:
215
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example, Given n = 3,You should return the followin...
分类:
其他好文 时间:
2014-07-27 10:21:02
阅读次数:
219
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1,...
分类:
其他好文 时间:
2014-07-27 10:16:02
阅读次数:
135
Given a m x n matrix, 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...
分类:
其他好文 时间:
2014-07-26 14:29:30
阅读次数:
183
题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.题解:这道题可以应用之前解过的Largetst Recta....
分类:
编程语言 时间:
2014-07-26 09:55:57
阅读次数:
301
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.题解,很巧妙的一道题,对于一个0-1矩阵,它的每一行及以上都可以看...
分类:
其他好文 时间:
2014-07-25 10:53:01
阅读次数:
292
通过itertools模块,可以用各种方式对数据进行循环操作1, chain()from intertools import chainfor i in chain([1,2,3], ('a', 'b', 'c'), 'abcde'): print ichain将可迭代的对象链接在一起,iter1循...
分类:
编程语言 时间:
2014-07-24 12:20:55
阅读次数:
255
累了就要写题解,最近总是被虐到没脾气。
来回最短路问题貌似也可以用DP来搞,不过拿费用流还是很方便的。
可以转化成求满流为2 的最小花费。一般做法为拆点,对于 i 拆为2*i 和 2*i+1,然后连一条流量为1(花费根据题意来定) 的边来控制每个点只能通过一次。
额外添加source和sink来控制满流为2。
代码都雷同,以HDU3376为例。
#include
#include
#...
分类:
其他好文 时间:
2014-07-23 22:40:08
阅读次数:
560
#pragma warning(disable:4996)
#include <cstdio>
#include <Windows.h>
#include <tchar.h>
#include <vector>
using namespace std;
/*
submit time : 2
1. Runtime Error
[]
request :
Given a ma...
分类:
其他好文 时间:
2014-07-23 21:34:35
阅读次数:
274