Bestcoder#5 1003

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都是这个思路??

 1 #include <vector>
 2
 3 #include <cstdio>
 4
 5 #include <cstring>
 6
 7 #include <iostream>
 8
 9 #include <algorithm>
10
11 using namespace std;
12
13
14
15 const int N = 1005;
16
17
18
19 double func[1005][1005];
20
21
22
23 int main()
24
25 {
26
27     func[0][0] = 0;
28
29     for(int i = 1;i<N;i++)
30
31         for(int j = 0;j<=i;j++)
32
33     {
34
35         if(j%2==1)
36
37         {
38
39             func[i][j] = func[i-1][j-1];
40
41         }
42
43         else
44
45         {
46
47             func[i][j] = i+func[i-1][j]*(i-j)*1.0/i+func[i-1][j-1]*j*1.0/i;
48
49         }
50
51     }
52
53     int T,n,cnt=0;
54
55     scanf("%d",&T);
56
57     while(T--)
58
59     {
60
61         cnt = 0;
62
63         scanf("%d",&n);
64
65         int a;
66
67         for(int i = 0;i<n;i++)
68
69         {
70
71             scanf("%d",&a);
72
73             if(a%2==1)
74
75                 cnt++;
76
77         }
78
79         //cout<<n<<‘ ‘<<cnt<<endl;
80
81         int ans = 3*func[n][cnt]+0.5;
82
83         printf("%d\n",ans);
84
85     }
86
87     return 0;
88
89 }
时间: 2024-10-12 00:46:50

Bestcoder#5 1003的相关文章

bestcoder #71 1003 找位运算&amp;的最大生成树

Clarke and MST Accepts: 33 Submissions: 92 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天克拉克变成了一名图论研究者. 他学习了最小生成树的几个算法,于是突发奇想,想做一个位运算and的最大生成树. 一棵生成树是由n-1n−1条边组成的,且nn个点两两可达.一棵生成树的大小等于所有在生成树上的边的权

BestCoder #45 1003 Dylans loves tree

problem 题意 给定一棵树,并给定在这棵树上的两种操作.一种操作是改变一个节点的权值,另外一个操作是对两个节点之间的路径上的权值进行统计,如果每个权值出现的次数都是偶数,输出-1,否则输出出现次数为奇数的权值(保证只有一个) 思路 这题是一个DFS序的模板题.首先想到,我们获得这棵树的DFS序,对于这个序列,我们可以去维护区间的异或和.由于是单点修改区间查询,可以用树状数组也可以直接写线段树.然后对于每个询问,我们查询出每个点到根的异或和(这里直接用DFS序中到根节点的异或和即可,因为如果

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

题目地址:HDU4859 做了做杭电多校,知识点会的太少了,还是将重点放在刷专题补知识点上吧,明年的多校才是重点. 这题题目求的最长周长,可以试想一下,这里的海岸线一定是在"."和"D"之间的,也就是说求最多的相邻的"."和"D"的配对对数.可以先转化成最小割求最小配对对数,因为总对数是一定的,只需要减去就行. 要先对周围填充上一圈的"D",然后变成了一个(n+2)*(m+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 edges, whose nodes are numbered from 1 to n. The degree of each node is defined as the number of the edges connected to it, and each node whose degree

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

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

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

题目传送门 1 /* 2 DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: 3 dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp[i][0] = dp[i-1][1] + dp[i-1][0]; 4 比赛时二维dp写搓了,主要是边界情况的判断出错,比如dp[3][1] = 1,因为第3块放了木桩,其他地方不能再放,dp[3][0]同理 5 解释一下dp[i][1]的三种情况,可能是前面相隔2个放的方案或者是不放的

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

传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 57 Problem Description GTY has n gay friends. To manage them conveniently, every morning he o

BestCoder 1st Anniversary($) 1003 Sequence

题目传送门 1 /* 2 官方题解: 3 这个题看上去是一个贪心, 但是这个贪心显然是错的. 4 事实上这道题目很简单, 先判断1个是否可以, 然后判断2个是否可以. 之后找到最小的k(k>2), 使得(m-k)mod6=0即可. 5 证明如下: 6 3n(n-1)+1=6(n*(n-1)/2)+1, 注意到n*(n-1)/2是三角形数, 任意一个自然数最多只需要3个三角形数即可表示. 7 枚举需要k个, 那么显然m=6(k个三角形数的和)+k, 由于k≥3, 只要m?k是6的倍数就一定是有解的

BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle

今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack> #include<vector> #include<map>