HDU 4923 Room and Moor(瞎搞题)

瞎搞题啊。找出1 1 0 0这样的序列,然后存起来,这样的情况下最好的选择是1的个数除以这段的总和。

然后从前向后扫一遍。变扫边进行合并。每次合并。合并的是他的前驱。这样到最后从t-1找出的那条链就是最后满足条件的数的大小。

Room and Moor

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 307    Accepted Submission(s): 90


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
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <map>
#include <set>
#define eps 1e-9
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?

0:x) using namespace std; const int maxn = 1000010; int num[maxn]; int sum[maxn][2]; int pre[maxn]; double x[maxn]; int main() { int T; cin >>T; while(T--) { int n; scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d",&num[i]); int t = 0; int cnt1 = 0; int cnt2 = 0; if(!num[0]) cnt1 = 1; if(num[0]) cnt2 = 1; for(int i = 1; i < n; i++) { if(num[i] > num[i-1]) { sum[t][0] = cnt1; sum[t++][1] = cnt2; cnt1 = cnt2 = 0; if(!num[i]) cnt1++; if(num[i]) cnt2++; continue; } if(!num[i]) cnt1++; if(num[i]) cnt2++; } sum[t][0] = cnt1; sum[t][1] = cnt2; t++; for(int i = 0 ; i < t; i++) x[i] = (1.0*sum[i][1]/((sum[i][0]+sum[i][1])*1.0)); pre[0] = -1; for(int i = 1; i < t; i++) { if(x[i] < x[i-1]) { sum[i][0] += sum[i-1][0]; sum[i][1] += sum[i-1][1]; x[i] = 1.0*sum[i][1]/(sum[i][1]+sum[i][0])*1.0; pre[i] = pre[i-1]; int p = pre[i]; while(p != -1) { if(x[i] < x[p]) { sum[i][0] += sum[p][0]; sum[i][1] += sum[p][1]; x[i] = 1.0*sum[i][1]/(sum[i][0]+sum[i][1])*1.0; pre[i] = pre[p]; p = pre[p]; continue; } break; } continue; } pre[i] = i-1; } int p = pre[t-1]; double ans =0; ans += sum[t-1][0]*pow(x[t-1], 2)+sum[t-1][1]*pow(x[t-1]-1, 2); while(p != -1) { ans += sum[p][0]*pow(x[p], 2)+sum[p][1]*pow(x[p]-1, 2); p = pre[p]; } printf("%.6lf\n",ans); } return 0; }



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541337.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java define_Java Long类的define()方法与示例

java define长类解码()方法 (Long class decode() method) decode() method is available in java.lang package. 在java.lang包中提供了define ()方法 。 decode() method is used to decode the given String value into a Long value. encode()方法用于将给定的String值解码…

linux修改文件用户组,linux命令 修改文件、文件夹所属用户、用户组

最近学习hadoop&#xff0c;在替换配置文件的时候&#xff0c;发现老是报错&#xff0c;没有权限替换。我们知道如何改变文件的用户组与拥有者了&#xff0c;那么&#xff0c;什么时候要使用chown或chgrp呢&#xff1f;或许你会觉得奇怪吧&#xff1f;是的&#xff0c;确实有时…

Kotlin 开篇

Kotlin 是一个基于 JVM 的新的编程语言&#xff0c;由 JetBrains 开发官网地址&#xff1a;http://kotlinlang.org。JetBrains&#xff0c;作为目前广受欢迎的 Java IDE IntelliJ 的提供商&#xff0c;在 Apache 许可下已经开源其Kotlin 编程语言。开源地址&#xff1a;https:/…

inputstream示例_Java InputStream close()方法与示例

inputstream示例InputStream类close()方法 (InputStream Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this InputStream and free all system resources linked with this stream…

linux下的文件系统,Linux根文件系统(“/”文件系统)下的目录介绍

Linux下的文件存储与Windows完全不同&#xff0c;Windows将系统文件存储在系统盘(比如说C:\下)Linux根本没有盘符到概念只有一个根文件系/&#xff0c;各个磁盘分区挂载在/media/下(或者/mnt/下)/下到如/etc,/proc,/bin,/dev,lib等很是让用惯了Windows的用户不解&#xff0c;下…

greenlet 详解

greenlet初体验回到顶部Greenlet是python的一个C扩展&#xff0c;来源于Stackless python&#xff0c;旨在提供可自行调度的‘微线程’&#xff0c; 即协程。generator实现的协程在yield value时只能将value返回给调用者(caller)。 而在greenlet中&#xff0c;target.switch&am…

Java Calendar toString()方法与示例

日历类toString()方法 (Calendar Class toString() method) toString() method is available in java.util package. toString()方法在java.util包中可用。 toString() method is used to string denotations of the calendar object. toString()方法用于对日历对象的符号进行字…

linux虚拟机怎么看var文件,一种获取Linux虚拟机内部日志的方法

一种获取Linux虚拟机内部日志的方法【技术领域】[0001]本发明涉及云计算管理技术领域&#xff0c;特别是指一种获取Linux虚拟机内部日志的方法。【背景技术】[0002]在云计算环境下&#xff0c;虚拟机被广泛使用&#xff0c;对于虚拟机的维护要求越来越高&#xff0c;当虚拟机出…

详细图解mongodb 3.4.1 win7x64安装

原文&#xff1a;http://www.cnblogs.com/yucongblog/p/6895983.html 详细图解&#xff0c;记录 win7 64 安装mongo数据库的过程。安装的版本是 MongoDB-win32-x86_64-2008plus-ssl-3.4.1-signed。 我下载的源文件&#xff1a;mongodb-win32-x86_64-2008plus-ssl-3.4.1-signed我…

java calendar_Java Calendar complete()方法与示例

java calendarCalendar类的complete()方法 (Calendar Class complete() method) complete() method is available in java.util package. complete()方法在java.util包中可用。 complete() method is used to fills in any non-set fields in the calendar fields. complete()方…

LXD 2.0 系列(十二):调试,及给 LXD 做贡献

介绍 终于要结束了&#xff01;这个大约一年前开始的这系列文章的最后一篇博文。 LXD 入门安装与配置你的第一个 LXD 容器资源控制镜像管理远程主机及容器迁移LXD 中的 DockerLXD 中的 LXD实时迁移LXD 和 JujuLXD 和 OpenStack调试&#xff0c;及给 LXD 做贡献如果你从一开始就…

linux用ping命令测试网速,linux下面使用命令测试网速

大家都知道在speedtest是市面上最准确最全面的测速工具&#xff0c;但在linux命令行不能直接使用&#xff0c;所以我们就借助脚本调用speedtest的接口来利用他测试网速。1.下载speedtest-cli脚本&#xff1a;下载地址&#xff1a;https://raw.githubusercontent.com/sivel/spee…

Java ArrayList isEmpty()方法与示例

ArrayList类isEmpty()方法 (ArrayList Class isEmpty() method) isEmpty() method is available in java.util package. isEmpty()方法在java.util包中可用。 isEmpty() method is used to check whether this Arraylist is "empty" or "not empty". isEmp…

linux家用系统版本,查看linux系统版本

篇一&#xff1a;linux下如何查看系统和内核版本linux下如何查看系统和内核版本 1. 查看内核版本命令&#xff1a;1) [rootq1test01 ~]# cat /proc/versionLinux version 2.6.9-22.ELsmp (bhcompilecrowe.devel.redhat.com) (gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)) #1…

python中locked_Python锁类| 带示例的locked()方法

python中lockedPython Lock.locked()方法 (Python Lock.locked() Method) locked() is an inbuilt method of the Lock class of the threading module in Python. Locked()是Python中线程模块的Lock类的内置方法。 This method returns True if the lock is acquired by a th…

rocksdb ubuntu c++源码编译测试

2019独角兽企业重金招聘Python工程师标准>>> 环境&#xff1a; ubuntu16.4 需要安装 snappy gflage bz2 zstd 以及g 其中zstd是facebook开放源代码里的压缩的库 git clone https://github.com/facebook/rocksdb.git cd rocksdb make static_lib 成功生成 librocksd…

vs生成linux服务器程序,从Visual Studio到Linux上调试C++代码

从Visual Studio到Linux上调试C代码04/30/20155 分钟可看完本文内容[原文发表时间] 2015/4/29 10:00 PM正如您可能已经听说的那样&#xff0c;Visual Studio 2015新推出了对Android开发的GDB支持。有趣的是&#xff0c;因为这项功能依赖GDB调试&#xff0c;我们完全可能稍加改动…

java clock计时_Java Clock类| 实例的Instant()方法

java clock计时Clock Class Instant()方法 (Clock Class instant() method) instant() method is available in java.time package. Instant()方法在java.time包中可用。 instant() method is used to get the current instant that is used with this Clock. Instant()方法用于…

使用国内DOCKER镜像源

在国内&#xff0c;通过Docker的pull和push命令访问hub.docker时&#xff0c;网络十分慢&#xff0c;而且会出现各种各样的网络连接问题。因此这里介绍下如何使用国内的镜像源&#xff0c;这里以DaoCloud为例。注册DaoCloud用户;注册完成后&#xff0c;会进入dashboard页面&…

linux命令top查看进程,linux 查看进程的命令(top)

标签&#xff1a;top操作系统支持多任务并不是计算机同时做很多事情&#xff0c;而是快速的轮换着执行这些任务。linux安排不同的程序等待使用CPU。进程的工作方式&#xff1a;当系统启动的时候&#xff0c;内核先把自己的程序初始化为进程&#xff0c;然后运行一个init的程序&…