Chinaunix首页 | 论坛 | 博客
  • 博客访问: 988356
  • 博文数量: 150
  • 博客积分: 3017
  • 博客等级: 少校
  • 技术积分: 3829
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-19 14:40
个人简介

Now in Baidu WISE team

文章分类

全部博文(150)

文章存档

2014年(8)

2013年(31)

2012年(111)

分类: Python/Ruby

2012-06-12 11:37:54

 

 

 


 

点击(此处)折叠或打开

  1. my @a = qw/1 2 3 4 5/;
  2. my @b = qw/1 2 3 4 5/;
  3. my ($x, $y) = (0.5, 4);

  4. my $start = 0;
  5. my $end = 4;

  6. my $cursor;

  7. while(1){

  8.     last if(($end - $start) == 1);
  9.     $cursor = int(($start+$end)/2);
  10.     my $v = $a[$cursor]*$x + $b[$cursor];

  11.     if($y>$v){
  12.         $start = $cursor;
  13.         next;
  14.     }
  15.     if($y<$v){
  16.         $end = $cursor;
  17.         next;
  18.     }
  19. }
  20. print "Start = $start End = $end \n";


 

阅读(698) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~