p1

[灵魂拷问♂]系列

痞子三分冷 提交于 2019-12-03 11:12:15
[灵魂拷问♂]系列 SP1043 GSS1 - Can you answer these queries I 题目: 链接 大致题意:求区间最大子段和,不带修改。 题解: 对于每个线段树节点。维护以下几个值: l, r:左右端点 sum:区间和 val:区间最大子段和 lv:一定包括区间左端点的最大子段和 rv:一定包括区间右端点的最大子段和 lv转移:lv = max(左儿子的lv, 左儿子的sum + 右儿子的lv) rv转移:rv = max(右儿子的rv,右儿子的sum + 左儿子的rv) val转移:val = max(max(左儿子的val, 右儿子的val), 左儿子rv + 右儿子lv) 这几种转移很好理解,就是分类讨论。 线段树的分类讨论无非就是都在mid左边的,都在mid右边的,横跨mid的。 注意,查询的时候。我们不能写成以下版本。 if(l <= mid) res = max(res, ask(p << 1, l, r)); if(r > mid) res = max(res, ask(p << 1 | 1, l, r)); return res; 因为这样写表达的含义就是指答案只来自于左区间和右区间。例如区间和、区间覆盖。但是当答案有来自于(取出左右区间的信息然后进行操作后得到的新信息)时,就要分三类讨论转移。 所以这题的查询代码如下 T ask(int

【漫画】什么是外部排序?【转】

爷,独闯天下 提交于 2019-12-03 09:53:56
漫画,什么是外部排序 还记得面试现场第一篇文章【面试现场】如何判断一个数是否在40亿个整数中?发出之后,最后蛋哥说把40亿个数先进行外部排序。有读者问到,内存无法一次性加载40亿个数,如何排序? 背景 西天取经的路上,一样上演着编程的乐趣..... (互联网侦察注:160亿字节大概是16G吧,20亿int32大概8G) 置换选择 例如我们可以从12个数据读取3个存到内存中,然后从内存中选出最小的那个数放进子串p1里; 之后再从在从剩余的9个数据读取一个放到内存中,然后再从内存中选出一个数放进子串p1里,这个数必须满足比p1中的其他数大,且在内存中尽量小。 这样一直重复,直到内存中的数都比p1中的数小,这时p1子串存放结束,继续来p2子串的存放。例如(这时假设内存只能存放3个int型数据): 12个无序的int数据 读入3个到内存中,且选出一个最小的到子串p1 从内存中再次读取一个元素86 从内存中再次读取一个元素3 从内存中再次读取一个元素24 从内存中再次读取一个元素8 这个时候,已经没有符合要求的数了,且内存已满,进而用p2子串来存放,以此类推。 通过这种方法,p1子串存放了4个数据,而原来的那种方法p1子串只能存放3个数据。 (不知道堆排序的可以看下我之前写的文章:【算法与数据结构】堆排序是什么鬼?) 从12个数据中读取3个数据,构建成一个最小堆

Python RandomForest - Unknown label Error

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have trouble using RandomForest fit function This is my training set P1 Tp1 IrrPOA Gz Drz2 0 0.0 7.7 0.0 -1.4 -0.3 1 0.0 7.7 0.0 -1.4 -0.3 2 ... ... ... ... ... 3 49.4 7.5 0.0 -1.4 -0.3 4 47.4 7.5 0.0 -1.4 -0.3 ... (10k rows) I want to predict P1 thanks to all the other variables using sklearn.ensemble RandomForest colsRes = ['P1'] X_train = train.drop(colsRes, axis = 1) Y_train = pd.DataFrame(train[colsRes]) rf = RandomForestClassifier(n_estimators=100) rf.fit(X_train, Y_train) Here is the error I get: ValueError: Unknown label type:

Pyspark Join and then column select is showing unexpected output

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am not sure if the long work is doing this to me but I am seeing some unexpected behavior in spark 2.2.0 I have created a toy example as below toy_df = spark . createDataFrame ([ [ 'p1' , 'a' ], [ 'p1' , 'b' ], [ 'p1' , 'c' ], [ 'p2' , 'a' ], [ 'p2' , 'b' ], [ 'p2' , 'd' ]], schema =[ 'patient' , 'drug' ]) I create another dataframe mdf = toy_df . filter ( toy_df . drug == 'c' ) as you know mdf would be mdf . show () +-------+----+ | patient | drug | +-------+----+ | p1 | c | +-------+----+ Now If I do this toy_df . join ( mdf ,[

Error in grid.arrange - arrangeGrob() function

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have two plots p1 and p2 which I am trying to plot using grid.arrage. My code looks as below: grid.arrange(p1, p2, ncol=2, top = textGrob("Distribution across each day of the week", gp = gpar(fontface = "bold", cex = 1.5)), bottom = "Day of the week") However, when I run this, I am seeing an error "Error in arrangeGrob(...) : could not find function "textGrob" When I run only grid.arrange(p1, p2, ncol=2) , it runs fine. But without any labels and title. However, I couldnt understand what is the problem with my code. I tried both main=...

【SQL练习题】排序

匿名 (未验证) 提交于 2019-12-03 00:32:02
原表如下: 建表脚本: CREATE TABLE districtproducts ( district varchar(255), name varchar(255), price int(255) ); INSERT INTO districtproducts VALUES ('东北', '橘子', 100); INSERT INTO districtproducts VALUES ('东北', '苹果', 50); INSERT INTO districtproducts VALUES ('东北', '葡萄', 50); INSERT INTO districtproducts VALUES ('东北', '柠檬', 30); INSERT INTO districtproducts VALUES ('关东', '柠檬', 100); INSERT INTO districtproducts VALUES ('关东', '菠萝', 100); INSERT INTO districtproducts VALUES ('关东', '苹果', 100); INSERT INTO districtproducts VALUES ('关东', '葡萄', 70); INSERT INTO districtproducts VALUES ('关西', '柠檬', 70); INSERT

初探KVO

匿名 (未验证) 提交于 2019-12-03 00:22:01
概述 KVO 的具体实现 具体实现代码如下: #import "ViewController.h" #import "Person.h" @interface ViewController () /** p1 */ @property ( strong , nonatomic ) Person *p1; @end @implementation ViewController - ( void )viewDidLoad { super viewDidLoad]; // 1.什么是通知 // 3个对象 self .p1 = [[Person alloc] init]; self .p1 .name = @"p1" ; // KVO是监听对象的属性值的改变的 self .p1 addObserver: self forKeyPath: @"name" options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: nil ]; self .p1 .name = @"123" ; } // 这个方法时属于 NSObject 类的,任何对象都可以作为观察者 - ( void )observeValueForKeyPath:( NSString *)keyPath ofObject:( id

【模板】最小圆覆盖

匿名 (未验证) 提交于 2019-12-03 00:13:02
P1742 最小圆覆盖 题目描述 给出N个点,让你画一个最小的包含所有点的圆。 输入格式 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) 输出格式 输出圆的半径,及圆心的坐标,保留10位小数 输入输出样例 6 8.0 9.0 4.0 7.5 1.0 2.0 5.1 8.7 9.0 2.0 4.5 1.0 输出 #1 5.0000000000 5.0000000000 5.0000000000 说明/提示 5.00 5.00 5.0 随机数处理复杂度为O(n) 第一个点定为圆心; 第二个点和第一个点的连线的中点定位圆心,距离为直径; 第三个点要和前两个点进行三点定圆; #pragma GCC optimize ( 2 ) #pragma GCC optimize ( 3 , "Ofast" , "inline" ) #include < bits / stdc ++. h > //O(n) #define ll long long #define met ( a , x ) memset ( a , x , sizeof ( a )) #define inf 0x3f3f3f3f #define ull unsigned long long using namespace std ; const double

多线程队列实现并发(做包子和吃包子)

匿名 (未验证) 提交于 2019-12-02 23:43:01
之前写过一个 用python生成器实现单线程并发(做包子和吃包子) 参看 https://blog.csdn.net/csdniter/article/details/90723175 现在用多线程队列再实现一下: import time import threading #线程模块 import queue #队列模块 q = queue . Queue ( 10 ) #创建一个队列对象,允许放10个数据,不限类型 def produce_baozi ( name ) : for i in range ( 1 , 11 ) : time . sleep ( 1 ) print ( "%s的第%s个包子做好了" % ( name , i ) ) q . put ( i ) q . task_done ( ) #线程间通信 def consume_baozi ( name ) : for i in range ( 1 , 11 ) : q . join ( ) date = q . get ( ) time . sleep ( 1 ) print ( "%s吃了第%s个包子" % ( name , date ) ) p1 = threading . Thread ( target = produce_baozi , args = ( "p1" , ) ) c2 = threading

[C#] LINQ֮SelectMany

匿名 (未验证) 提交于 2019-12-02 22:06:11
声明:本文为 www.cnc6.cn 原创,转载时请注明出处,谢谢! 一、第一种用法: public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector); 废话不多说,直接Post上代码: 1,编写Person类: class Person { public string Name { set; get; } public int Age { set; get; } public string Gender { set; get; } public Dog[] Dogs { set; get; } } 2,编写Dog类: public class Dog { public string Name { set; get; } } 请注意:在Person类里有一个Dog数组,用于存储实例化Person类所拥有的所有Dog集合,这里就是SelectMany的关键。 3、编写客户端试验代码: List<Person> personList = new List<Person> { new Person { Name = "P1", Age = 18, Gender =