原创 並查集 5-30 tree ------錯誤方法
#include <iostream> using namespace std; int fa[100000];// father int f_u(int x) { int root=x; while(fa[root]!=root)
原创 5-16 冒泡排序
#include <iostream>#include <fstream>using namespace std;int main(){ int n; cin>>n; int in[n+1]; for(int i=0;i<n;i++)
原创 5-30 並查集 tree
#include <iostream> #include <fstream> using namespace std; ifstream fin("tree.in"); ofstream fout("tree.out"); #define
原创 tree 用點、邊的算法
由於江老師說上次那個算法是以前的,所以我就用了新學的計算邊數與點數的算法……程序:#include <iostream> #include <fstream> #include <algorithm> using namespac
原创 4-25 字符串
定義:string 變量名; 賦值: string 變量名(字符串); string 變量名 (字符數量,字符);(字符數量個字符) 變量名 = 字符串; 等價於 變量名.assign("字符串"); 輸入: cin>>變量名; 輸出
原创 6-6 並查集練習——friend
#include <iostream> #include <fstream> #include <algorithm> using namespace std; int fa[100001]; ifstream fin("friend
原创 galaxy 原來的方法——超時(沒有壓縮路徑)
因爲沒有壓縮路徑,因此訪問每一個成員的根會十分的慢,因此十分容易超時(因爲超時,所以不知道對不對……)#include <iostream> #include <fstream> #include <algorithm> usin
原创 5-16 插入排序
#include <iostream>#include <fstream>using namespace std;int main(){ int n; cin>>n; int in[n+1],ans[n+1]; for(int i=0;
原创 6-6 並查集練習——ttime
#include <iostream> #include <fstream> #include <algorithm> using namespace std; ifstream fin("ttime.in"); ofstream f
原创 n種錢幾種分法程序
#include <iostream>#include <fstream>using namespace std;bool ch[1000000];int a[100000];int main(){ int n; cin>>n; lo
原创 5-16 選擇排序
#include <iostream>#include <fstream>using namespace std;int main(){ int n; cin>>n; int in[n+1]; cin>>in[0]; int maxx=
原创 6-17 創新班第十課
首先,江老師評價了一下我們的博客,說我的tree那題沒有用新學的方法做,所以我就在博客上貼了程序 在這裏,江老師講了兩個很重要的概念: 1、靜態和動態: 按照t
原创 2016-8-6夏令營總結(kmp,迴文串,擴展kmp)
今天我們用了一個上午學習了字符串中的kmp,最長迴文子串和擴展kmp算法,下午在編相應的裸題。 KMP算法 我們有一個長度爲n的字符串S,長度爲m的字符串T,問T在S裏出現了幾次? 這題是我們平時最經常遇到的字符串問題。這題暴力搜索的話
原创 創新班21課總結
創新班早上還是講了salesman那3題,下午就講了關於樹的圖論。先是salesman,有3種做法: 第1種: 然後就一直按照123走,直到做完。 但是如果每次都找一遍最大值,那就是超時的60分O(n?)算法了,但是
原创 位運算
位運算 首先,先明確一下一個概念:位運算是通過二進制進行操作的。 首先來認識一下幾個位運算的符號。 符號 名稱 & 與運算(and) | 或運算(huo) << 左移 >> 右移 ~ 取反