Bestcoder#5 1003

Poor RukawTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24    Accepted Submission(s): 11

Problem Description

Last time, Hanamichi lost the basketball battle between him and Rukaw. So these days he had a burning desire to wreak revenge. So he invented a new game and asked Rukaw to play with him. What’s more, the loser should confess his ignorance and on the other hand the winner can go on a trip with Haruko.

Hanamichi knows the game well (as he invented it), and he always chooses the best strategy, however Rukaw is not so willing to play this game. He just wants it to be finished as soon as possible so that he can go to play basketball. So he decides not to think about the best strategy and play casually.

The game’s rules are here. At first, there are N numbers on the table. And the game consists of N rounds. Each round has a score which is the number of the numbers still left on the table. And Each round there will be one number to be removed from the table. In each round, two players take turns to play with these numbers.To be fair, Rukaw plays first in the first round. If there’s more than 1 numbers on the table, players can choose any two numbers they like and change them to a number abs(x-y). This round ends when there’s only one number left on the table, and if this number is an odd number, Rukaw wins, otherwise Hanamichi wins. The score of this round will be add to the winner. After that, all numbers will be recovered to the state when this round starts. And the loser of this round has the right to remove one number and he also has the right to play first in the next round. Then they use the remaining numbers to start next round. After N rounds, all numbers removed and this game ends. The person who has more scores wins the whole game.

As you know, Rukaw has already decided to play casually, that is to say, in his turn, he chooses numbers randomly, each numbers left on the table has the same possibility to be chosen. When a round ends, if Rukaw is the loser, he also randomly chooses a number to remove. And Hanamichi will always choose numbers or remove numbers to maxmium his final total score. Here comes the question:
Given the N numbers on the table at the beginning, can you calculate the expectation of the final score of Hanamichi. (We don’t care about who wins the whole game at all.)

Input

This problem contains multiple tests.
In the first line there’s one number T (1 ≤ T ≤ 200) which tells the total number of test cases. For each test case, there a integer N (1 ≤ N ≤ 1000) in the first line, and there are N intergers Ai , i = 1, 2, … , N (1 ≤ Ai ≤ 100000), in the second line which are the numbers at the beginning.

Output

This problem is intended to use special judge. But so far, BestCoder doesn’t support special judge. So you should output your answer in the following way. If the expectation you get is X, output \([3\times X+0.5]\) in a line. Here, [A] means the largest integer which is no more than A.

Sample Input

222 421 2

Sample Output

93

Hint

In the first example, Hanamichi will always win two rounds and the score of two rounds will be 2 and 1. So the answer is 3. (And you should output 9.) In the second example, Rukaw wins the first round. And after that Hanamichi has the right to choose a number from 1 and 2 to remove. (Because this round started with this two numbers.) And We know that he will choose 1 to maximum his final total score. So when the second round starts, there’s only one number 2 left on the table and Hanamichi plays first. He immediately wins this round and got 1 point. Then the game ends. So the answer is 1.(And you should output 3.)

错误点:概率dp,因为cnt没初始化,RE

思路:想到了奇偶关系以及转化关系,但是没有想到如何处理那么多状态,其实后面的状态是重复的,所以dp从后向前考虑就可以得到答案。。是不是概率dp都是这个思路??

 #include <vector>

 #include <cstdio>

 #include <cstring>

 #include <iostream>

 #include <algorithm>

 using namespace std;

 const int N = ;

 double func[][];

 int main()

 {

     func[][] = ;

     for(int i = ;i<N;i++)

         for(int j = ;j<=i;j++)

     {

         if(j%==)

         {

             func[i][j] = func[i-][j-];

         }

         else

         {

             func[i][j] = i+func[i-][j]*(i-j)*1.0/i+func[i-][j-]*j*1.0/i;

         }

     }

     int T,n,cnt=;

     scanf("%d",&T);

     while(T--)

     {

         cnt = ;

         scanf("%d",&n);

         int a;

         for(int i = ;i<n;i++)

         {

             scanf("%d",&a);

             if(a%==)

                 cnt++;

         }

         //cout<<n<<' '<<cnt<<endl;

         int ans = *func[n][cnt]+0.5;

         printf("%d\n",ans);

     }

     return ;

 }

Bestcoder#5 1003的更多相关文章

  1. HDU 4859(Bestcoder #1 1003)海岸线(网络流之最小割)

    题目地址:HDU4859 做了做杭电多校,知识点会的太少了.还是将重点放在刷专题补知识点上吧,明年的多校才是重点. 这题题目求的最长周长.能够试想一下,这里的海岸线一定是在"."和 ...

  2. HDU 5682/BestCoder Round #83 1003 zxa and leaf 二分+树

    zxa and leaf Problem Description zxa have an unrooted tree with n nodes, including (n−1) undirected ...

  3. BestCoder 1st Anniversary($) 1003 Sequence

    题目传送门 /* 官方题解: 这个题看上去是一个贪心, 但是这个贪心显然是错的. 事实上这道题目很简单, 先判断1个是否可以, 然后判断2个是否可以. 之后找到最小的k(k>2), 使得(m-k ...

  4. 从lca到树链剖分 bestcoder round#45 1003

    bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或) ...

  5. BestCoder Round #81 (div.2) 1003 String

    题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...

  6. BestCoder Round #29 1003 (hdu 5172) GTY's gay friends [线段树 判不同 预处理 好题]

    传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  7. DP BestCoder Round #50 (div.2) 1003 The mook jong

    题目传送门 /* DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp ...

  8. BestCoder Round #50 (div.1) 1003 The mook jong (HDU OJ 5366) 规律递推

    题目:Click here 题意:bestcoder 上面有中文题目 分析:令f[i]为最后一个木人桩摆放在i位置的方案,令s[i]为f[i]的前缀和.很容易就能想到f[i]=s[i-3]+1,s[i ...

  9. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

随机推荐

  1. 帆软报表FineReport数据连接中游标问题解决方案汇总

    1. 概念 在数据库中, 游标是一个十分重要的概念.游标是一种能从包括多条数据记录的结果集中,每次提取一条记录的机制. 用SQL语言从数据库中检索数据后,结果放在内存的一块区域中,往往是一个含有多个记 ...

  2. 洛谷P1415 拆分数列[序列DP 状态 打印]

    题目背景 [为了响应党中央勤节俭.反铺张的精神,题目背景描述故事部分略去^-^] 题目描述 给出一列数字,需要你添加任意多个逗号将其拆成若干个严格递增的数.如果有多组解,则输出使得最后一个数最小的同时 ...

  3. jdbcTemplate之jdbc模板技术

    1:为什么要使用jdbcTemplate? 在实际开发中使用jdbc技术太过复杂,为了减少代码冗余,操作简单 步骤一:创建实体类 package beans; public class Book { ...

  4. git clone Linux 源码并切换TAG

    想从github上下载一个特定TAG分支来查看代码,按照先git clone后git checkout的方式,提示说有文件没有提交.因为只查看不编译运行,所以这些关系不大的文件采取删除或者重新命名后提 ...

  5. LeetCode:Merge k Sorted Lists

    题目链接 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexi ...

  6. 利用 lucene.net 实现高效率的 WildcardQuery ,记一次类似百度搜索下拉关键字联想功能的实现。

    打开百度输入  站内搜索也要实现类似功能.最基础的做法,写个方法查数据库搜索历史综合表keywordSearch(先将被搜索过的关键字记录到一张表,记录好他们被搜索的次数.上次搜索的有多少结果) 大概 ...

  7. Android四大组件之—— 使用服务进行后台操作

    什么是服务 服务是一个没有可视化界面的组件,它可以在后台长期运行并进行各种操作. 服务的创建 我们只需要继承Service类并实现相应的方法即可创建服务 要想启动服务,还得在AndroidManife ...

  8. TAC 坦克队

    The Art of Code 团队成员 组长:   031402330吴宇轩 组员:   031402509胡泽善   031402224彭 巍   031402230张建明   031402508 ...

  9. SSH整合报错:No result defined for action and result input

    目前发现这个问题主要是在Action中的execute返回值时,没有对应的result name而引起的.很有可能是由于程序执行中出错了,但是对 应的Action中没有添加 input的result  ...

  10. Neural Style学习3——操作

    Basic usage: th neural_style.lua -style_image <image.jpg> -content_image <image.jpg> Ope ...