Room and Moor

2023-10-19 17:30
文章标签 room moor

本文主要是介绍Room and Moor,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

11916: Room and Moor

时间限制: 6 Sec  内存限制: 256 MB
提交: 2  解决: 2
[提交] [状态] [命题人:外部导入]
题目描述
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:

 

输入
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 the minimal f (A, B) when B is optimal and round it to 6 decimals.

 

样例输入

复制样例数据

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
样例输出
1.428571
1.000000
0.000000
0.000000

 

#include <bits/stdc++.h>using namespace std;
typedef long long ll;
const int maxn = 3e5 + 10;
const ll mod = 1e9 + 7;
const double eps = 1e-7;
struct node {int cnt0, cnt1;double val;
} v[maxn];
int T, n, cnt;
int c[maxn];int main() {//freopen("1.txt", "r", stdin);stack<node> sk;scanf("%d", &T);while (T--) {scanf("%d", &n);for (register int i = 1; i <= n; ++i)scanf("%d", c + i);int l = 1, r = n;while (c[l] == 0 && l <= n)l++;while (c[r] == 1 && r >= 1)r--;if (l > r) {printf("0.000000\n");continue;}cnt = 0;for (register int i = l; i <= r;) {int n0 = 0, n1 = 0;while (c[i] == 1 && i <= r)i++, n1++;while (c[i] == 0 && i <= r)i++, n0++;v[++cnt].cnt0 = n0;v[cnt].cnt1 = n1;v[cnt].val = 1.0 * n1 / (double) (n0 + n1);//sk.push(v[cnt]);
        }//while (!sk.empty())sk.pop();for (register int i = 1; i <= cnt; ++i) {if (sk.empty())sk.push(v[i]);else {node last = sk.top();if (last.val <= v[i].val) {sk.push(v[i]);} else {node cur = v[i];while (true) {last = sk.top();if (cur.val < last.val) {cur.cnt0 += last.cnt0;cur.cnt1 += last.cnt1;cur.val = 1.0 * cur.cnt1 / (double) (cur.cnt0 + cur.cnt1);sk.pop();} else {sk.push(cur);break;}if (sk.empty()) {sk.push(cur);break;}}}}}node o;double res = 0;while (!sk.empty()) {o = sk.top();//cout<<"debug o.val="<<o.val<<' '<<"debug o.cnt0="<<o.cnt0<<' '<<"debug o.cnt1="<<o.cnt1<<endl;
            sk.pop();res += o.val * o.val * o.cnt0 + (1.0 - o.val) * (1.0 - o.val) * o.cnt1;}printf("%.6f\n", res);}return 0;
}

 

转载于:https://www.cnblogs.com/czy-power/p/11336551.html

这篇关于Room and Moor的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/241295

相关文章

【HDU】5566 Clarke and room【树链剖分+AC自动机】

题目链接:Clarke and room #include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define ls ( o << 1 )#define lson ls , l , m#define rs ( o << 1 | 1 )#define rson rs , m + 1 , r#define rt

R显卡VR性能如何?AMD发布 VRMark Cyan Room 测试结果

(52VR润饰原译文并重新进行编辑)       如果你曾通过 PC VR 头显来体验虚拟现实,你就会知道它们有能够提供一种所谓的“临场感”,亦即身临其境的感觉。如果你的PC无法及时渲染下一帧的影像,临场感就会被破坏,甚至消失。更糟糕的是,如果系统一直无法跟上,连续的掉帧将会令头显用户感到极其不舒服。为了避免这样的问题,VR规格的PC需要足够好、足够快速的CPU和GPU,以及合适

HDU 4923 (杭电多校 #6 1003题)Room and Moor(公式+栈)

题目地址:HDU 4923 比赛的时候脑残了。。思路完全想出来了。。只不过想出了个根本不可能存在的极端数据,然后一看输入数据是100组,就把自己给否决了。。。sad。。当时就应该大胆试一试的。。。 这个题首先可以把最前面的0和最后面的1去掉,因为这两块总可以用0和1抵消掉。然后中间就分成了10相间的情况,然后根据10相间,可以分成若干组,每一组都是由几个1和几个0组成的。比如说11011011

ViewModel(6)ViewModel与Room结合进行数据库操作。

当 ViewModel 与 Room 结合使用时,可以构建出高效且架构良好的 Android 应用。 首先,创建 Room 数据库、实体、DAO 等相关组件。例如,假设有一个 User 实体表示用户信息: @Entity(tableName = "users")public class User {@PrimaryKey(autoGenerate = true)private int id;

初探Jetpack(四) -- ROOM 数据库

初探Jetpack(一) – ViewModel 初探Jetpack(二) – Lifecycles 初探Jetpack(三) – LiveData Demo工程 Android 虽然自身携带SQLite,但是操作比较麻烦,而且如果再大型项目,会变得比较混乱且难以维护,除非你设计了一套非常好的架构和封装。 当然,如果要操作简单的话,郭老师的 Litepal 算不错的,不过我们今天学习 go

Codeforces 466B Wonder Room(暴力)

题目链接:Codeforces 466B Wonder Room 题目大意:给定n,a,b,要求找到ai,bi,(ai≥a, bi≥b)并且ai∗bi≥6∗n,并且ai∗bi要尽量小。 解题思路:枚举ai,根据6n算出需要的bi,注意ai只需要枚举到 6n ‾‾‾√ #include <cstdio>#include <cstring>#include <algorithm

HDU 4923 Room and Moor

题目链接~~> 做题感悟:比赛做这题是只考虑到前面 0 和后面 1 是没有用的其它的方面就没想法了,看了题解才明白…… 解体思路:                   首先考虑到的应该是前面的 0 和后面的 1 是没有用处的 ,那么剩下的就是前面是 1 ,后面是 0 的若干段 10 串,可以先分别处理每一段。                  这里每一段的数列中的值都是一样的且是平均数,解

【No More Room in Hell】地狱已满服务器一键开服多人联机教程

1、购买后登录服务器 进入控制面板后会出现正在安装的界面,安装大约5分钟(如长时间处于安装中请联系我们的客服人员) 2、连接游戏 2.1、安装完成后复制开机下方的IP地址 2.2、打开Steam点击左上角的查看➡服务器 点击收藏➡右下角+号 粘贴地址点击确定 2.3、选中添加的地址选择连接 至此开服教程就结束了!

Room注解无效原因

在Android项目中,如果父模块使用Kotlin,而子模块用Java编写,并且在子模块中使用了Room库,那么你会发现需要使用kapt而不是annotationProcessor来处理Room注解。这里有几个原因和背景知识: 1. 项目配置的影响 父模块的配置影响子模块: 当父模块使用Kotlin时,通常会在父模块的build.gradle文件中引入Kotlin插件,这样会使整个项目默认使

HDU 4923 Room and Moor【栈】【想法】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4923 题目大意:给你一串A = {A1, A2,..., AN}由{0,1}组成, 你要构造出一字符串 B = {B1, B2,... , BN}与A的长度相同。  求出这个最小值。 最开始见到这个题目先是想了想应该怎么做,比如先把A串处理一下。 1)把A前面的0去掉 2)把A后面的1去掉