0 | 1 | 2 | 3 | 4 |
---|---|---|---|---|
x |
vector<int> S;
int search(int x){
int n = S.size();
for(int i = 0; i < n; ++i)
if(S[i] == x) return i;
return -1;
}
y | x |
---|
y | x |
---|
x | y |
---|
vector<int> S;
int search(int x){
int L = 0, R = int(S.size()) - 1;
while(L <= R){ // 初學者這裡容易寫壞(無限迴圈)
int mid = (L+R) / 2;
if(S[mid] == x) return mid;
if(S[mid] < x) // x 在右邊
L = mid + 1;
else // x 在左邊
R = mid - 1;
}
return -1;
}
vector<int> S;
int search(int x){
int L = 0, R = int(S.size()) - 1;
while(R - L > 5){ // 給一個很小的範圍
int mid = (L+R) / 2;
if(S[mid] == x) return mid;
if(S[mid] < x) // x 在右邊
L = mid + 1;
else // x 在左邊
R = mid - 1;
}
for(; L <= R; ++L) //剩下的暴力搜尋
if(S[L] == x) return L;
return -1;
}
< x | == x | > x |
---|
< x | == x | > x |
---|
< x | > x |
---|
< x |
---|
vector<int> S;
int lowerBound(int x){
int L = 0, R = S.size();
while(L < R){
int mid = (L + R) / 2;
if(S[mid] < x)
L = mid + 1;
else
R = mid;
}
return L;
}
< x | == x | > x |
---|
< x | > x |
---|
< x |
---|
vector<int> S;
int upperBound(int x){
int L = 0, R = S.size();
while(L < R){
int mid = (L + R) / 2;
if(S[mid] <= x)
L = mid + 1;
else
R = mid;
}
return L;
}
vector<int> S;
int search(){
int L = 0, R = S.size();
while(L < R){
int mid = (L + R) / 2;
if(S[mid] == mid)
L = mid + 1;
else
R = mid;
}
return L;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, a, b;
cin >> n >> a >> b;
int sol;
for(int i = 1; i <= min(a,b); ++i)
if(a/i + b/i >= n)
sol = i;
cout << sol << '\n';
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, a, b;
cin >> n >> a >> b;
int L = 1, R = min(a,b) + 1;
while(L < R){
int mid = (L+R)/2;
if(a/mid + b/mid >= n)
L = mid + 1;
else
R = mid;
}
cout << L - 1 << '\n';
return 0;
}
int n = nums1.size(), m = nums2.size();
int L = 0, R = n;
int midian;
while(true){
int mid = (L+R)/2;
int remain = (n+m+1)/2 - mid;
if(remain < 0){
R = mid-1;
continue;
}
if(mid < n && remain > 0 && nums2[remain - 1] > nums1[mid])
L = mid + 1;
else if(mid > 0 && remain < m && nums2[remain] < nums1[mid - 1])
R = mid - 1;
else{
if(mid == 0) midian = nums2[remain - 1];
else if(remain == 0) midian = nums1[mid - 1];
else midian = max(nums1[mid - 1], nums2[remain - 1]);
break;
}
}
if((n+m)%2) return midian;
if(mid == n) return (midian + nums2[remain]) / 2.0;
if(remain == m) return (midian + nums1[mid]) / 2.0;
return (midian + min(nums1[mid], nums2[remain])) / 2.0;
upperBound(x) - lowerBound(x)
int S[] = {0,1,2,3,4,5};
cout << *lower_bound(S, S + 6, 3) << '\n'; // 3
vector<int> S2 = {4,5,6,7,8,9};
cout << *lower_bound(S2.begin(), S2.end(), 7) << '\n'; // 7
int S[] = {0,1,2,3,4,5};
cout << *upper_bound(S, S + 6, 3) << '\n'; // 4
vector<int> S2 = {4,5,6,7,8,9};
cout << *upper_bound(S2.begin(), S2.end(), 7) << '\n'; // 8
int S[] = {0,1,3,3,4,5};
cout << upper_bound(S, S + 6, 3) -
lower_bound(S, S + 6, 3) << '\n'; // 2