Time of Update: 2018-12-05
幾個常用例子例1:得到devicetype的值,首先原始字串中是否包含devicetype=,如果包含此串兒則使用如下方式獲得devicetype的值。int main(int argc, char argv[]){string szMsg("_Community=public&_MachineName=192.168.6.96&_Port=161&devicetype=_SnmpWin&seid=2");char *pPos =
Time of Update: 2018-12-05
乍一看,像最小產生樹,實際不用,因為資料量較小(最大8台電腦),所以直接類比全排列算最小值就可以。代碼如下:#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;struct point{ int x, y;} po[10];int n;double save_d[10]
Time of Update: 2018-12-05
經典“八皇后問題”,把所有情況全部遍曆一遍,統計最大值即可。代碼如下:#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int a[9][9], vis[3][20], save[9], n, tot;void search(int cur){ int i;
Time of Update: 2018-12-05
Extended Lights OutTime Limit: 2 Seconds Memory Limit: 65536 KBIn an extended version of the game Lights Out , is a puzzle with 5 rows of 6 buttons each (the actual puzzle has 5 rows of 5 buttons each). Each button has a light. When a button is
Time of Update: 2018-12-05
全排列,統計記錄每個排列中“頻寬”最大的值,最後輸出所有最大值中最小的那個。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int cct, ahl[27], map[27][27];int save[9],
Time of Update: 2018-12-05
大體題意就是將列表第一列的字串不斷換成第二列的字串,直到將所給的整個句子中所有出現的第一列字串全部換掉為止,然後再進行下一個字串的替換。題目本身不難,相信只要認真一點,就可以輕鬆AC掉 ~(如果用上strstr()函數和sprintf函數會使代碼簡潔不少,效率也會提高不少。當然如果會用STL的string的話,同樣會很快。)代碼如下:#include<stdio.h>#include<string.h>#include<math.h>int
Time of Update: 2018-12-05
描述:就是性價比問題,誰的性價比高誰就優先,如果一樣,就按照工作的順序優先#include <cstdio>#include <cstdlib>#include <cstring>int cmp(const void *p1,const void *p2){ if(((int *)p1)[1]*((int *)p2)[0]>((int *)p1)[0]*((int *)p2)[1]) return 1; else if((((int *)p1
Time of Update: 2018-12-05
描述:區間選取問題的變換問題#include<cmath>#include<cstdio>#include<cstdlib>int cmp(const void *p1,const void *p2){ if(((double *)p1)[0]>((double *)p2)[0]) return 1; else if(((double *)p1)[0]<((double *)p2)[0]) return -1; else {
Time of Update: 2018-12-05
描述: 我們把序列排成不增序,即d1>=d2>=...>=dn,則d可簡單圖化若且唯若d'=(d2-1, d3-1, ... d(d1+1)-1, d(d1+2), d(d1+3), ... dn)可簡單圖化。這個定理寫起來麻煩,實際上就是說,我們把d排序以後,找出度最大的點(設度為d1),把它和度次大的d1個點之間連邊,然後這個點就可以不管了,一直繼續這個過程,直到建出完整的圖,或出現負度等明顯不合理的情況。舉例:序列S:7,7,4,3,3,3,2,1 刪除序列S的首項
Time of Update: 2018-12-05
題意實際上要求每次比較四個圖形(其中三個是旋轉翻轉得到的),然後通過比較如果這四個圖形之前都沒有出現過,則將這四個圖形全部存起來,以備以後進行比較(還有一點需要注意的,就是如果原圖形經過旋轉得到的圖形和原圖形相同,這種情況是不算重複的)。剛開始理解成每次幾個比較完之後只把原圖形存起來了,WA了好幾次。方法:因為資料量較小,直接將二維圖存成一維數組,然後暴力枚舉比較就可以。代碼如下:#include <iostream>#include
Time of Update: 2018-12-05
/*題意:給出n個點,m個邊。給出每個點的權值,每個邊的權值。求建立一棵樹,root=1,求這棵樹的最小費用,費用=樹上每條邊*子樹中各頂點的權值。思路:root的權值是沒用的,而其餘節點是必須用的,每條邊*子樹中各定點的權值=各個點*點到根的最短路,於是轉化成了root到各個點的最短路。*/#include<cstdlib>#include<iostream>#include<sstream>#include<cstdio>#include<
Time of Update: 2018-12-05
按照題目說的去類比就可以,唯一值得注意的是,兩個單詞之間可能不止一個空格,因為這個RE了好幾次。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int main(){#ifdef test
Time of Update: 2018-12-05
剛開始審錯題以為是“上下左右”四個方向走,結果編出來以後,範例都沒跑過,又仔細審了審題,才明白過來,騎士的走法與國際象棋騎士的走法一樣,按'日'字走。方法比較簡單,因為資料量比較小,DFS回溯+雜湊判重足矣。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath&
Time of Update: 2018-12-05
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#define N 100100using namespace std;int fcmp(const void *p1,const void *p2){ return strcmp((char*)p1,(char*)p2);}int main (){ //freopen("a.txt","r",
Time of Update: 2018-12-05
A hard Aoshu ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/Others)Total Submission(s): 345 Accepted Submission(s): 173Problem DescriptionMath Olympiad is called “Aoshu” in China. Aoshu is very popular in
Time of Update: 2018-12-05
Telephone LinesTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3468 Accepted: 1245DescriptionFarmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the
Time of Update: 2018-12-05
#include <iostream>#include <cmath>#include <cstring>using namespace std;long su(long a,long b,long c){ long d(a); while(d%b==0&&d!=1) { d=d/b; c++; } return c;}void sc(long a,long b,long
Time of Update: 2018-12-05
倒水問題,bfs+雜湊,需要將每一步的總倒水量全部存起來,最後再排一次序,將小於等於d 的最大的d及其匹配的總到水量輸出即可。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;const int MAXSIZE
Time of Update: 2018-12-05
類比題,代碼稍長,一定仔細。代碼如下:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;char Map[8][9];int Hstep_x[8] = {2, 2, -2, -2, 1, 1, -1, -1};int Hstep_y[8] = {1, -1, 1, -1, 2, -2
Time of Update: 2018-12-05
開始用的回溯TLE了,後來改用全排列+DFS AC。代碼如下:(0.728s):#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int a[5], flag;void solve(int cur, int sum){