題意:求割點,並計算去掉割點後連通分支的數量。#include <iostream>using namespace std;#define N 1005#define min(a,b) (a<b?a:b)int size, id;int head[N], vis[N];int low[N], dfn[N], connect[N];struct { int v, next; } edge[N];void add ( int u, int v ){size++;edge[size]
B. Unarytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUnary is a minimalistic Brainfuck dialect in which programs are written using only one token.Brainfuck programs use 8 commands: "+", "-", "[
題意:給定一個字串, 如 alala, 求既是它首碼,又是它尾碼的子串( a, ala, alala ) ,按升序輸出所以可能的子串的長度。 題解:next 函數的應用。當然用hash也可以。#include <iostream>using namespace std;#define N 400005char str[N];int next[N];void get_next ( int n ){int i = 0, j = -1;next[0] = -1;while ( i <
題意:老師想帶他的學生們出去旅行,但是不想他們之間發生戀愛。也就是說,任意兩個可能發生戀愛的人不能同時都帶去。要求能帶去旅行的最大人數。老師認為滿足下列情況的人之間不會發生戀愛。1.Their height differs by more than 40 cm.2.They are of the same sex. 3.Their preferred music style is different. 4.Their favourite sport is the same (they are
題意:先輸入兩個整數 n, k。然後有 n 行輸入, I 代表寫下一個數字, Q代表詢問在所有寫下的數字中第 k 大的數數多少?題解:因為當寫下的數少於 k 個是不存在詢問的情況。所以可以建一個堆,然後沒寫下一個數字,若它比堆中的最小數字還小,則堆不做改變。若它比堆中的最小數字要大,那麼將堆中的最小數字去掉,並加入剛寫入的數字。具體寫了三種方法:方法一:最小堆#include <algorithm>#include <iostream>using namespace
題意:一同牛隻願意在幾個特定的棚子裡面產奶。每頭牛喜好不同,每個棚子只容納一同牛。求最大匹配。#include <iostream>using namespace std;#define N 210bool vis[N], bond[N][N];int match[N];int n, m;bool find_path ( int u ){for ( int v = 1; v <= m; v++ ){if ( bond[u][v] && !vis[v]
題意:有n個學生,一男一女可能會陷入浪漫之中,現在知道每個人的浪漫關係。求一個最大集,使得集合裡的所有人之間沒有浪漫關係。題解:二分圖匹配,最大獨立集。#include <iostream>using namespace std;#define N 510bool vis[N];int match[N], bond[N][N], cnt[N], n;bool find_path ( int u ){for ( int i = 1; i <= cnt[u]; i++ ){int
C. Turing Tapetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputINTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output,
D. Piettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPiet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and
E. Logo Turtletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and