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

2021-10-02 21:30:22 字數 931 閱讀 7051

傳送門

這題數學加雙指標

沒錯,你沒有看錯,又是雙指標,雙指標是個好東西呀~

題目大概意思是給你兩組長度相同的序列,問有多少序列滿足一下條件:

假設兩組序列分別為a,b

a[i] <= b[i]

滿足以上要求的a的序列有多少個,其中如果元素出現部分相同,也視為不同序列,所以我們不需要排重啦~

我們可以直接對序列a ,b 進行sort,然後用雙指標來看看有多少滿足,統計個數,直接乘到答案中去就可以啦

上**啦~

雙指標,偶來啦~

#include

using

namespace std;

const

int n =

1e5+10;

const

int mod =

1e9+7;

typedef

long

long ll;

int n;

int a[n]

;int b[n]

;ll ans =1;

intmain()

sort

(a +

1, a + n +1)

;for

(int i =

1; i <= n; i++

)sort

(b +

1, b + n +1)

;for

(int i =

1, j =

1; i <= n; i++

) ans = ans *

max(

0, j - i)

% mod;

} cout <<

(ans + mod)

% mod << endl;

return0;

}

嘻嘻~下期見噢

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

長期更新,補完為止 2 g 判正誤 題意 t組資料。判斷a d b e c f是否等於g。1e9 a,b,c,g 1e9,0 d,e,f 1e9。保證不會出現指數和底數同為 0 的情況。思路 硬算會tle或mle。快速冪取模,為了增加過題概率,多取幾個模數判斷。includeusing namesp...

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

找規律,推公式 三角形個數為2 m n m n m 1 n 1 2 m n mn m 1 n 1 2 m n mn m 1 n 1 include include include include using namespace std typedef long long ll const int m...

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

h題 突然發現h題可以用好多種方法做的。方法一 雙指標,維護乙個修改次數小於等於k的區間 include using namespace std typedef long long ll const int mod 1e9 7 const int n 1e5 5 const int inf 0x3f...