num

Codeforces Round #618 (Div. 2)

谁说胖子不能爱 提交于 2020-03-09 01:19:40
QAQ : 我太难了 A. Even But Not Even 题意: 给你一个长度为 n 的数组 a, 你可把其中一个数的值加一,这个操作你可以做无数次,要求最后的数组之和不等于零,数组之积不等于 0 ,输出所需最小的操作数。 思路: 暴力模拟即可,要求数组中不能有 0 ,和不等于 0 。 代码: #include <bits/stdc++.h> using namespace std; int num[105]; int main() { int T; scanf("%d",&T); while(T--) { int n; cin >> n; int sum = 0,ans = 0; for(int i = 0;i<n;++i) { cin >> num[i]; if(num[i]==0) { ans++; sum+=1; } else { sum+=num[i]; } } if(sum!=0) printf("%d\n",ans); else printf("%d\n",ans+1); } return 0; } B. Array Sharpening 题意: 给你一个数组 n,n 保证是个偶数,将这两个数组划分为等大小的两个数组,使这两个数组中位数之差的绝对值最小。输出这个最小值。 思路: 将数组从小到大排序,答案就是位于中间的两个数差的绝对值。 代码: #include

01: 数组

我们两清 提交于 2020-03-09 00:39:53
算法面试其他篇 目录: 1.1 简单数组题   1、去除列表中相加等于指定数后的列表(x+y=4)       [1,3,5,7,1,2] ==> [5,7,1,2] [1,3,3,5,7,1,2] ==> [3,5,7,1,2] #! /usr/bin/env python # -*- coding: utf-8 -*- def func(l, tag=4): for i in range(len(l)): a = l[i] if a != None: b = tag - a try: index = l.index(b) if index != i: # 避免 2 + 2 = 4只有一个2也没重置为None l[i] = None l[index] = None else: if l.count(b) > 2: # 如果有两个就都重置为 None l[i] = None l[l.index(b)] = None except Exception as e: pass print l # [None, None, 5, 7, 1, 2] while None in l: l.remove(None) return l # [5, 7, 1, 2] l = [1,3,5,7,1,2] print func(l, 4) ''' [1,3,5,7,1,2] [None, None, 5

自动生成构造器,存储过程参数

戏子无情 提交于 2020-03-09 00:03:48
发现写构造器和存储过程参数太麻烦,写了个自动生成的(根据表名) /* 文件头 文件名:TableTask.cs,WebconfigSetTask 存储路径:SqlServerTask 作者:Far.v 建立日期及时间:2008-04-26 9:20 最后修改日期及时间:2008-05-01 11:30 文件功能描述:业务逻辑层 备注: */ namespace SqlServerTask { using System; using System.Data; using System.Data.SqlClient; public class TableTask { private string Parm_Table = "@table"; private string pope; public string ColattStr(string popestr) { switch (popestr) { case "167": return "VarChar"; case "56": return "Int"; case "48": return "TinyInt"; case "104": return "Bit"; case "61": return "DateTime"; case "52": return "SmallInt"; case "127": return

C#索引器理解

岁酱吖の 提交于 2020-03-08 23:59:09
C#索引器介绍举例 索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的。 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 (3)索引器不是一个变量 索引器和属性的不同点 (1)属性以名称来标识,索引器以函数形式标识 (2)索引器可以被重载,属性不可以 (3)索引器不能声明为static,属性可以 一个简单的索引器例子 using System; using System.Collections; public class IndexerClass { private string[] name = new string[2]; //索引器必须以this关键字定义,其实这个this就是类实例化之后的对象 public string this[int index] { //实现索引器的get方法 get { if (index < 2) { return name[index]; } return null; } //实现索引器的set方法 set { if (index < 2) { name[index] = value; } } } } public class Test { static void Main() { //索引器的使用 IndexerClass Indexer =

leetcode 【 Find Minimum in Rotated Sorted Array 】python 实现

生来就可爱ヽ(ⅴ<●) 提交于 2020-03-08 23:56:27
题目 : Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2 ). Find the minimum element. You may assume no duplicate exists in the array. 代码 :oj测试通过 Runtime: 52 ms 1 class Solution: 2 # @param num, a list of integer 3 # @return an integer 4 def findMin(self, num): 5 # none case 6 if num is None: 7 return None 8 # short lenght case 9 if len(num)==1 : 10 return num[0] 11 # binary search 12 start = 0 13 end = len(num)-1 14 while start<=end : 15 if start==end : 16 return num[start] 17 if start+1==end : 18 return min(num[start],num

Leetcode刷题笔记(部分非原创)(1-20题)

怎甘沉沦 提交于 2020-03-08 23:49:56
1. Two Sum leetcode链接: https://oj.leetcode.com/problems/two-sum/ 最基础的一道题,方法很多,用HashMap存pair是一种(HashSet和HashMap的方法在这里原理是一样的)。也可以sort the whole array first,then use two pointers, one start from the left side, the other from the right side. if array[left]+array[right]>target, move the right index to the left by 1, 小于的话同理. 这里给一个HashMap的方法。 1 public int[] twoSum(int[] numbers, int target) { 2 HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); 3 int[] result = new int[2]; 4 for(int i = 0; i < numbers.length; i++) { 5 if(map.containsKey(numbers[i])) { 6 int index = map.get(numbers[i]);

【leetcode】Find Minimum in Rotated Sorted Array I&&II

冷暖自知 提交于 2020-03-08 23:44:41
题目概述: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the array. 解题思路: 在一个有顺序的数组中查找个最小值,很容易想到的就是二分法,的确,这里用的就是二分,不过要做一点改进。 改进的思路是这样的: 1.我们容易想到最好的情况就是这个数组是普通的排好序的,如【1,2,3,4】,那么最小的必然是下标最小的。用旋转的情况假设第一个小于最后一个那么最小值肯定也是第一个,也就是说计算过程中只要找到left<right的结果就出来了 2、如果这里面出现了rotate的话,如【3,4,1,2】那么最小值肯定会出现在左右的一遍,那么到底是哪边呢,这里我们可以比较最左和最后值的大小,比如这里`3="">2 说明在这里前面的那个3是旋转过去的。这是后我们就要用中间那个值,这里是 (0+3)/2=1`这里4>2(right)说明最小值应该实在后半块里的,于是乎改left就好。反之是改right就是一样的过程了,就是一个二分的思想 1 class

生产者与消费者 升级

倾然丶 夕夏残阳落幕 提交于 2020-03-08 20:26:28
/** * @DESCRIPTION: * Sychronized wait notifyAll * 注意: while来判断唤醒条件 if会引起 虚假唤醒 * @Author: WangLt * @Date: 2020/3/8 */ @SuppressWarnings ( "all" ) public class SellerAndBuyer { public static void main ( String [ ] args ) { Data data = new Data ( ) ; new Thread ( ( ) - > { for ( int i = 0 ; i < 10 ; i ++ ) { try { data . decrement ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } , "T1" ) . start ( ) ; new Thread ( ( ) - > { for ( int i = 0 ; i < 10 ; i ++ ) { try { data . increment ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } , "T2" ) .

redis语法与命令

给你一囗甜甜゛ 提交于 2020-03-08 19:04:36
一、简述 Redis支持的键值类型有:String字符类型、map散列类型、list列表类型、set集合类型、sortedset有序集合类型。接下来对这些键值类型在使用上进行总结,并介绍下Keys命令,虽然语法简单,但由于数量过多,还需要我们多多实践。 二、String字符类型 1、赋值 语法:SET key value 127.0.0.1:6379> set test 123 OK 2、取值 语法:GET key 127.0.0.1:6379> get test "123“ 3、取值并赋值 语法:GETSET key value 127.0.0.1:6379> getset s2 222 "111" 127.0.0.1:6379> get s2 "222" 4、设置/获取多个键值 语法: MSET key value [key value …] MGET key [key …] 127.0.0.1:6379> mset k1 v1 k2 v2 k3 v3 OK 127.0.0.1:6379> get k1 "v1" 127.0.0.1:6379> mget k1 k3 1) "v1" 2) "v3" 5、删除 语法:DEL key 127.0.0.1:6379> del test (integer) 1 6、数值增减 a. 递增数字 当存储的字符串是整数时

python 中的字符串使用总结

蓝咒 提交于 2020-03-08 18:30:50
一、 Python 的 优点 二、 python 的安装 https://www.python.org/downloads/ 点击第二行(cu…)自定义安装 选中all-users 选择安装路径(不要有中文,不要有空格) 可以更换盘 三、【环境变量配置】:打开电脑属性 进入高级设置 选择环境变量 新建系统变量 【变量名字:PYTHON_HOME】、【变量值:python所在的路径】、在环境变量中找到Path 选择编辑 更改变量值【%PYTHON_HOME%;】 四、变量的组成由:变量名、赋值符号、变量值。 五、Python 中的标识符和关键字:标识符由字母、下划线和数字组成。切记数字不能开头。 六、命名规则《见名知意、驼峰命名》myMotherName=”xxx” 七、单个单词不用大写 、两个以上 从第二个单词每个首字母大写 八、Python 变 量 和 数 据 类 型 九、.查看关键字 步骤:python import keyword -> keyword.kwlist [‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’,