O(1) 的小乐

Job Hunting

公告

记录我的生活和工作。。。
<2011年2月>
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

统计

  • 随笔 - 182
  • 文章 - 1
  • 评论 - 41
  • 引用 - 0

留言簿(10)

随笔分类(70)

随笔档案(182)

文章档案(1)

如影随形

搜索

  •  

最新随笔

最新评论

阅读排行榜

评论排行榜

TCO Round1

1 比较简单,不过不是那么容易想。
  给定初始字符串,然后两个缓冲队列,把初始字符串经过一部分操作变成目标字符串。
 
  由于具有两个缓冲队列,而且初始字符串中字符只有两类,所以可以一次搞定!利用substr() 判断一下就OK
 
2  应该观察到对最后的期望有贡献的只是具有连续洼地的地方,所以只要枚举出现连续洼地的期望就可以了,复杂度是O(n^2)的,然后下面的代码就非常清楚了!主要是没有注意这个关键点!
class MuddyRoad{
  public:
  double getExpectedValue(vector <int> road){
    vector<double> prob;
    for(int i=0;i<road.size();i++)prob.push_back((double)road[i]/100);
    int n=prob.size();
    double ans=0;
    for(int i=1;i<=n-2;i++){
      for(int j=i;j<=n-2;j++){
        int c=(j-i+1)/2;
        double p=1;
        p*=(1-prob[i-1]);
        p*=(1-prob[j+1]);
        for(int k=i;k<=j;k++)p*=prob[k];
        ans+=p*c;
      }
    }
    return ans;
  }
};

当时比赛的时候,我在想DP的状态转移,貌似写挫了,不太清楚O(n)的算法思路和我的是否相似。。
 
 
3
看来还是蛮简单的,就是一个容斥原理啊,复杂度是O(nlogn)+O(n)* O(容斥)
容斥其实是蛮难做的!看下面这个:
The simplest approach would be to go over all 1,000,000,000,000 IP addresses individually, and for each one, check all the requests to see who offers the highest price, and then add that to the total.

This works perfectly except it will obviously be too slow. So instead of looking at individual IP addresses, we should partition the set of all IP addresses, so that each part will be assigned to a single buyer. Then, we simply need to find the size and price for each part, and we can easily multiply and add them together.

For example, if we have requests for "1.2.3.0", "1.2.3.1" and "1.2.3.*" then interesting parts would be {"1.2.3.0"}, {"1.2.3.1"}, and {"1.2.3.2","1.2.3.3",...,"1.2.3.999"}. All of these can be represented implicitly if we take a special value (like -1 in bmerry's code) to mean "all other, unused values".

Since the interesting values for each component come from the N requests in the input, there are at most N4 parts to check (or (N+1)4 in bmerry's code). With an additional loop for each part this yields an O(N5) algorithm.

posted on 2011-06-26 13:21 Sosi 阅读(202) 评论(1)  编辑 收藏 引用

评论

# re: TCO Round1 2011-07-26 16:14 双星休闲鞋

看得还真是挺复杂的。
  回复  更多评论    

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


统计系统