acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 二分查找

    这是一道模板题没什么思路可说上代码

    userId_undefined

    ikun

    倔强青铜
    0阅读
    0回复
    0点赞
  • 题解

    userId_undefined

    胡天维

    倔强青铜
    0阅读
    0回复
    0点赞
  • 题解-二分查找

    userId_undefined

    AC

    倔强青铜
    0阅读
    0回复
    0点赞
  • 递归写法

    #include<bits/stdc++.h> using namespace std; int n; int a[1000005]; int ans = -1; void dfs(int l,int r, int x){ if(l>r) return ; int mid = (l+r) >> 1; if(a[mid] >= x){ ans = mid; dfs(1,mid-1,x); } else{ dfs(mid+1,r,x); } return ; } int main(){ cin >> n; for(int i = 1; i <= n ; i ++){ cin >> a[i]; } int x; cin >> x; dfs(1,n,x); if(a[ans] == x)cout << ans; else cout << -1; return 0; }

    userId_undefined

    c++

    倔强青铜
    0阅读
    0回复
    0点赞
  • for硬来

    #include<iostream> using namespace std; int main(){ int a[100]; int n,x; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } cin >> x; for (int i = 1; i <= n; ++i) { if (a[i] == x) { cout << i; return 0; } } cout << -1; return 0; }

    userId_undefined

    ZDZL_A C 君.

    倔强青铜
    0阅读
    0回复
    0点赞

共45条

  • 1
  • 2
  • 3
20条/页
跳至页
首页