新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> We choose to study algorithmic problems,  not because they are easy,  but because they are hard.
    [返回] 计算机科学论坛计算机理论与工程『 算法理论与分析 』 → [讨论]一道北大CS考研题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 28144 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [讨论]一道北大CS考研题 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     Logician 帅哥哟,离线,有人找我吗?天蝎座1984-10-28
      
      
      威望:9
      头衔:逻辑爱好者
      等级:研三(收到IBM CRL的Offer了)(版主)
      文章:1219
      积分:10357
      门派:IEEE.ORG.CN
      注册:2005/3/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Logician发送一个短消息 把Logician加入好友 查看Logician的个人资料 搜索Logician在『 算法理论与分析 』的所有贴子 点击这里发送电邮给Logician  访问Logician的主页 引用回复这个贴子 回复这个贴子 查看Logician的博客楼主
    发贴心情 [讨论]一道北大CS考研题

    有两个(递增)有序数组A和B,长度均为n。为简单起见,不妨设这2n个数全是互异的整数。
    设计一个算法,能在O(log n)时间内找到两个数组“合并后的中数”。即,假设这2n个数已经归并成了一个长度为2n的有序数组C(C[0],...,C[2n-1])。 “合并后的中数”x=(C[n-1]+C[n])/2。输出这个x。

       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    Three passions, simple but overwhelmingly strong, 
    have governed my life: the longing for love, the
    search for knowledge, and unbearable pity for the
    suffering of mankind.
                                - Bertrand Russell

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/20 9:53:00
     
     phoenixinter 帅哥哟,离线,有人找我吗?水瓶座1987-2-12
      
      
      威望:1
      头衔:Ikki
      等级:大四(GRE考了1600分!)(版主)
      文章:127
      积分:1126
      门派:Lilybbs.net
      注册:2005/3/14

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给phoenixinter发送一个短消息 把phoenixinter加入好友 查看phoenixinter的个人资料 搜索phoenixinter在『 算法理论与分析 』的所有贴子 点击这里发送电邮给phoenixinter  引用回复这个贴子 回复这个贴子 查看phoenixinter的博客2
    发贴心情 
    这个是原题么?感觉O(logn)不大可能的说

    ----------------------------------------------
    phoenixinter
    algorithm bm@lilybbs
    ikki@poj

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/20 16:55:00
     
     Logician 帅哥哟,离线,有人找我吗?天蝎座1984-10-28
      
      
      威望:9
      头衔:逻辑爱好者
      等级:研三(收到IBM CRL的Offer了)(版主)
      文章:1219
      积分:10357
      门派:IEEE.ORG.CN
      注册:2005/3/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Logician发送一个短消息 把Logician加入好友 查看Logician的个人资料 搜索Logician在『 算法理论与分析 』的所有贴子 点击这里发送电邮给Logician  访问Logician的主页 引用回复这个贴子 回复这个贴子 查看Logician的博客3
    发贴心情 
    是回忆题。O(log n)这里应该没错。
    因为原题还要求证明log n阶是最优的(这个当然很简单)。
    互异的条件是我加的……

    ----------------------------------------------
    Three passions, simple but overwhelmingly strong, 
    have governed my life: the longing for love, the
    search for knowledge, and unbearable pity for the
    suffering of mankind.
                                - Bertrand Russell

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/20 17:19:00
     
     phoenixinter 帅哥哟,离线,有人找我吗?水瓶座1987-2-12
      
      
      威望:1
      头衔:Ikki
      等级:大四(GRE考了1600分!)(版主)
      文章:127
      积分:1126
      门派:Lilybbs.net
      注册:2005/3/14

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给phoenixinter发送一个短消息 把phoenixinter加入好友 查看phoenixinter的个人资料 搜索phoenixinter在『 算法理论与分析 』的所有贴子 点击这里发送电邮给phoenixinter  引用回复这个贴子 回复这个贴子 查看phoenixinter的博客4
    发贴心情 
    Say the two arrays are sorted and increasing, namely A and B.
    It is easy to find the median of each array in O(1) time.
    Assume the median of array A is m and the median of array B is n.
    Then,
    1' If m=n, then clearly the median after merging is also m, the algorithm holds.
    2' If m<n, then reserve the half of sequence A in which all numbers are greater than
       m, also reserve the half of sequence B in which all numbers are smaller than n.
       Run the algorithm on the two new arrays.
    3' If m>n, then reserve the half of sequence A in which all numbers are smaller than
       m, also reserve the half of sequence B in which all numbers are larger than n.
       Run the algorithm on the two new arrays.

    Time complexity: O(logn)

    ----------------------------------------------
    phoenixinter
    algorithm bm@lilybbs
    ikki@poj

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/20 21:15:00
     
     Logician 帅哥哟,离线,有人找我吗?天蝎座1984-10-28
      
      
      威望:9
      头衔:逻辑爱好者
      等级:研三(收到IBM CRL的Offer了)(版主)
      文章:1219
      积分:10357
      门派:IEEE.ORG.CN
      注册:2005/3/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Logician发送一个短消息 把Logician加入好友 查看Logician的个人资料 搜索Logician在『 算法理论与分析 』的所有贴子 点击这里发送电邮给Logician  访问Logician的主页 引用回复这个贴子 回复这个贴子 查看Logician的博客5
    发贴心情 
    nod.
    好办法。
    ^_^

    ----------------------------------------------
    Three passions, simple but overwhelmingly strong, 
    have governed my life: the longing for love, the
    search for knowledge, and unbearable pity for the
    suffering of mankind.
                                - Bertrand Russell

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/21 3:25:00
     
     carroty 帅哥哟,离线,有人找我吗?
      
      
      等级:大四(GRE考了1600分!)
      文章:153
      积分:1257
      门派:IEEE.ORG.CN
      注册:2006/4/4

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给carroty发送一个短消息 把carroty加入好友 查看carroty的个人资料 搜索carroty在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看carroty的博客6
    发贴心情 
    #include <iostream>

    using namespace std ;

    int main(){

     cout<<"Enter size of the array:";

     int size;
     cin>>size;

     int * a= new int[size];
     int * b= new int[size];

     cout<<"Enter array A:";
     for(int i=0;i<size;i++)
      cin>>a[i];

     cout<<"Enter array B:";
     for(i=0;i<size;i++)
      cin>>b[i];

     if(a[0]>b[size-1]){
      cout<<(a[0]+b[size-1])/2<<endl;
      delete [] a;
      delete [] b;
      return 0;
     }
     if(b[0]>a[size-1]){
      cout<<(b[0]+a[size-1])/2<<endl;
      delete [] a;
      delete [] b;
      return 0;
     }

     int as,bs,ae,be;
     as=bs=0;
     ae=be=(size-1);
     while(1)
     {
      if((as+1)==ae)break;
      if(a[(as+ae)/2]>b[(size-1)-(as+ae)/2]){
       ae=(as+ae)/2;
      }
      else if(a[(as+ae)/2]<b[(size-1)-(as+ae)/2]){
       as=(as+ae)/2;
      }
     }
     int tmp_min=(a[ae]<b[(size-1)-as])?a[ae]:b[(size-1)-as];
     int tmp_max=(a[as]>b[(size-1)-ae])?a[as]:b[(size-1)-ae];

     cout<<(tmp_min+tmp_max)/2<<endl;
     delete [] a;
     delete [] b;
     return 0;
    }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/6/14 14:11:00
     
     Supremgoooo 帅哥哟,离线,有人找我吗?
      
      
      等级:大四下学期(考上研究生啦!)
      文章:201
      积分:1872
      门派:XML.ORG.CN
      注册:2006/4/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Supremgoooo发送一个短消息 把Supremgoooo加入好友 查看Supremgoooo的个人资料 搜索Supremgoooo在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看Supremgoooo的博客7
    发贴心情 

    赞大家!!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/6/14 16:57:00
     
     toniee 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:4
      积分:71
      门派:XML.ORG.CN
      注册:2006/7/10

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给toniee发送一个短消息 把toniee加入好友 查看toniee的个人资料 搜索toniee在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看toniee的博客8
    发贴心情 
    好!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/7/10 20:05:00
     
     liustream 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:57
      门派:XML.ORG.CN
      注册:2006/5/25

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liustream发送一个短消息 把liustream加入好友 查看liustream的个人资料 搜索liustream在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liustream的博客9
    发贴心情 
    善!
    长见识了
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/7/17 17:54:00
     
     flykk 帅哥哟,离线,有人找我吗?天秤座1981-10-19
      
      
      等级:大一新生
      文章:2
      积分:73
      门派:IEEE.ORG.CN
      注册:2006/11/13

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给flykk发送一个短消息 把flykk加入好友 查看flykk的个人资料 搜索flykk在『 算法理论与分析 』的所有贴子 点击这里发送电邮给flykk 引用回复这个贴子 回复这个贴子 查看flykk的博客10
    发贴心情 
    int tmp_min=(a[ae]<b[(size-1)-as])?a[ae]:b[(size-1)-as];
    int tmp_max=(a[as]>b[(size-1)-ae])?a[as]:b[(size-1)-ae]
    是不是反了
    还有能不能把算法的原理说明一下

    ----------------------------------------------
    ieee.org.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/12/19 17:07:00
     
     GoogleAdSense天秤座1981-10-19
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 算法理论与分析 』的所有贴子 点击这里发送电邮给Google AdSense 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/6/16 15:03:40

    本主题贴数14,分页: [1] [2]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    109.375ms