牛客寒假演算法基礎集訓營6

2021-10-04 17:41:49 字數 2517 閱讀 3026

現在有正整數集合 a 和 b,每個集合裡有 n 個數,你要建立他們間的一一對映,將每對配對的數字相加可以得到 n 個和,你要做的就是最大化第 k 大的和。

分別將前k大的數, 乙個集合第i小的和另乙個集合第i大的, 配對, 得出k個數最後最小的那個數就是答案。

小 q 新學會了一種魔法,可以對乙個 n行m列 的網格上的敵人造成傷害 , 第 i 次使用魔法可以對網格上的乙個十字形區域(即第 xi 行和第 yi 列的並)中的每個格仔上的敵人造成 zi 點傷害 , 現在小 q 一共使用了 h 次魔法,輸出σwij(i+j)對 10^9+7 取模的結果。

思路:開額外兩個陣列分別記錄第i行受到的總傷害,和第j列受到的總傷害,mp來記錄第i行,第j列的單位受到的傷害。。直接將全部點受到的傷害存入mp會超時。

#include

using namespace std;

typedef

long

long ll;

const

long

long mod =

1e9+7;

const

int inf =

0x3f3f3f3f

;const

double pi =

3.141592

;const

int e =

1e5+5;

ll n, m, h, ans =0;

ll a[

2005

], b[

2005

], mp[

2005][

2005];

intmain()

for(

int i =

1; i <= n; i++)}

printf

("%lld\n"

, ans)

;return0;

}

合法括號序列的定義是:

1.空序列是合法括號序列

2.如果 s 是乙個合法括號序列,那麼(s)是合法括號序列

3.如果 a 和 b 都是合法括號序列,那麼 ab 是乙個合法括號序列

現在給定乙個括號序列,求最少刪去幾個括號能得到乙個合法的括號序列

思路:遍歷字串,如果為「(」,計數器+1

如果為「)」且計數器大於0,計數器-1

如果為「)」且計數器小於0,說明前面沒有與之對應的「(」,ans+1。

最後計數器中的值為,為匹配的「(」。

#include

using namespace std;

typedef

long

long ll;

const

long

long mod =

1e9+7;

const

int inf =

0x3f3f3f3f

;const

double pi =

3.141592

;const

int e =

1e5+5;

intmain()

cout << ans + sum << endl;

//未匹配的(和未匹配的)相加

}return0;

}

現有乙個邊長為正整數的三角形,問能否以其三個頂點為圓心畫三個圓,使三個圓兩兩外切

a=r1+r2

b=r1+r3

c=r2+r3

三個方程三個未知量,有解,不存在「no」的情況。

#include

using namespace std;

typedef

long

long ll;

const

long

long mod =

1e9+7;

const

int inf =

0x3f3f3f3f

;const

double pi =

3.141592

;int

main()

return0;

}

牛客寒假演算法基礎集訓營

首先看到這個題目資料範圍就可以知道這不是乙個可以暴力過的題。所以應該要推乙個結論。我們可以將這個同學的一來一回看成一組,那麼就可以理解為乙個來回中n可以減少n m 1 個人。那麼我們現在要讓所有人都進去,那就是看n m 1 的數量。但是有可能存在一些情況,就是說當你的倒數第二組中的回來的那趟使得n變...

2020牛客寒假演算法基礎集訓營6

先將兩個陣列排好序,從兩邊列舉最大的k個數相加,最小的就是最大的第k個數 include include include include include using namespace std const int n 100050 int a n b n n,k,ans 2e8 intmain vo...

2021牛客寒假演算法基礎集訓營6

思路 k1排k2前面滿足 k1.a k2.ax k2.b k1.b k1.ax k1.b k2.b k2.ak1.b k2.b k1.a k2.a k1.b include define ull unsigned long long define ll long long const int inf...