摘要:
我們知道,char *s="aisdfj"; 是成立的。于是char *s[]={"one", "two", ……}也是成立的。就相當于把char *s看成另外一種類型的變量一樣。其實,就這么簡單。Sample Inputone + two =three four + five six =zero seven + eight nine =zero + zero =Sample Output39096View Code #include "stdio.h"#include "string.h"ch
閱讀全文
摘要:
題目:http://acm.swust.edu.cn/oj/problem/4/這是一道簡單的題目,但是可以說明問題了。View Code #include "iostream"#include "string"#include "cstdio"#include "cstring"#include "algorithm"#include "queue"using namespace std;char Map[105][105];int Used[105][105];int D
閱讀全文
摘要:
DFS在搜索的過程中,可以搜索一大片的連通的區域。題目:http://acm.swust.edu.cn/oj/problem/1/View Code #include<iostream>#include<string.h>using namespace std;int direction[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};int used[1005][85];char map[1005][85];int W, H, i, j, count, Max, tx, ty;void dfs(int i, int j){ int k; cou
閱讀全文
摘要:
我們知道,要是將數組開成int a[0xFFFFFFF]這么大,那是肯定不行。它會提示too big.但是如果用map的話,那就可以了。從這個方面來講,map就是數組的升級版嘍!這個可是我發現的哦。下面簡單的給出一個例子來。題目:http://acm.swust.edu.cn/oj/problem/0822/下面給出錯誤的代碼:View Code #include<iostream>#include<cstring>#include<algorithm>using namespace std;#define Max 1500000001int Num[Max
閱讀全文
摘要:
問題:求矩陣相乘后的和。一、最基本的算法下面給出一個例子來說明一下矩陣是如何相乘的。矩陣A為 1 0 2 3 5 6矩陣B為 3 1 2 2 1 3C=A*B = 1*3+0*2+2*1 1*1+0*2+2*3 3*3+5*2+6*1 3*1+5*2+6*3最簡單的算法就是用3個for循環就可以搞定了。假設A有ArowNum行, AvolBrow列。B必有AvolBrow行,假設B有BvolNum列。則循環如下: for(int i=0; i<ArowNum; i++) for(int j=0; j<BvolNum; j++) ...
閱讀全文
摘要:
下面來看一道簡單的但是有點意思的最短路徑的問題。本次用的解法是Floyd.題目:http://acm.swust.edu.cn/oj/problem/0819/在使用Floyd的時候有三點需要注意:一:map[][]數組的初始化 這個是十分的重要的,不然無法Floyd。具體點就是,map[i][i]=0; map[i][j]=INF;二、輸入時候的選擇性 只有做到這一步,才能保證是最短的,不然不行。具體點就是,if(map[u][v] > w) map[u][v] = map[v][u] = w; 這個主要用在題目中沒有說明是否會多次輸入同一條邊的時候。三、只有一個結點的情況 毫無...
閱讀全文
摘要:
SPFA算法是求單源路徑的經典算法,就是一點到其它所有點的最短路徑。這個類似于Flyod但是效率要高很多。下面給出具體的演示。Minya Konka decided to go to Fuzhou to participate in the ACM regional contest at their own expense.Through the efforts, they got a small amount of financial support from their school, but the school could pay only one of those costs bet
閱讀全文
摘要:
今天做了一個題目,感覺字符數組的初始化有點奇怪,就親自測試了一下,果不其然。確實很奇怪。這個就要和數組區分開了。一定不能將兩者混淆了。下面給出測試的代碼,并一一解析。View Code #include "iostream"#include "string"#include "cstring"using namespace std;#define size 10int main(){ char s1[size]="1", s2[size]={0}; for(int i=0; i<10; i++) cout&l
閱讀全文
摘要:
DescriptionAs a contestant, you must be familiar with the rules of ACM-ICPC. Teams are ranked according to the most problems solved. Teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed f
閱讀全文
摘要:
1.初始化演示2.push_back()演示3.insert()演示4.pop_back()演示5.erase()演示6.size()演示7.empty()演示8.assign()演示#include<iostream>#include<vector>using namespace std;typedef vector<int> vint;int main(){ cout<<"初始化對象:"<<endl; vint vec1; ///vec1對象初始為空 vint vec2(10, 6); ///vec2對象最初有
閱讀全文