noip知識點總結

2021-08-31 02:55:27 字數 2123 閱讀 5280

基本運算

狀壓運用:狀壓dp

求從0到n-1,每個點經過一次的最短路徑

#includeusing namespace std;

const int n = 20 + 1;

int f[1《成對運算:

當n為偶數時 n xor 1 = n+1

當n為奇數時 n xor 1 = n-1

用於取鄰接表的正反邊。

字首和 (差分陣列)

設差分陣列 d[i],= a[i] - a[i-1]; 則有

s um

1id[

i]=a

[i

]sum_^d[i] = a[i]

sum1i​

d[i]

=a[i

]d[l] += c,d[r+1] -= c;

就可以得出a的l–r減去c的答案

查詢x的後繼while(l != r)

查詢x的前趨
while(l != r)

查詢x
while(l != r)

}

二分答案
sort(b+1,b+1+n);

m = unique(b+1,b+1+n)-b-1;

for (int i = 1;i <= n;i++)

a[i] = lower_bound(b+1,b+1+m,a[i])-b;

rmq

其他應用:

p = 1,k = 0,sum = 0;

while(p)

找到從左到右第乙個比i大或小的值的位置;

tac存下標,f存下標,tac中單調遞增,

f是從左到右第乙個比i大或小的值的位置;

int t = 0;

for (int i = 1;i <= n;i++)

int l = 1,r = 1;

q[1] = 0;

for (int i = 1;i <= n;i++)

while(t1 < lent)

int i = 0,j = 0;

while(i < lens)

}

一. 動態規劃

最長上公升子串行:

#includeusing namespace std;

const int n = 1e3 + 10;

int f[n],n,a[n],ans;

int main()

for (int i = 1;i <= n;i++)

for (int i = 1;i <= n;i++)

f[i]=m

ax(f

[j])

a[i]

>a[

j],i

>j,

a[i]

−a[j

]<=i

−j​#includeusing namespace std;

const int n = 1e3 + 10;

int f[n],n,a[n],ans;

int main()

printf("%d\n",ans);

return 0;

}

最長公共上公升子串行

o (n

3)

o(n^3)

o(n3

for (int i = 1;i <= n;i++)

for (int j = 1;j <= m;j++)

else f[i][j] = f[i-1][j];

}

o(n

2)

o(n^2)

o(n2)

考慮到最外層i是固定的,所以for k 0 -> j ,在j+1的時候,只有j+1,進入了決策集合,而集合是不減的,所以只需o(1)判斷是否可以加入即可

for (int i = 1;i <= n;i++)

}

知識點總結

1,迴圈中的中斷 continue 跳出此次迴圈,繼續for迴圈 break 跳出當前for迴圈 return 跳出當前方法 2,字串的操作 componentseparatedbystring stringbyreplacingoccurencesofstring withstring iskin...

知識點總結

oncreate onstrat onresume onpause onstop onrestart ondestroy standard 啟動activity都會產生乙個新的activity 預設模式 singletop 啟動activity允許多個,但不允許重疊 singletask 只允許有乙...

知識點總結

function go go 呼叫 go為變數名 setinterval go,1000 1000ms clearinterval 關閉定時器 function abc a,b 2,3 5undefined 未定義 null 空 nan 非數值 string 字串 var a 123 數字型別 va...