Time of Update: 2018-12-05
由於英語極差,看了半天也沒看懂題目,最後參考了其他人的題解才搞懂題目,我就直接把題意貼過來了 題意:這道題目只是題意自己就去理解了半天,大概題意如下:給出i一個n*n的矩陣,初始化為均為0,還有關於這個矩陣的幾種操作,操作如下:命令1:(X Y A)對位於座標(X Y)的值加A;命令2:(L B R
Time of Update: 2018-12-05
【連結】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1657【原題】A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily
Time of Update: 2018-12-05
這個題就是一個定理的運用:中位元m具有各變數絕對值與其離差絕對值之和最小的性質。當n是偶數時,num[n/2],num[n/2-1]之間的數都與各個數差的絕對值之和是最小的。#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;int num[1000001
Time of Update: 2018-12-05
題目連結 DescriptionAn entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with "wasted" or "extra" information removed. In other words, entropy encoding removes information that was not necessary
Time of Update: 2018-12-05
Prim演算法例如下面的無向連通圖: #include <iostream>#include <vector>#include <limits>using namespace std;struct TreeNode// 邊結點定義{public:TreeNode (int nVertexIndexA = 0, int nVertexIndexB = 0, int nWeight = 0): m_nVertexIndexA (nVertexIndexA),
Time of Update: 2018-12-05
原題為: 輸入一個16進位的字串, 使得程式輸出0xdeadbeef 程式如下:/* Bomb program that is solved using a buffer overflow attack */#include <stdio.h>#include <stdlib.h>#include <ctype.h>/* Like gets, except that characters are typed as pairs of hex
Time of Update: 2018-12-05
16、17講開始涉及到圖,光是虛擬碼的話實現起來不是很直接,所以乾脆補全一下需要用到的圖的類定義及一些成員函數,限於篇幅,成員函數、最小堆、並查集等的實現沒有貼出來。 graph類定義template <typename T, typename E>class Graph{public:Graph(int sz){maxVertices = sz;numVertices = 0;numEdges = 0;}virtual ~Graph(){};bool GraphEmpty()
Time of Update: 2018-12-05
#include <iostream>#include <limits>#include <string>using namespace std;int main(){cout<<boolalpha;cout<<"max(short): "<<numeric_limits<short>::max()<<endl;cout<<"max(int):
Time of Update: 2018-12-05
#include <iostream>#include <math.h>#include <stdlib.h>#include <time.h>#include <windows.h>#define slot_size 100000//散列槽的大小#define arr_size 80000//動態關鍵字集合#define min_size 0//動態關鍵字集合的最小值#define max_size 999 #define
Time of Update: 2018-12-05
#include<iostream>#include<fstream>#include<map>#include<algorithm>#include <iomanip>using namespace std;int main(){map<char,int>d;ifstream ifs("d:\\data.txt");char c;while(ifs>>c){if(isalpha(c)){char
Time of Update: 2018-12-05
#include <iostream>using namespace std;const int maxnum = 100;const int maxint = 99999; // 邊typedef struct Edge{int u, v; // 起點,終點int weight; // 邊的權值}Edge; Edge edge[maxnum]; // 儲存邊的值int dist[maxnum]; // 結點到源點最小距離 int nodenum,
Time of Update: 2018-12-05
AES明文在加密過程中涉及到位元組代換、行移位、列混合、輪密鑰加等過程。這裡對列混合的演算法做出一些淺顯的解釋。列混合其實就是對一個狀態的每一列去乘一個矩陣,其中乘法是在有限域GF(2^8)內進行的,不可約多項式為x^8+x^4+x^2+x+1先把演算法代碼列出來:void AES::MixColumns(unsigned char state[][4]) //列混合{ unsigned char t[4]; int r,c; for(c=0; c< 4; c++)
Time of Update: 2018-12-05
#include <iostream>using namespace std; int n; // 一個裝配線上有n個裝配站int e1, e2; // 進入裝配線1,2需要的時間int x1, x2; // 離開裝配線1,2需要的時間int t[3][100]; // t[1][j]表示底盤從S[1][j]移動到S[2][j+1]所需時間,同理t[2][j]int a[3][100];
Time of Update: 2018-12-05
#include <iostream>#include <cmath>#include <cstdlib>#include <time.h>#include <windows.h>#define slot_size 20000//散列槽的大小#define arr_size 100000//動態關鍵字集合#define min_size 0//動態關鍵字集合的最小值#define max_size 999 #define
Time of Update: 2018-12-05
Froyd-Warshall演算法用於求解所有點對之間的最短距離,其中權值可以為負值,但是不能有負數的環。時間複雜度為O(n^3)。 該演算法的思路是, 第一步:所有從 i 到 j 的最短路徑為i、j之間的權值(不相連的話就設為某個MAX數值) 第二步:如果結點數為 n, 對 n 從 1 到 n,每次假設加入一個結點後,那麼 i 與
Time of Update: 2018-12-05
#include <iostream>#include <fstream>#include <vector>#include <ctime>using namespace std;int keyA[12]={1,3,5,7,9,11,15,17,19,21,23,25};//具有mod26乘法逆的12個元素int keyB[26];char encode(char ch, int key_a, int key_b)//加密函數{int
Time of Update: 2018-12-05
#include <iostream>using namespace std;int main(){int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};//100以內的質數int seq[10000];for(int i=0; i<10000; ++i)seq[i]=1;for(int i=0; i<25; ++i) {
Time of Update: 2018-12-05
#include <stdio.h>#include <string.h>char name[] = "\x41\x41\x41\x41" //name[0]-name[3]"\x41\x41\x41\x41" //name[4]-name[7]"\x41\x41\x41\x41" "\x12\x45\xfa\x7f"
Time of Update: 2018-12-05
這個題資料挺大的,本來我想定義str[2147483647]然後把它跑出來存起來,讀入資料a後直接輸出str[a-1],但是資料太大了,所以先手算了一下一個大概的範圍, 9 45 99 9045
Time of Update: 2018-12-05
第二十三章 最小產生樹 總結:這一章介紹了最小產生樹,並介紹了找出最小產生樹的兩個演算法,Prim演算法和Kruskal演算法,它們都用到了貪心策略。 1. 最小產生樹對無向連通圖G=(V,E),對圖中的每一條邊(u,v)єE,都有一個權值w(u,v)。我們希望找出一個無迴路的子集T包含於E,它串連了所有的頂點,且其權值之和w(T)=Σw(u,v)為最小。把確定T的問題稱為最小產生樹問題。 2.