tmp

hdu 4812 树分治+逆元+手写hashmap

◇◆丶佛笑我妖孽 提交于 2019-11-30 11:54:27
a*b%mod==k等价于k*inv(b)%mod==a 然后树分治,用hashmap记录即可,unorder_map/map貌似会TLE,我手写了一个 注意这个小范围的逆元可以直接线性处理 复杂度$nlogn*hashmap$ #include<bits/stdc++.h> #define ll long long #define rep(ii,a,b) for(int ii=a;ii<=b;++ii) #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define fi first #define se second #define mp make_pair #define pii pair<ll,ll> using namespace std; const int maxn=1e6+10,maxm=2e6+10; const ll INF=0x88888888,mod=1e6+3; int casn,n,m,k; ll val[maxn],inv[maxn]; const int maxsz=4e6+9;//@素数表@:1e7+19,2e7+3,3e7+23 //1e6+3,2e6+3,3e6+7,4e6+9,1e5+3,2e5+3,3e5+7,4e5+9 //@要保证取值的操作次数小于maxsz

Store file in directory tmp on heroku Rails

℡╲_俬逩灬. 提交于 2019-11-30 11:37:51
In my Delayed Job, I tried to create a file to tmp folder file_path = Rails.root.join('tmp', "#{file_name}." + file_extension); exported_file = kit.to_pdf # Save file to disk File.open(file_path, 'wb') do |file| file << exported_file end It works well in local but on Heroku there is a error in Delayed Job "No such file or directory - /app/tmp/test.pdf" So how I can solve this problem. I do not want to store file in S3. Thank you Heroku uses what is called an ephemeral filesystem . This means that your local filesystem is only accessible to a single dyno, and once the dyno is stopped, restarted

Python程序练习题(一)

拈花ヽ惹草 提交于 2019-11-30 06:18:03
Python :程序练习题(一) 1.2 整数序列求和。用户输入一个正整数 N ,计算从 1 到 N (包含 1 和 N )相加之后的结果。 代码如下: n=input("请输入整数N:") sum=0 for i in range(int(n)): sum+=i+1 print("1到N求和结果:",sum) 知识点整理: 输入: < 变量 >=input(< 提示性文字 >) ,获得用户的输入,以字符串形式保存在 < 变量 > 中。 计数循环: for i in range(< 计数值 >)           < 表达式 > 运行结果: 1.3 九九乘法表输出。工整打印输出常用的九九乘法表,格式不限。 代码如下: for i in range(1,10): for j in range(1,i+1): print("{}*{}={:2}".format(j,i,i*j),end=' ') print('') 知识点整理: 上 面的 代码使用了两个循环的嵌套 , for 循环每执行完一次就跳出。 代码详解:首先,进入 i 的 for 循环,此时 i=1, 到达 j 的 for 循环,此时 j=1 , i+1 变为 2 ,进入 j 的 for 循环,循环打印出结果 1x1=1 ( end= ’ ’ 表示不换行,输出空格为了排版整齐), j 的 for 循环执行完跳出,到达 i 的

用栈实现队列

你离开我真会死。 提交于 2019-11-30 05:51:25
具体思路: 通过两个栈来模拟 class MyQueue { public: /** Initialize your data structure here. */ stack<int>q1; stack<int>q2; MyQueue() { } /** Push element x to the back of queue. */ void push(int x) { while(!q2.empty()){ q1.push(q2.top()); q2.pop(); } q1.push(x); while(!q1.empty()){ q2.push(q1.top()); q1.pop(); } return ; } /** Removes the element from in front of queue and returns that element. */ int pop() { int tmp = 0; if(!q2.empty()){ tmp = q2.top(); q2.pop(); } return tmp; } /** Get the front element. */ int peek() { int tmp = 0; if(!q2.empty()){ tmp = q2.top(); } return tmp; } /** Returns whether

Javascript 交换两个变量的值

ぃ、小莉子 提交于 2019-11-30 05:39:44
概要  本文主要描述,如何不使用中间值,将两个变量的值进行交换。  前三种只适用于number类型的数值交换,第四和第五种适合其他类型。 一、普通做法 var a = 1, b = 2, tmp; tmp = a; a = b; b = tmp;  普通的做法就是声明多一个临时变量 tmp ,进行数据交换过程中的缓存。这样的做法直观,易懂。但是,会增加内存的使用。 二、算术运算 var a = 1, b = 2; a = a + b; // a = 3, b = 2 b = a - b; // a = 3, b = 1 a = a - b; // a = 2, b = 1  通过算术运算过程中的技巧,可以巧妙地将两个值进行互换。但是,有个缺点就是变量数据溢出。因为JavaScript能存储数字的精度范围是 -2 53 到 2 53 。所以,加法运算,会存在溢出的问题。 三、异或运算 var a = 1, // 二进制:0001 b = 2; // 二进制:0010 a = a ^ b; // 计算结果:a = 0011, b = 0010 b = a ^ b; // 计算结果:a = 0011, b = 0001 a = a ^ b; // 计算结果:a = 0010, b = 0001  本题巧用位运算的技巧,利用 a ^ b ^ b == a 的特点,进行数值交换

shell重定向的顺序问题

旧街凉风 提交于 2019-11-30 05:27:58
三个默认的文件描述符 0 : stdin(标准输入) 1 : stdout(标准输出) 2 : stderr(标准错误输出) 系统中这3个文件描述符所对应的文件: 重定向顺序 示例脚本 echo "hello world" echo "xxx" sh test.sh hello world xxx sh test.sh >/tmp/out $ cat /tmp/out hello world xxx sh -x test.sh >/tmp/out 2>/tmp/err stdout和stderr分别被重定向到/tmp/out和/tmp/err。 $ cat /tmp/out hello world xxx $ cat /tmp/err + echo 'hello world' + echo xxx sh -x test.sh 2>&1 >/tmp/out stdout被重定向到/tmp/out,stderr被重定向到stdout。因为在执行2>&1的时候,stdout对应的文件为/dev/pts/2,所以stderr的输出仍为stdout,后面的stdout被重定向到/tmp/out。 $ sh -x test.sh 2>&1 >/tmp/out + echo 'hello world' + echo xxx $ cat /tmp/out hello world xxx 文件描述符

leetcode 2 两数相加

99封情书 提交于 2019-11-30 04:03:26
题目描述: 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。 您可以假设除了数字 0 之外,这两个数都不会以 0 开头。 示例: 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 输出:7 -> 0 -> 8 原因:342 + 465 = 807 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/add-two-numbers 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 这个题只有两个地方需要思路: 进位 加法、边界判断。 我第一遍的思路很直接,有一个空的就返回另一个就行了,两个都不空就进位加法,然后空一个换个while继续直到都加完了。 最后我漏掉的一个边界就是,两个都空了还有 最高位的进位。 第一遍思路很直,所以就直接写了三个while,每个while内容差不多粘贴也不用手打,然后觉得代码很丑……就统一判断写了份短的。但是我还是把长的记下来,因为三while执行24ms,统一判断需要36ms,差得很多了。 数据结构: /** * Definition for singly-linked list. * struct ListNode

AGC007题解

末鹿安然 提交于 2019-11-30 03:16:32
发现自己思维能力又跟不上了...做题有点吃力...所以回归AGC刷题计划... AGC040506都写了一部分题然后懒得补全了,所以从07开始做吧。大概是从C开始。 C 这也太人类智慧了吧... 我先是自己画了个柿子 咱也不知道对不对 先丢着 $\frac{1}{i-j+1} * \frac{1}{2^{j-n+1}} * ((2i-2j+1)d_1 + \frac{2i+2j-3}{2i-2j+1} x)$ 就是根据每一个球到哪一个洞推的,发现是小数显然用不了 鸽了。 然后就发现了这人类智慧的题解 发现有个性质没用上 就是等差数列 我们接着转换问题 变成数轴上有2n个点 每次可以取走相邻两颗 贡献是它俩之间的距离 惊喜一刻到了:可以发现每次距离期望的变化是等差数列! 等差数列+等差数列依然是等差数列= = 所以我们直接维护首项末项和公差就可以计算了 好像...很人类智慧... //Love and Freedom. #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #define ll long long #define inf 20021225 #define db double using namespace std; int read() { int s=0,f=1; char ch

Heroku - how to write into “tmp” directory?

老子叫甜甜 提交于 2019-11-30 02:47:14
问题 I need to use the tmp folder on Heroku (Cedar) for writing some temporarily data, I am trying to do that this way: open("#{Rails.root}/tmp/#{result['filename']}", 'wb') do |file| file.write open(image_url).read end But this produce error Errno::ENOENT: No such file or directory - /app/tmp/image-2.png I am trying this code and it's running properly on localhost, but I cannot make it work on Heroku. What is the proper way to save some files to the tmp directory on Heroku (Cedar stack)? Thank

Linux目录和基本命令

时光怂恿深爱的人放手 提交于 2019-11-30 02:29:23
Linux文件系统结构 Linux目录结构的组织形式和Windows有很大的不同。首先Linux没有“盘(C盘、D盘、E盘)”的概念。已经建立文件系统的硬盘分区被挂载到某一个目录下,用户通过操作目录来实现磁盘读写。 Linux不像Windows那样的系统目录,Linux使用正斜杠"/"而不是反斜杠"\"来标识目录。 Linux首先是建立一个根"/"文件系统,所有的目录也都是由根目录衍生出来。 登录系统后,在当前命令窗口输入命令: ls / 查看结果如下图: 在Linux底下,所有的文件与目录都是由根目录开始,是目录与文件的源头,然后一个个的分支下来,如同树枝状,因此称为这种目录配置为:目录树。 目录树的特点是什么呢? 目录树的起始点是根目录(/,root); 每一个目录不止能使用本地的文件系统,也可以使用网络上的文件系统,可以利用NFS服务器挂载特定目录。 每一个文件在此目录树中的文件名,包含完整路径都是独一无二的。 目录树架构示意图 以下是对这些目录的解释: /bin : bin是Binary的缩写, 这个目录存放着最经常使用的命令。 /boot: 这里存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件。 /dev : dev是Device(设备)的缩写, 该目录下存放的是Linux的外部设备,在Linux中访问设备的方式和访问文件的方式是相同的。 /etc