📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
楼主: 小狗雪碧
跳转到指定楼层
上一主题 下一主题
收起左侧

狗狗上门面经

🔗
umialpha 2019-3-7 11:29:58 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
umialpha 2019-3-7 11:35:39 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
umialpha 2019-3-7 14:43:56 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
umialpha 2019-3-7 14:58:31 | 只看该作者
全局:
按照烙印取了最左边的点,代码更短。
  1. def split_points(points):
  2.     # 去最左边最下面的点
  3.     st = [1 << 32, 1 << 32]
  4.     st_idx = None
  5.     for i, (px, py) in enumerate(points):
  6.         if px < st[0] or px == st[0] and py < st[1]:
  7.             st = px, py
  8.             st_idx = i

  9.     points.pop(st_idx)
  10.     INF = 1 << 31
  11.     def cmp(p):
  12.         k = (p[1] - st[1]) * 1.0 / (p[0] - st[0]) if p[0] != st[0] else INF
  13.         return k
  14.     # 按照斜率排序
  15.     points = sorted(points, key=cmp)
  16.     mid = points[len(points) / 2]
  17.    
  18.     return st, mid
复制代码
回复

使用道具 举报

🔗
visa 2019-3-7 15:15:06 | 只看该作者
全局:
umialpha 发表于 2019-3-7 14:43
这一题我后来仔细写了一下,终于理解了烙印给的提示, 最下面最左边的点,可以保证其余点在这个点的一侧, ...

层主你好,我觉得是不是任意一点都可以找到一点把平面上的点分成两等分啊,下面是我用c++写的一份代码
  1. Skip to content

  2. Search or jump to…

  3. Pull requests
  4. Issues
  5. Marketplace
  6. Explore
  7. @xczhang07 Sign out
  8. 1
  9. 0 0 xczhang07/leetcode
  10. Code  Issues 0  Pull requests 0  Projects 0  Wiki  Insights  Settings
  11. leetcode/google_interview/divide_points_in_matrix.cpp
  12. @xczhang07 xczhang07 Create divide_points_in_matrix.cpp
  13. 4a363ec  a day ago
  14. 59 lines (53 sloc)  1.38 KB
  15.    

  16. int dividePoint(pair<int, int> p1, pair<int, int> p2, pair<int, int> p)
  17. {
  18.         int d = (p.first - p1.first)*(p2.second - p1.second) - (p.second - p1.second)*(p2.first-p1.first);
  19.         return d;
  20. }

  21. pair<vector<pair<int,int>>, vector<pair<int,int>>> dividePoints(vector<pair<int, int>>& points)
  22. {
  23.         pair<vector<pair<int,int>>, vector<pair<int,int>>> ret;
  24.         if (points.size() <= 2)
  25.                 return ret;
  26.         auto point1 = points[0];
  27.         vector<pair<int, int>> up;
  28.         vector<pair<int, int>> bottom;
  29.         for (int i = 1; i < points.size(); ++i)
  30.         {
  31.                 auto point2 = points[i];
  32.                 for (int i = 0; i < points.size(); ++i)
  33.                 {
  34.                         auto t = points[i];
  35.                         if ((t.first == point1.first && t.second == point1.second) || (t.first == point2.first && t.second == point2.second))
  36.                                 continue;
  37.                         int d = dividePoint(point1, point2, t);
  38.                         if (d > 0)
  39.                                 up.push_back(t);
  40.                         else
  41.                                 bottom.push_back(t);
  42.                 }
  43.                 if (up.size() == bottom.size())
  44.                         return make_pair(up, bottom);
  45.                 else
  46.                 {
  47.                         up.clear();
  48.                         bottom.clear();
  49.                 }
  50.         }
  51.         return ret;
  52. }

  53. int main()
  54. {
  55. vector<pair<int, int>> points = { {1,1}, {2,2}, {2,3},{2,4},{-1,0},{-3,-4} };

  56.         pair < vector<pair<int,int>>, vector<pair<int, int>> > partition = dividePoints(points);
  57.         for (auto e : partition.first)
  58.         {
  59.                 cout << "(" << e.first << "," << e.second << ")" << " ";
  60.         }
  61.         cout << endl;

  62.         for (auto e : partition.second)
  63.         {
  64.                 cout << "(" << e.first << "," << e.second << ")" << " ";
  65.         }
  66.         cout << endl;
  67. return 0;
  68. }
复制代码
回复

使用道具 举报

🔗
visa 2019-3-7 15:16:32 | 只看该作者
全局:
  1. int dividePoint(pair<int, int> p1, pair<int, int> p2, pair<int, int> p)
  2. {
  3.         int d = (p.first - p1.first)*(p2.second - p1.second) - (p.second - p1.second)*(p2.first-p1.first);
  4.         return d;
  5. }

  6. pair<vector<pair<int,int>>, vector<pair<int,int>>> dividePoints(vector<pair<int, int>>& points)
  7. {
  8.         pair<vector<pair<int,int>>, vector<pair<int,int>>> ret;
  9.         if (points.size() <= 2)
  10.                 return ret;
  11.         auto point1 = points[0];
  12.         vector<pair<int, int>> up;
  13.         vector<pair<int, int>> bottom;
  14.         for (int i = 1; i < points.size(); ++i)
  15.         {
  16.                 auto point2 = points[i];
  17.                 for (int i = 0; i < points.size(); ++i)
  18.                 {
  19.                         auto t = points[i];
  20.                         if ((t.first == point1.first && t.second == point1.second) || (t.first == point2.first && t.second == point2.second))
  21.                                 continue;
  22.                         int d = dividePoint(point1, point2, t);
  23.                         if (d > 0)
  24.                                 up.push_back(t);
  25.                         else
  26.                                 bottom.push_back(t);
  27.                 }
  28.                 if (up.size() == bottom.size())
  29.                         return make_pair(up, bottom);
  30.                 else
  31.                 {
  32.                         up.clear();
  33.                         bottom.clear();
  34.                 }
  35.         }
  36.         return ret;
  37. }

  38. int main()
  39. {
  40. vector<pair<int, int>> points = { {1,1}, {2,2}, {2,3},{2,4},{-1,0},{-3,-4} };

  41.         pair < vector<pair<int,int>>, vector<pair<int, int>> > partition = dividePoints(points);
  42.         for (auto e : partition.first)
  43.         {
  44.                 cout << "(" << e.first << "," << e.second << ")" << " ";
  45.         }
  46.         cout << endl;

  47.         for (auto e : partition.second)
  48.         {
  49.                 cout << "(" << e.first << "," << e.second << ")" << " ";
  50.         }
  51.         cout << endl;
  52. return 0;
  53. }
复制代码
回复

使用道具 举报

🔗
umialpha 2019-3-7 15:51:21 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
umialpha 2019-3-7 15:56:23 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
umialpha 2019-3-7 16:03:39 | 只看该作者
全局:
第五轮是不是要和面试官讨论以下几点:1.是否nested。 2. 这样的情况['a','b','a']是不是应该返回['a',1],['b',1],['a',1]。 还有什么情况呢?
回复

使用道具 举报

🔗
hanover 2019-3-7 21:47:02 | 只看该作者
全局:
点的问题有问题,如果所有的点都在一条直线上,是做不到的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表