ICode9

精准搜索请尝试: 精确搜索
  • 最小栈问题2019-08-09 09:06:29

    题目:如何实现一个栈,既存在基本的push pop操作,又可以有getMin操作,注:元素均是int型 原始方法:维持一个变量,使之保存入栈的最小值,当第一个最小值出去后,遍历剩下的栈元素并更新最小值变量,这种算法pop的时间复杂度是O(n),其他操作的时间复杂度都是O(1),空间复杂度是O(1); 改进1:如果可以申

  • CCF-中间数2019-07-27 09:42:57

    #include<iostream> #include<cmath> #include<algorithm> #include<string> #include<vector> #include<cstdio> #include<cstring> #include<queue> using namespace std; int main() { int n; cin>>n; int *a=ne

  • 【Python、练习题】自定义栈,并实现O(1)查找最值方法2019-04-26 12:48:39

    以查找最小值为例 class MyStack: def __init__(self): self.values = [] self.mins = [] def push(self, ins): if not self.mins: self.mins.append((0, ins)) elif ins < self.mins[-1][1]: self.mins.

  • CodeForces - 621A Wet Shark and Odd and Even2019-04-10 15:48:07

    题目: 传送门 思路: 保证 sum 结果为 偶数,则 a[i] 为偶数 ,一定可以加上 . 如果a[I]为奇数,我们先把其放进奇数之和里,如果最后奇数之和为偶数,直接加上,反正,减去最小的奇数即可。 #include <iostream> #include <algorithm> using namespace std; long long ans = 0; long long

  • P1460 健康的荷斯坦奶牛 Healthy(DFS)2019-04-06 16:40:52

    思路:这道题还是用了小小的剪枝,这里要注意的是该题有很多中构建树的顺序,但是,在这众多顺序中不一定都能保证输出的方案字典序最小。 构建搜索树:如图构建       剪枝,emmm,看代码: #include<iostream>using namespace std;int a[20][30];int b[30], an[30], mm[20], gg[20];int n,

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有