链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The plant in the j-th column of the i-th row belongs the a[i][j]-th type. White Cloud wants to help Whi…
题目链接:https://www.nowcoder.com/acm/contest/180/D 线性基的学习:https://www.cnblogs.com/vb4896/p/6149022.html 链接:https://www.nowcoder.com/acm/contest/180/D来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 小a有n个数,他提出了一个很有意思的…
不懂hash的话:https://www.cnblogs.com/ALINGMAOMAO/p/10345850.html 思路:对于一个大矩阵的每一个子矩阵都对应着一个hash值k, 当k出现2次以上时就满足要求 只是对长度进行二分就可以了. 收获:学会了hash算法 #include<iostream> #include<map> using namespace std; #define ll long long #define ull unsigned long long ;…
题目:http://www.nowcoder.com/practice/8ee967e43c2c4ec193b040ea7fbb10b8 C++ 负数需要特殊处理,因为负数右移会补1(符号位) class Solution { public: int NumberOf1(int n) { unsigned int v = n; ; while (v) { sum += v&; v >>= ; } return sum; } };…
题目:http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e C++ class Solution { public: bool Find(vector<vector<int> > array,int target) { int rows = array.size(); ].size(); ; ; && y < rows ) { if (array[x][y] == target) r…
顺时针打印矩阵 牛客网 剑指Offer 题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10. class Solution: #run:33ms memory:5712k def printMatrix(self, matrix): if matrix is None:…
题意 n*m的农场有若干种不同种类作物,如果作物接受了不同种类的肥料就会枯萎.现在进行t次施肥,每次对一个矩形区域施某种类的肥料.问最后枯萎的作物是多少. 分析 作者:xseventh链接:https://www.nowcoder.com/discuss/87630?type=101来源:牛客网 我们通过差分(其实就是二维前缀和)可以在O(nm)的时间求出每个点被撒了几次肥料 然后我们可以对每种植物分开求被撒了几次相同种类的肥料,然后判断被撒肥料的次数是否等于被撒的相同种类肥料的次数来确定这个植…
链接:https://ac.nowcoder.com/acm/contest/558/C来源:牛客网 小猫在研究二元组. 小猫在研究最大值. 给定N个二元组(a1,b1),(a2,b2),…,(aN,bN),请你从中选出恰好K个,使得ai的最小值与bi的最小值之和最大. 请输出ai的最小值与bi的最小值之和 输入描述: 第一行两个正整数N,K,表示二元组数量与需要选的数量. 接下来N行,第i行两个正整数ai,bi. 输出描述: 一行一个正整数,表示最大的a_i的最小值与b_i的最小值之和. 示例…
算法题 19 二叉平衡树检查 牛客网 CC150 实现一个函数,检查二叉树是否平衡,平衡的定义如下,对于树中的任意一个结点,其两颗子树的高度差不超过1. 给定指向树根结点的指针TreeNode* root,请返回一个bool,代表这棵树是否平衡. 解题代码:时间复杂度为O(NlogN) N为树中的节点数 # -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = No…
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, find out the K-th minimum weighted clique. A subset of vertices of an undirected graph is called clique if and only if every two distinct vertices in th…