Time of Update: 2018-12-05
//BFS廣度優先搜尋,結合資料結構隊列#include<iostream>#include<queue>using namespace std;int arr[200000];int vis[200000];//已訪問數組queue<int> q1,q2;//用資料結構隊列可節省搜尋空間int deep;void set(int n,int deep,int k){if(arr[n-1] != deep-1 && n - 1 > 0 &
Time of Update: 2018-12-05
//DP動態規劃,求最長上升子序列#include<cstdio>int arr[1001],d[1001],len,max = 1;//最大值應初始化為1,因為最小值是1.當只有1個資料是輸出1.int main(){for(int i = 1;i <= 1000;++i)d[i] = 1;//將DP數組初始化為1scanf("%d",&len);for(int i = 1;i <=
Time of Update: 2018-12-05
Description給定兩個整數M,N,產生一個M*N的矩陣,矩陣中元素取值為A至Z的26個字母中的一個,A在左上方,其餘各數按順時針方向旋轉前進,依次遞增放置,當超過26時又從A開始填充。例如,當M=5,N=8時,矩陣中的內容如下: A B C D E F G H V W X Y Z A B I U J K L M N C J T I H G F E D K
Time of Update: 2018-12-05
//求逆序數對#include<iostream>using namespace std;const int MAXN = 500001;long long int A[MAXN],T[MAXN],cnt;void merge_sort(long long int *A,int x,int y,long long int *T,long long int &cnt)//歸併排序{if(y-x > 1){int m = x + (y-x)/2;//劃分過程int p =
Time of Update: 2018-12-05
Problem DescriptionThese days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.Give you some integers, your task is to sort these
Time of Update: 2018-12-05
It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakdown in law and order, the Government decides on a radical measure--all
Time of Update: 2018-12-05
//DFS深度優先搜尋,WA了5次就因為1個while後面的條件差了一個……教訓啊!!!#include<iostream>using namespace std;int map[22][22],possible,minstep,w,h,beginx,beginy;void dfs(int x,int y,int r,int di)//di是4個方向的編號 1:向上 2:向右 3:向下 4:向左{if(r >
Time of Update: 2018-12-05
//DFS深度優先搜尋/回溯法/八皇后類型題#include<iostream>using namespace std;char map[9][9];int vis[9];//vis數組標記當前列是否已有其他棋從而提高效率int n,c,tot;void dfs(int l,int cnt)//cnt當前還有多少棋子要擺放{if(cnt == 0) //遞迴邊界,所有棋子已合理擺放完畢{tot++;//解個數return;}if(n-l+1 <
Time of Update: 2018-12-05
//用scanf比cin快很多,可以從804ms 到 204ms#include<cstdio>#include<iostream>using namespace std;int main(){int m,n,id,max,sec,time;int rank[10010];while(scanf("%d%d",&n,&m)){if(n == 0)break;memset(rank,0,sizeof(rank));max = sec = 0;time =
Time of Update: 2018-12-05
//簡單高精度運算#include<iostream>using namespace std;struct BigInt//結構體{char data[110];//字串資料int num[110];//整型資料int len;//位元長度void print()//列印函數{if(num[len] != 0)cout << num[len];//注意長度,得提前判斷進位的情況for(int i = len-1;i >= 0;--i)cout <<
Time of Update: 2018-12-05
P01:
Time of Update: 2018-12-05
//深度優先搜尋 POJ上最水的深搜#include<iostream>using namespace std;int y,x,n,r,c,ans = 0,_max = -1;int map[102][102];bool vis[102][102];void dfs(int y,int x){if(vis[y][x] == 1 || map[y][x] == 0)return;vis[y][x] = 1;ans++; dfs(y-1,x);dfs(y,x-1);
Time of Update: 2018-12-05
#include<cstdio>#include<iostream>using namespace std;int f[15000];int max(int a, int b){return a >b ? a: b;}int main(){int maxd = -1,n,m,w,d;scanf("%d%d",&n,&m);//滾動數組memset(f,0,sizeof(f));for(int i = 1;i <= n;++i){scanf("%
Time of Update: 2018-12-05
//簡單搜尋題目//思路:在讀入圖形時開一個flag標記,標記這個圖形一刀切的符號和座標,同時記錄這些符號的數量。//如果發現有兩種不同符號,直接判錯。發現沒有一刀切符號,就是全部為'.'也判錯//經過這一篩選,可以保證圖是由一種符號切的,但不確定切得對不對//下一步判斷:從一刀切的符號和沿線方向開始搜尋,看數量是否正確,不正確判錯#include<iostream>using namespace std;char map[30][30],flag;int t,y,x,cnt,_y,
Time of Update: 2018-12-05
//簡單題,純粹類比就能通過#include<iostream>using namespace std;bool check(int n,bool arr[100][100]){int sum;for(int i = 0;i < n;++i){sum = 0;for(int j = 0;j < n;++j){sum += arr[i][j];}if(sum % 2 != 0)return false;}for(int i = 0;i < n;++i){sum = 0
Time of Update: 2018-12-05
//類比/資料結構——棧堆(stack)#include<iostream>#include<stack>using namespace std;const int MAXN = 1000 + 10;int n,target[MAXN],temp;int main(){while(cin >> n){if(n == 0)break;while(1){stack<int> s;//申請STL棧堆int A = 1,B = 1;//A是有順序的車廂號,
Time of Update: 2018-12-05
//思路簡單,但細節上的處理比較多//用char字串來讀入數字,這樣處理起來會方便許多#include<iostream>#include<cstring>#include<algorithm>using namespace std;int n,time,temp;bool same;char num1[100],num2[100],num3[100];bool cmp(char a,char b)//降序sort比較函數{return a >
Time of Update: 2018-12-05
//快排水題,練習STL的QSORT#include<iostream>using namespace std;int arr[10010];int cmp(const void *a, const void *b){int *A = (int*)a;int *B = (int*)b;return *A - *B;}int main(){int n;cin >> n;for(int i = 0;i < n;++i)cin >> arr[i];qsort(
Time of Update: 2018-12-05
//尋找公式,思路是先列舉每一跳所能跳的最遠距離,然後發現規律,再注意下y-x=0時候的判斷即可//結果得出數列//0,1,2,4,6,9,12,16,20,25,30.......//0,0+1,1+1,2+2,4+2,6+3,9+3,12+4,16+4.....#include<iostream>using namespace std;int main(){int
Time of Update: 2018-12-05
//廣度優先搜尋#include<iostream>#include<queue>using namespace std;const int SIZE = 10000;bool prime[SIZE];int step[SIZE];//樹深度標誌int base[4] = {1,10,100,1000};int main(){ for(int i = 0; i < SIZE; i++)prime[i] = true;//產生素數表,方便判斷