pipe

[USACO09JAN]全流Total Flow

最后都变了- 提交于 2020-01-31 12:46:52
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different size pipes connected in an apparently haphazard way. He wants to calculate the flow through the pipes. Two pipes connected in a row allow water flow that is the minimum of the values of the two pipe's flow values. The example of a pipe with flow capacity 5 connecting to a pipe of flow capacity 3 can be reduced logically to a single pipe of flow capacity 3: +---5---+---3---+ -> +-

AC日记——[USACO09JAN]全流Total Flow 洛谷 P2936

隐身守侯 提交于 2020-01-31 12:45:11
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different size pipes connected in an apparently haphazard way. He wants to calculate the flow through the pipes. Two pipes connected in a row allow water flow that is the minimum of the values of the two pipe's flow values. The example of a pipe with flow capacity 5 connecting to a pipe of flow capacity 3 can be reduced logically to a single pipe of flow capacity 3: +---5---+---3---+ -> +-

NIO管道(Pipe)

限于喜欢 提交于 2020-01-31 11:19:44
Java NIO 管道是2个线程之间的单向数据连接。Pipe有一个source通道和一个sink通道。数据会被写到sink通道,从source通道读取。 @Test public void test1() throws IOException{ //1. 获取管道 Pipe pipe = Pipe.open(); //2. 将缓冲区中的数据写入管道 ByteBuffer buf = ByteBuffer.allocate(1024); Pipe.SinkChannel sinkChannel = pipe.sink(); buf.put("通过单向管道发送数据".getBytes()); buf.flip(); sinkChannel.write(buf); //3. 读取缓冲区中的数据 Pipe.SourceChannel sourceChannel = pipe.source(); buf.flip(); int len = sourceChannel.read(buf); System.out.println(new String(buf.array(), 0, len)); sourceChannel.close(); sinkChannel.close(); } 来源: CSDN 作者: 存在,及合理 链接: https://blog.csdn.net/qq

Redis 3. 与python交互

孤街浪徒 提交于 2020-01-30 10:20:33
3. 与python交互 安装包 到 中文官网 查找客户端代码 联网安装 sudo pip install redis 使用源码安装 unzip redis-py-master.zip cd redis-py-master sudo python setup.py install 交互代码 引入模块 import redis 连接 try: r=redis.StrictRedis(host='localhost',port=6379) except Exception,e: print e.message 方式一:根据数据类型的不同,调用相应的方法,完成读写 更多方法同前面学的命令 r.set('name','hello') r.get('name') 方式二:pipline 缓冲多条命令,然后一次性执行,减少服务器-客户端之间TCP数据库包,从而提高效率 pipe = r.pipeline() pipe.set('name', 'world') pipe.get('name') pipe.execute() 封装 连接redis服务器部分是一致的 这里将string类型的读写进行封装 import redis class RedisHelper(object): def __init__(self, host='localhost', port=6379): self._

Bash - Initialize variable to output of command “permission denied”

会有一股神秘感。 提交于 2020-01-30 08:54:25
问题 I'm writing a small bash script to get the number out of each file name. For example the file name helloworld1.txt would produce 1 . When attempting to set the output to the variable i I get an error for each file. line 5: 985.txt: Permission denied If I just echo the command echo $f | tr -dc '[0-9]' rather than assign it to a variable, everything is good. #!/bin/bash for f in * do i=`$f | tr -dc '[0-9]'` // Permission denied. echo $i done 回答1: You have missed echo here. The line i=`$f | tr

进程间通信

試著忘記壹切 提交于 2020-01-28 07:53:03
【进程间通信】 进程间由于空间独立,资源互相无法直接获取 此时在不同的进程间传递数据就需要专门的进程间通信方法 和磁盘交互: 使用中间文件,但是不安全,速度慢 进程间通信方法(IPC): 管道、消息队列、共享内存、信号、信号量、套接字 【管道通信Pipe】 1.原理: 在内存中开辟一块空间,形成管道结构,管道对多个进程可见,进程可以通过对管道的读写操作进行通信 2.[multiprocessing.Pipe] 1.fd1,fd2 = Pipe(duplex=True) 功能:创建一个管道 参数: duplex默认为True 表示双向管道 设置为False 表示单项管道 返回值: 返回两个管道流对象,表示管道两端 如果是双向管道,则都可以读写 如果是单向管道,则fd1只读 fd2只写 2.fd1.recv() 功能:从管道内读取信息 参数:无 返回值:读到的内容 注意:当管道内无内容的时候会阻塞 3.fd2.send(data) 功能:向管道写入内容 参数:要写的内容 注意:可以发送几乎python的任意数据类型 3.示例(双向管道): from multiprocessing import Process,Pipe import os,time # 创建管道 fd1,fd2 = Pipe() def fun(name): time.sleep(3) # 向管道内写入内容 fd2

Creating a multi-level pipe for Linux commands

早过忘川 提交于 2020-01-25 08:03:14
问题 I'm trying to create a multi-level pipe, where the input is Linux commands (e.g. ls | sort) and the output is just the regular output when typed into a Linux console (essentially just use execlp to execute the commands). I've attempted to create a program that works for 1 and 2 levels, but I can't seem to get the 2 level one to work, specifically with the command "ls | sort". The program just freezes. I also don't know how to continue beyond that and add more levels (required to support 16

Exclude or include the particular row from the mat-table view

一个人想着一个人 提交于 2020-01-25 07:48:07
问题 I have a material data table like id title description The data source for my mat-table is represented by dataSource$: Observable<Thing[]> <mat-table #table [dataSource]="dataSource$ | async"> ... <mat-table> Based on a dropdown I want to be able to show all the data(the way it works at the moment) but also to hide the items that have description empty and way around hide the items that have description not empty. I think I have to do that through the custom pipe? or use a .filter() on my

How can I tell if there is new data on a pipe?

泄露秘密 提交于 2020-01-25 03:45:09
问题 I'm working on Windows, and I'm trying to learn pipes, and how they work. One thing I haven't found is how can I tell if there is new data on a pipe (from the child/receiver end of the pipe? The usual method is to have a thread which reads the data, and sends it to be processed: void GetDataThread() { while(notDone) { BOOL result = ReadFile (pipe_handle, buffer, buffer_size, &bytes_read, NULL); if (result) DoSomethingWithTheData(buffer, bytes_read); else Fail(); } } The problem is that the

Python multiprocess non-blocking intercommunication using Pipes

旧城冷巷雨未停 提交于 2020-01-24 12:48:20
问题 Is it possible to receive process intercommunications using Pipes in a non-blocking fashion? Consider the following code: from multiprocessing import Process, Pipe import time def f(conn): time.sleep(3) conn.send('Done') conn.close() if __name__ == '__main__': parent_conn, child_conn = Pipe() p = Process(target=f, args=(child_conn,)) p.start() while True: print('Test') msg = parent_conn.recv() if msg == 'Done': break print('The End') p.join() The parent_conn.recv() will block the while-loop