hdu 4923 第六次多校
2014-08-07 17:47
176 查看
Room and Moor
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 79 Accepted Submission(s): 12
Problem Description
PM Room defines a sequence A = {A1, A2,..., AN}, each of which is either 0 or 1. In order to beat him, programmer Moor has to construct another sequence B = {B1, B2,... , BN} of the same length,
which satisfies that:
Input
The input consists of multiple test cases. The number of test cases T(T<=100) occurs in the first line of input.
For each test case:
The first line contains a single integer N (1<=N<=100000), which denotes the length of A and B.
The second line consists of N integers, where the ith denotes Ai.
Output
Output the minimal f (A, B) when B is optimal and round it to 6 decimals.
Sample Input
4 9 1 1 1 1 1 0 0 1 1 9 1 1 0 0 1 1 1 1 1 4 0 0 1 1 4 0 1 1 1
Sample Output
1.428571 1.000000 0.000000 0.000000
Source
2014 Multi-University Training Contest 6
Recommend
hujie | We have carefully selected several similar problems for you: 4930 4929 4928 4927 4926
贪心即可 用栈维护区间递增,如果比栈顶小,就合并区间,直到合法为止;
然后每个区间f(a,b)=x*y/(x+y), x代表区间内1的个数,y代表区间内0的个数。
代码:
#include <cstdio> #include <stack> using namespace std; struct Node { int ae, be; double ce; void init() { ce=double(be)/double(ae+be); } }; int main () { //freopen("data.in","r",stdin); int n,T,date,oldDate; int BB; int BH; int a,b; double ans; Node temp; stack<Node> q; scanf("%d",&T); while (T--) { scanf("%d",&n); a=0,b=0,BB=0,BH=0; oldDate=1; for (int i=0;i<n;i++) { scanf("%d",&date); if((date!=oldDate)&&i!=0) { temp.ae=a; temp.be=b; temp.init(); while (!q.empty()&&temp.ce<q.top().ce) { temp.ae=temp.ae+q.top().ae; temp.be=temp.be+q.top().be; temp.init(); q.pop(); } q.push(temp); if(date==0) { a=1; b=0; } else {a=0; b=1;} } else { if(date==0) { a++; } else { b++; } } if((i==n-1)&&date==0) { temp.ae=a; temp.be=b; temp.init(); while (!q.empty()&&temp.ce<q.top().ce) { temp.ae=temp.ae+q.top().ae; temp.be=temp.be+q.top().be; temp.init(); q.pop(); } q.push(temp); } oldDate=date; } ans=0; while (!q.empty()) { ans+=q.top().ce*q.top().ae; q.pop(); } printf("%.6f\n",ans); } return 0; }
相关文章推荐
- HDU 4923 (杭电多校 #6 1003题)Room and Moor(公式+栈)
- HDU 4923 Room and Moor (多校第六场C题) 单调栈
- 2014多校联合六(HDU 4923 HDU 4925 HDU 4927 HDU 4930)
- HDU 4923 Room and Moor (多校第六场C题) 单调栈
- hdu 4923 Room and Moor(数学题)2014多校训练第6场
- HDU-4923 Room and Moor 多校对抗之数学题
- hdu 5289 Assignment(2015多校第一场第2题)RMQ+二分(或者multiset模拟过程)
- HDU 5378 Leader in Tree Land(2015 多校第7场 dp)
- HDU 4335What is N?2012多校联赛第四场(欧拉函数+坑数据)
- HDU 4861(多校)1001 Couple doubi
- hdu 多校联赛 Counting Divisors
- HDU杭电2013 多校第一场解题报告
- hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语
- 2013 多校联合 F Magic Ball Game (hdu 4605)
- 2016 多校最后一题 (HDU 5724) Chess (组合博弈)
- HDU 5387 Clock(模拟)——(多校练习8)
- Limited Permutation HDU - 6044 多校1
- [2015hdu多校联赛补题]hdu5384 Danganronpa
- 2013 多校第一场 hdu 4609 3-idiots(FFT)
- 多校第一场 1009 hdu 5296 Annoying problem(dfs序+在线倍增lca)