【HDU】4923 Room and Moor(2014多校第六场1003)
Room and Moor
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 263 Accepted Submission(s): 73
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.
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std; #define eps 0.00000001
const int LEN = ; int arr[LEN];
struct line
{
int l, r, sum;
double rate;
}; stack<line> s; int main()
{
int T, n;
line tmp;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for(int i = ; i < n; i++)
scanf("%d", arr+i);
int h = ;
while(arr[h] == )
h++;
int k = n - ;
while(arr[k] == )
k--;
for(int i = h; i <= k; i++){
if (i == h || i > h && arr[i-] == && arr[i] == ){
tmp.l = i;
tmp.sum = ;
}
if (i < k && arr[i] == && arr[i+] == || i == k){
tmp.r = i;
//printf("l = %d, r = %d\n", tmp.l, tmp.r);
tmp.rate = tmp.sum * 1.0 / ((tmp.r - tmp.l + ) * 1.0);
//printf("rate=%f\n", tmp.rate);
while(true){
if (s.empty() || s.top().rate - tmp.rate < eps){
s.push(tmp);
break;
}
if (s.top().rate - tmp.rate > eps){
tmp.l = s.top().l;
tmp.sum += s.top().sum;
tmp.rate = tmp.sum*1.0 / ((tmp.r - tmp.l + )*1.0);
s.pop();
}
}
}
if (arr[i] == )
tmp.sum++;
}
double ans = ;
while(!s.empty()){
ans += (( - s.top().rate) * ( - s.top().rate) * s.top().sum + s.top().rate * s.top().rate * (s.top().r - s.top().l + - s.top().sum));
s.pop();
}
printf("%f\n", ans);
}
return ;
}
【HDU】4923 Room and Moor(2014多校第六场1003)的更多相关文章
- HDU 4923 Room and Moor (多校第六场C题) 单调栈
Problem Description PM Room defines a sequence A = {A1, A2,..., AN}, each of which is either 0 or 1. ...
- 2014多校第七场1003 || HDU 4937 Lucky Number
题目链接 题意 : 给定一个十进制n,让你转化成某个进制的数,让这个数只包含3 4 5 6这些数字,这个进制就成为n的幸运数字,输出有多少幸运数字,例如19,5进制表示是34,所以5是19的一个幸运数 ...
- 2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)
题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. #inc ...
- 2014多校第六场 1007 || HDU 4927 Series 1(杨辉三角组合数)
题目链接 题意 : n个数,每操作一次就变成n-1个数,最后变成一个数,输出这个数,操作是指后一个数减前一个数得到的数写下来. 思路 : 找出几个数,算得时候先不要算出来,用式子代替,例如: 1 2 ...
- 2014多校第六场 1005 || HDU 4925 Apple Tree
题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
- HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)
题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...
- 多校第六场 1003 hdu 5355 Cake(贪心)
题目链接:(数据加强后wa了) hdu 5355 题目大意: 给出一个蛋糕.切成1~n大小的n块.问是否能在不继续分割的情况下拼凑出m等份. 题目分析: 首先我们是可以知道每份蛋糕的尺寸的,利用n*( ...
- HDU 4923 Room and Moor(推理+栈维护)
HDU 4924 Room and Moor 题目链接 题意:给定一个01组成的a序列.要求一个b序列,b序列每一个数值为[0, 1]之间的数,而且b序列为非递减序列,要求∑(ai−bi)2最小,求这 ...
随机推荐
- 正三角形的外接圆面积,nyoj-274
正三角形的外接圆面积 时间限制:1000 ms | 内存限制:65535 KB 难度:0 描述给你正三角形的边长,pi=3.1415926 ,求正三角形的外接圆面积. 输入 只有一组测试数据 ...
- Razor学习(二)@Html标签
原文链接:http://blog.csdn.net/pasic/article/details/7093802 只是因为原文作者说的东西,还有很多作为基础知识的东西,我都没有掌握,所以总结在这里,蓝字 ...
- python学习day10
目录 Twisted Redis RabbitMQ Twisted 事件驱动 事件驱动分为两个部分:第一,注册事件:第二,触发事件. 自定义事件启动框架,命名为:"弑君者" ...
- android的edittext输入长度
http://blog.csdn.net/uyu2yiyi/article/details/6329738 http://flysnow.iteye.com/blog/828415/ http://s ...
- Visual Studio 2015 Update 3 RC 候选预览版粗来了
.Net 基金会 http://www.dotnetfoundation.org/ 更新的真快,刚打完2的补丁包,3就粗来了............ https://www.visualstudio. ...
- C#调用API函数EnumWindows枚举窗口的方法
原文 http://blog.csdn.net/dengta_snowwhite/article/details/6067928 与C++不同,C#调用API函数需要引入.dll文件,步骤如下: 1. ...
- eclipse启动tomcat 访问http://localhost:8080 报404错误
eclipse启动tomcat 访问http://localhost:8080 报404错误 Server Locations修改后会变灰,如果需要更改设置,则需要移除与Tomcat服务器关联的项目, ...
- C语言的本质(20)——预处理之二:条件预处理和包含头文件
我们可以通过定义不同的宏来决定编译程序对哪些代码进行处理.条件编译指令将决定那些代码被编译,而哪些是不被编译的.可以根据表达式的值或者某个特定的宏是否被定义来确定编译条件. 条件编译可分为三种情况,按 ...
- Sereja and Coat Rack(水)
Sereja and Coat Rack Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- UVA 1623 Enter The Dragon
题意: 一只龙,在每个不下雨的日子都可以喝干一个湖里的水,当湖满时,再向这个湖里下雨就会溢出.给出下雨的顺序,求龙喝水的序列. 分析: 记录每个湖上次满水的日子,和不下雨的日子.下雨时,查找当前湖上次 ...