微软面试题[1-2]

1.Given a rectangular(cuboidal for the puritans) cake whith a rectangular piece removed (
any size or orientation), how would you cut the remainder of the cake into two equal halves with one straight cut of a knife?

译:给定一块已在任意位置用任意方向切去一个矩形块的矩形蛋糕(注意是立体的,质量均匀的),怎样用一刀切出相等重量的两块来?

 

找出这两个矩形块的中心点m和n,然后切面a可以垂直矩形的任意面,但是必须过m和n点,这样切后的两块蛋糕在体积上是相等了

 

2. You're given anarray containing both positive and negative integers and required to find thesub-array with the largest sum (O(N) a la KBL). Write a routine in C for theabove.

一个矩阵中包含正数和负数,要求寻找和最大的子矩阵

int main()
{
 
 int a[] ={ -2,30,-5,-13,-19,1,-3,2};
 int len=8;
 int sum=0,beg=0,end=0,maxBeg=0,maxEnd=0,maxSum=0,i=0;
 maxBeg=i;
 maxEnd=i;

 while (i < len)
 {
  sum +=a [ i ];
  if( sum > maxSum )
  {
   maxSum = sum;
   maxEnd = end;
   maxBeg = beg;
  }
  else if( sum < 0 )
  {
   beg = i + 1;
   sum = 0;
  }
  i++;
  end++;
 }
   
    printf("beg %d,end %d,sum %d",maxBeg,maxEnd,maxSum);
 
 
 return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值