正則方法 exec 和match以及test,execmatchtest var patt=new RegExp(/\d+/g); var str="dfgdfg5465yhhgh65y65hh41"; var result; // var reset=patt.exec(str); while ((result=patt.exec(str))!= null){
HDU 1171 Big Event in HDU(01背包),hdu1171 題意:給出每個物體的價值和物體的數量,如何分使得A,B所得價值最接近並且A的價值不能小於B思路:DP演算法,背包問題,求法是先求出總價值sum,再用dp[]求sum/2最多能放多少價值!即可以求出其中一個數了,另一個就是sum-dp[sum/2]了。#include <iostream>#include <cstdio>#include <cstring>using
Codeforces 528A Glass Carving STL類比,codeforces528a題目連結:點擊開啟連結題意:給定n*m的矩陣,k個操作2種操作:1、H x 橫向在x位置切一刀2、V y 豎直在y位置切一刀每次操作後輸出最大的矩陣面積思路:因為行列是不相干的,所以只要知道每次操作後行的最大間距和列的最大間距,相乘就是最大面積用一個set維護橫向的所有座標點,一個multiset維護橫向的間距。每次對行操作x則在set中找到比x大的最小數 r 和比x小的最大數l
Pow(x, n),pow 實現指數函數,這個還是比較簡單的。考慮到X為0或者正負數就行,還有就是避免重複計算,不然會逾時的。代碼如下:class Solution: # @param x, a float # @param n, a integer # @return a float def pow(self, x, n): if n == 0: return 1 if n == 1:
programming error (function overloading),ajaxerrorfunctionHere is the definition of function overloading:Function overloading or meth overloading is the ability to create multiple methods of same name with different implementations:Here is an
Valid Palindrome,validpalindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a palindrome.Note: