ABC见上一篇

感觉这场比赛很有数学气息。

D:

  显然必须要贴着之前的人坐下。

  首先考虑没有限制的方案数。就是2n - 1(我们把1固定,其他的都只有两种方案,放完后长度为n)

  我们发现对于一个限制,比它小的限制只有可能在它的一边。

  于是对于有限制的一段,我们可以找到最靠近边界的两个限制,取其中最大的限制,递归计算向比它小的限制的方向走它的限制步所覆盖的一段,这一段应该包含目前区间内所有的限制,剩下的就是没有限制的,可以直接计算。

mycode:

/*
* Problem: Sereja and Cinema
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 100010, MOD = 1000000007LL; int n, a[MAXN], sum[MAXN];
long long inv[MAXN], f[MAXN], finv[MAXN]; long long comb(int x, int y) {
return f[x + y] * finv[x] % MOD * finv[y] % MOD;
} long long func(int l, int r) {
long long ans;
if (sum[l - 1] == sum[r]) {
ans = 1;
int i;
for (i = l; i < r; ++i)
ans = (ans << 1) % MOD;
return ans;
}
int p, q;
for (p = l; p <= r; ++p)
if (a[p])
break;
for (q = r; q >= l; --q)
if (a[q])
break;
if (p == q && a[p] == 1)
return comb(p - l, r - p);
ans = 0;
int x, y;
if (a[p] >= a[q]) {
x = p;
y = x + a[p] - 1;
if (y >= q && y <= r)
ans += func(x + 1, y) * comb(x - l, r - y);
}
if (a[p] <= a[q]) {
y = q;
x = y - a[q] + 1;
if (x >= l && x <= p)
ans += func(x, y - 1) * comb(x - l, r - y);
}
return ans % MOD;
} int main(/*int argc, char **argv*/) {
int i; scanf("%d", &n);
sum[0] = 0;
for (i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
sum[i] = sum[i - 1] + (a[i] != 0);
}
inv[1] = 1;
for (i = 2; i < MAXN; ++i)
inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
f[0] = finv[0] = 1;
for (i = 1; i < MAXN; ++i) {
f[i] = f[i - 1] * i % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
printf("%I64d", func(1, n)); fclose(stdin);
fclose(stdout);
return 0;
}

E:

  这个题目我们可以发现实际上就是取一个区间的数集{a[i]},所求就是:1/2 * a[1] + 1/4 * a[2] + 1/8 * a[3] + ……,由于精度所以我们可以忽视a[50]以后的。

  我们可以考虑一个数为结果带来的代价。我们考虑比V大的数,Let the position of elements on the left: p1> p2> ... > Ps1. And positions right: q1 < q2 < ... < qs2.这样它带来的代价就是

  mycode:

/*
* Problem: Sereja and Dividing
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 300010; int n, a[MAXN];
std::vector<std::pair<int, int> > v;
std::set<int> s; double solve(int x) {
double two, c1, c2;
int cnt, prev, y;
s.insert(x);
std::set<int>::iterator it = s.find(x);
two = 1.0;
cnt = 0;
prev = x;
c1 = 0.0;
while (cnt < 50) {
y = *(--it);
c1 += (prev - y) * two;
if (y == 0)
break;
++cnt;
two /= 2.0;
prev = y;
}
it = s.find(x);
two = 1.0;
cnt = 0;
prev = x;
c2 = 0.0;
while (cnt < 50) {
y = *(++it);
c2 += (y - prev) * two;
if (y == n + 1)
break;
++cnt;
two /= 2.0;
prev = y;
}
return c1 * c2;
} int main(/*int argc, char **argv*/) {
int i;
double ans; scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", a + i);
for (i = 1; i <= n; ++i)
v.push_back(std::make_pair(-a[i], i));
std::sort(v.begin(), v.end());
s.insert(0);
s.insert(n + 1);
ans = 0.0;
for (i = 0; i < n; ++i)
ans += solve(v[i].second) * a[v[i].second];
printf("%.9lf", ans / 2.0 / n / n); fclose(stdin);
fclose(stdout);
return 0;
}

Codeforces 380 简要题解的更多相关文章

  1. Codeforces 863 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 简要题解?因为最后一题太毒不想写了所以其实是部分题解... A题 传送门 题意简述:给你一个数,问你能不能通过加前导000使其成为一个回文数 ...

  2. Codeforces 381 简要题解

    做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...

  3. Codeforces 1120 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 传送门 A题 传送门 题意简述:给你一个mmm个数的数列,现在规定把一个数列的1,2,...,k1,2,...,k1,2,...,k分成第一组,把k+1, ...

  4. Codeforces 1098 简要题解

    文章目录 前言 A题 B题 C题 D题 E题 传送门 前言 没错因为蒟蒻太菜了这场的最后一道题也咕掉了,只有AAA至EEE的题解233 A题 传送门 题意简述:给出一棵带点权的树,根节点深度为111, ...

  5. Codeforces 1110 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 众所周知ldxoildxoildxoi这种菜鸡选手是不会写HHH题的,因此该篇博客只有AAA题至GGG题的题解,实在抱歉. A题 传送门 题 ...

  6. Codeforces 845 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 A题 传送门 题意:2n2n2n个人下棋,分为两个阵营,每个阵营nnn个人,每个人有一个积分,积分高的能赢积分低的,问如果你可以随意选人,然 ...

  7. Codeforces 1065 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 GGG题略难,膜了一波zhouyuyang{\color{red} zhouyuyang}zhouyuyang巨佬的代码. 其余都挺清真的. ...

  8. Codeforces 888 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 A题 传送门 题意简述:给一个数列,问有多少个峰值点(同时比两边都大/小的点) 思路:按照题意模拟. 代码: #include<bit ...

  9. Codeforces 884 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 传送门 A题 传送门 题意简述: 一个人要完成一件事总共需要ttt秒,现在有nnn天,每天有aia_iai​不能做事,问他可以在第几天做完. 思路:按照题 ...

随机推荐

  1. NSPoint

    #import <Foundation/Foundation.h>   int main(int argc, const char * argv[]) {    @autoreleasep ...

  2. 1、探究java方法参数传递——引用传递?值传递!

    原创博文,转载请注明出处.谢谢~~ java程序运行时,其对象是怎么进行放置和安排的呢?内存是怎么分配的呢?理解好这个很有好处!java有5个地方可以存储数据: 1.寄存器.这是最快的存储区,位于处理 ...

  3. linux用dd测试磁盘速度

    [root@localhost ~]# time dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file记录了1000000+0 的读入记录了100000 ...

  4. linux系统的文件类型学习

    linux是一个文件型操作系统,在linux下一切皆文件. 目录.字符设备.块设备.管道.套接字.符号连接文件等在linux下统统都是文件. linux下的文件类型分为以下几种类型: 1. 正规文件, ...

  5. C# Index 定义索---引具体使用

    using System;using System.Collections.Generic;namespace TestThisIndex{    public class Program    {  ...

  6. BZOJ 2323 细胞(矩阵)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2323 题意: 题意过于复杂,我直接简化下.给出一个长度为n的数字串,只包含1到9,将数字 ...

  7. sh.exe": grunt: command not found

    今天在git命令行工具中使用 grunt的时候,总是提示我找不到grunt命令,如: sh.exe": grunt: command not found 但是我运行 npm install ...

  8. Careerdesign@foxmail.com

    Careerdesign@foxmail.com 相关文章 32岁了,我还有没有机会转行做程序员吗? 如何有效渡过充满迷茫的大学生活 毕业了,我是先择业,还是先就业? 程序员创业,不要把风险带给家人! ...

  9. poj 3792 Area of Polycubes (简单模拟)

    题目 题意:在三维坐标系中,给定n个立方体的中心坐标,立方体的边长为1,按照输入顺序,后来输入的必须和之前输入的立方体有公共的边. 而且,不能和之前输入的立方体相同. 如果满足条件,输出表面积.如果不 ...

  10. 解析CSS加密技术之“障眼法”

    CSS(Cascading Style Sheet,可译为“层叠样式表”或“级联样式表”)是一组格式设置规则,用于控制Web页面的外观.通过使用CSS样式设置页面的格式,可将页面的内容与表现形式分离. ...