#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 500;
///快速幂
ll quickpow(ll x, ll n)
{
ll ret = 1;
while(n){
if(n&1) ret = ret * x % mod;
n >>= 1;
x = x * x % mod;
}
return ret;
}
///树状数组
ll C[maxn];
ll lowbit(ll x)
{
return x&-x;
}
ll add(ll i, ll x)
{
while(i<=n){
C[i] += x;
i += lowbit(i);
}
}
ll sum(ll i)
{
ll ret = 0;
while(i>0){
ret += C[i];
i -= lowbit(i);
}
return ret;
}
///RMQ
ll dp[3000][3000];
void init(ll a[], ll n)
{
for(int i = 1; i <= n; i ++) dp[i][0] = a[i];
for(int j = 1; (1<<j) <= n; j ++){
for(int i = 1; i + (1<<j) < n; i ++){
dp[i][j] = min(dp[i][j-1], dp[i+(1<<j)][j-1]);
}
}
}
ll rmq(ll l, ll r)
{
ll k = log(r-l+1);
return min(dp[l+(1<<k)][k],dp[r-(1<<k)+1][k]);
}
///递推组合数
void tui()
{
for(int i = 0; i <= maxn-5; i ++){
c[i][0] = c[i][i] = 1;
for(int j = 1; j < i; j ++)
c[i][j] = c[i-1][j] + c[i-1][j-1];
}
}
///二分查找
bool check(x)
{
return true;
}
int main()
{
//生成随机数
srand((unsigned)time(NULL));
for(int i = 0; i < 10;i++ )
cout << rand() << '\t';
cout << endl;
///输入一行数字
string s;
int n = 0;
getline(cin,s);
stringstream ss(s);
while(ss>>x){
a[n++] = x;
}
///二分之查找
ll l = 1, r = n;
ll ans = 1;
while(l <= r){
ll m = (l+r)>>1;
if(check(m)) ans = m,l = m+1;
else r = m-1;
}
}
个人常用算法模板
最新推荐文章于 2024-05-29 18:35:23 发布