📣 独立日限时特惠: VIP通行证立减$68
查看: 6770| 回复: 24
跳转到指定楼层
上一主题 下一主题
收起左侧

[入门|算法|数据结构] 2016 9月 Algorithm,Part1 week3 作业帖

全局:
公开课
学校名称: Princeton University
Unit号: 3
开课时间: 2016-09-02
课程全名: Algorithm,Part1
平台: Coursera

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
课程汇总 && 介绍:http://www.1point3acres.com/bbs/thread-200970-1-1.html

第三次作业,Collinear Points, 作业入口


上一篇:2016 9月 Algorithm,Part1 week4 作业帖
下一篇:2016 9月 Algorithm,Part1 week5 作业帖
全局:
哎改了好多遍 immutable那里始终通过不了
clone()也用了 还是不行...
现就这样了吧 心好累...

1490095762(1).png (24.66 KB, 下载次数: 7)

1490095762(1).png

评分

参与人数 1大米 +1 收起 理由
xujr + 1 我也是,深复制也不行

查看全部评分

回复

使用道具 举报

推荐
nsc 2017-2-28 17:13:54 | 只看该作者
全局:
immutable的问题后来解决了。花了很长时间。跟各位分享下。
因为时间过去很久了,大致思路是,java程序的输入还是输出的array,一定要在程序内做个copy,不是仅仅copy reference,是把reference所指向的object也copy了。这样,当程序外面的array有变化的时候,不会影响程序内的数据,就是immutable的了!
这是一种所谓的best practice吧。
以上供参考

评分

参与人数 1大米 +3 收起 理由
xujr + 3 感谢分享!

查看全部评分

回复

使用道具 举报

推荐
nsc 2016-11-17 17:12:09 | 只看该作者
全局:
程序里还有两个错误一直没解决。满分的同学能否给点提示?谢谢!

BruteCollinearPoints.java和FastCollinearPoints.java里各一个错误,类型相同。

Test 10: Check that data type is immutable by testing whether each method
        returns the same value, regardless of any intervening operations
  *  input8.txt
     -  failed after 12 operations involving BruteCollinearPoints
     -  first and last call to segments() returned different arrays
     -  sequence of operations was:
          BruteCollinearPoints collinear = new BruteCollinearPoints(points);
          collinear.numberOfSegments() -> 2
          collinear.numberOfSegments() -> 2
          mutate points[] array that was passed to constructor
          mutate points[] array that was passed to constructor
          collinear.numberOfSegments() -> 2
          mutate points[] array that was passed to constructor
          collinear.segments()
          mutate array returned by last call to segments()
          collinear.numberOfSegments() -> 2
          collinear.numberOfSegments() -> 2
          collinear.segments()
     -  failed on trial 1 of 100

  *  equidistant.txt
     -  failed after 9 operations involving BruteCollinearPoints
     -  first and last call to segments() returned different arrays
     -  sequence of operations was:
          BruteCollinearPoints collinear = new BruteCollinearPoints(points);
          mutate points[] array that was passed to constructor
          collinear.segments()
          collinear.numberOfSegments() -> 4
          mutate points[] array that was passed to constructor
          mutate array returned by last call to segments()
          collinear.numberOfSegments() -> 4
          mutate points[] array that was passed to constructor
          collinear.segments()
     -  failed on trial 1 of 100

==> FAILED

Test 13: Check that data type is immutable by testing whether each method
         returns the same value, regardless of any intervening operations
  *  input8.txt
     -  failed after 10 operations involving FastCollinearPoints
     -  first and last call to segments() returned different arrays
     -  sequence of operations was:
          FastCollinearPoints collinear = new FastCollinearPoints(points);
          collinear.numberOfSegments() -> 2
          collinear.segments()
          mutate points[] array that was passed to constructor
          collinear.segments()
          mutate array returned by last call to segments()
          mutate points[] array that was passed to constructor
          mutate points[] array that was passed to constructor
          collinear.numberOfSegments() -> 2
          collinear.segments()
     -  failed on trial 1 of 100

  *  equidistant.txt
     -  failed after 11 operations involving FastCollinearPoints
     -  first and last call to segments() returned different arrays
     -  sequence of operations was:
          FastCollinearPoints collinear = new FastCollinearPoints(points);
          collinear.numberOfSegments() -> 4
          collinear.numberOfSegments() -> 4
          collinear.segments()
          mutate points[] array that was passed to constructor
          collinear.segments()
          collinear.numberOfSegments() -> 4
          collinear.numberOfSegments() -> 4
          collinear.numberOfSegments() -> 4
          mutate array returned by last call to segments()
          collinear.segments()
     -  failed on trial 1 of 100

==> FAILED



补充内容 (2017-2-28 20:15):
immutable的问题后来解决了。补发下了思路。请帖子内找。
回复

使用道具 举报

🔗
zzdsg 2016-9-10 21:38:52 | 只看该作者
全局:
先后提交了九遍,看了网上的提示才得了满分。。。心累

无标题.png (20.08 KB, 下载次数: 0)

无标题.png
回复

使用道具 举报

🔗
youngyang 2016-9-22 22:12:00 | 只看该作者
全局:
适当的使用Arrays.sort()非常有用!

捕获.PNG (26.74 KB, 下载次数: 0)

捕获.PNG
回复

使用道具 举报

🔗
 楼主| minchen57 2016-9-24 05:45:07 | 只看该作者
全局:
交作业,



还是废了点时间的
回复

使用道具 举报

🔗
loveyomin 2016-9-25 21:01:46 | 只看该作者
全局:
请问,这个问题是啥问题?我程序里调用了point.toString()方法。。。
Test 8: Check for fragile dependence on return value of toString()
  *  filename = equidistant.txt
     -  student   solution has 1 non-null entries
     -  reference solution has 4 non-null entries
     -  3 missing entries in student solution, including: (30000, 0) -> (20000, 10000) -> (10000, 20000) -> (0, 30000)

  *  filename = input40.txt
     -  student   solution has 1 non-null entries
     -  reference solution has 4 non-null entries
     -  3 missing entries in student solution, including: (2000, 29000) -> (4000, 29000) -> (22000, 29000) -> (28000, 29000)

  *  filename = input48.txt
     -  student   solution has 1 non-null entries
     -  reference solution has 6 non-null entries
     -  5 missing entries in student solution, including: (1000, 26000) -> (9000, 26000) -> (11000, 26000) -> (18000, 26000)

==> FAILED
回复

使用道具 举报

🔗
Raymomd 2016-9-26 02:00:20 | 只看该作者
全局:
loveyomin 发表于 2016-9-25 21:01
请问,这个问题是啥问题?我程序里调用了point.toString()方法。。。
Test 8: Check for fragile dependen ...

就是没有找全所有的共线点
回复

使用道具 举报

🔗
Raymomd 2016-9-26 02:47:28 | 只看该作者
全局:
提交作业,没有满分的原因是改变了传入单数points,但是要用Arrays.sort 就会改变原点阵,除非重新建矩阵,但是这样多用了spacet

回复

使用道具 举报

🔗
loveyomin 2016-9-26 19:51:48 | 只看该作者
全局:
Raymomd 发表于 2016-9-26 02:47
提交作业,没有满分的原因是改变了传入单数points,但是要用Arrays.sort 就会改变原点阵,除非重新建矩阵, ...

effective java 里面建议 不要改变传入的参数,所以测试里才会有测试参数。。。points.clone()新建矩阵就好。空间满足题设要求,memory测试也是可以过的。。
回复

使用道具 举报

🔗
loveyomin 2016-9-26 19:53:12 | 只看该作者
全局:
Raymomd 发表于 2016-9-26 02:00
就是没有找全所有的共线点

嗯,错误提示是这个,但关键是,,,本机跑出来的结果是对的,比如第一个,他说student solution 1 non-null entries,但实际上我debug的结果就是4个。。。
回复

使用道具 举报

🔗
Raymomd 2016-9-26 21:55:24 | 只看该作者
全局:
loveyomin 发表于 2016-9-26 19:53
嗯,错误提示是这个,但关键是,,,本机跑出来的结果是对的,比如第一个,他说student solution 1 non-n ...

咦,你有testcode吗,哪里可以找到啊,我一开始和你有一样的问题,但后来发现还是没考虑所有情况
回复

使用道具 举报

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

本版积分规则

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