SQYBI.com

Change is a part of life, and takes part in finding us who we are.

TopCoder SRM 413

| 11 Comments

Div 2果然是水题.第一次SRM,变黄.
yuhch不好好出题啊...
此文测试插件用 有爱者可以忽略

第一题,纯水.贴TC的标程:

double minTime(int length, int maxAcceleration, int maxVelocity) {
  double t1 = sqrt(length / double(maxAcceleration));
  if(maxAcceleration * t1 > maxVelocity) {
    double t2 = maxVelocity / double(maxAcceleration);
    return (length - maxAcceleration * t2 * t2) / maxVelocity + 2 * t2;
  } else
    return 2 * t1;
}

第二题,我的做法是求解一大堆不等式:
假设给出了a0,a1,a2,...其中a1,a2...分别等于[a1],[a2]...,那么
a1-a0<=d<a1-a0+1
a2-a0<=2*d<a2-a0+1
...
TC给出的代码如下:

double minCommonDifference(int a0, vector  seq) {
  // fraction representing 0/1 (minimum permissible value)
  pair  res(0, 1);
  // find d
  for(int i = 0; i < seq.size(); ++i)
    if(res.first * (i + 1) < (seq[i] - a0) * res.second) {
      res.first = seq[i] - a0;
      res.second = i + 1;
    }
  // check whether a solution is possible
  for(int i = 0; i < seq.size(); ++i)
    if(seq[i] != a0 + (i + 1) * res.first / res.second)
      return -1;
  return res.first / double(res.second);
}

出现问题了...先测试到这里

刚才看了一下,Zoundry瞎改HTML.没办法,以后只能到blog后台来写了...装个增强的WYSIWYG插件去...

update:WLW竟然可以用!没想到啊.
继续写完.

第三题看似范围很大,实际用到的状态并不多,所以开一个map做记忆化搜索就解决问题.继续贴TC的代码:

map  mem;
long long calc(long long n, int p, int q) {
  if(n == 0)
    return 1;
  if(mem.count(n))
    return mem[n];
  mem[n] = calc(n / p, p, q) + calc(n / q, p, q);
  return mem[n];
}

这次题目就这样,很水了...
WLW似乎也把line参数给吞了...泪奔...

关闭了可视化编辑器,希望这次能行...
以后就得这么发代码了...

You May Like These:

  1. UVa 102 -- Ecological Bin Packing
  2. DS大作业的两段代码
  3. UVa 100 -- The 3n + 1 problem
  4. 私密:测试Nxun的代码高亮插件
  5. TopCoder入门教程 -- sqybi完善版

Author: sqybi

理工男,宅男,闵行MIT荣誉出品。

11 Comments

  1. 话说……这个网站速度真是……有点无语……我家IE都打不开 用FX才打开的…… 尴尬……

  2. 恭喜 网速快了不少

  3. 这个语法高亮的插件不错, 叫什么? 顺便, 把我的Blog的链接加上吧. 我马上加你的

  4. 話說...topcoder有給出題解? 謝謝給個地址= =~

  5. @sai901013: 一般比赛结束后几周会在首页放出...好久不TC了,具体在哪儿我也不清楚...

  6. 正在调试....不知道是哪个插件的问题

  7. 当然了....因为我换了这个主题....原先是主题的问题

  8. 我的Gravatar怎么没显示出来?!

  9. 链接已经加上
    语法高亮插件叫wp-syntax 似乎所有语法高亮插件都要后台直接修改HTML代码,不然就用不了...不知道有没有能在WYSIWYG编辑器里用的语法高亮?
    gravatar的问题正在解决 已经有方案了..只不过没时间

  10. 哦.. 原来只有回复的时候才显示, 真bug

  11. 好了, 你的链接我加了

发表评论

Required fields are marked *.

*


请使用@user: comment的格式来回复一个人的评论, 或者直接点击评论后的"回复". 例如:
@sqybi: 你好!
这样sqybi将会收到一封通知邮件.