Python 小程式,對檔案操作及其他,下面是自己寫的幾個對檔案操作的小程式,裡面涉及到檔案操作,列表(集合,字典)的運用等。比如說,從檔案中讀取一行資料,分別存放於列表中,再對列表進行操作,如去掉裡面的重複項,排序等操作。常見對檔案中行進行操作:#這裡列出兩個常用的方法方法01: 一次性讀取所有行>>> f = file('1.txt')>>> while 1:lines = f.readlines()if not
Leetcode_num15_Maximun Subarray,leetcode題目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1]
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 【部分題解】,2014牡丹江亞洲地區賽邀請賽K題:想法題分析:兩種變化,添加和交換,首先:星號是n的話最少需要的數字是n+1,那麼可以首先判斷數字夠不夠,不夠的話現在最前面添數字,如果滿足的話直接類比如果數字不夠的話把當前的星號和最後一個數字交換即可。css函數可以不用。AC代碼:#include <cstdio>#include
zoj 3822 Domination(2014牡丹江地區賽D題),zoj牡丹江DominationTime Limit: 8 Seconds Memory Limit: 131072 KB Special JudgeEdward is the headmaster of Marjar University. He is enthusiastic
POJ1422 Air Raid 【DAG最小路徑覆蓋】,poj1422dagAir RaidTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6763 Accepted: 4034DescriptionConsider a town where all the streets are one-way and each street leads from one
hdu 4027 Can you answer these queries?(線段樹),hdu4027題目大意:hdu 4027 Can you answer these queries?題目大意:給定一個長度為N的序列,Q次操作,0 l r:將區間l r之間的數開根;1 l r:查詢l r之間數的和。解題思路:這題看上去是一道線段樹,其實它就是一道線段樹,只不過不用想的太複雜,因為開根的趨近1的速度非常快,所以每個節點只要標記區間內元素是否相同即可。複雜度妥妥的。#include
poj2155 Matrix 二維數組數組,poj2155matrixhttp://poj.org/problem?id=2155MatrixTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 18769 Accepted: 7078DescriptionGiven an N*N matrix A, whose elements are either 0 or 1. A[