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. 87. Scramble String

    题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...

  2. 49. Anagrams

    题目: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will ...

  3. Splunk常用命令

    重启/查看状态/停止splunk [root@localhost splunk]# /opt/splunk/bin/splunk restart / status / stop

  4. phantomjs使用说明

    phantomjs使用说明 12条评论   phantomjs实现了一个无界面的webkit浏览器.虽然没有界面,但dom渲染.js运行.网络访问.canvas/svg绘制等功能都很完备,在页面抓取. ...

  5. JDBC学习总结(一)

    1.JDBC概述     JDBC是一种可以执行SQL语句并可返回结果的Java API,其全称是Java DataBase Connectivity,也是一套面向对象的应用程序接口API,它由一组用 ...

  6. NDK(17)让ndk支持完整C++,exception,rtti,

    C++ Support The Android platform provides a very minimal C++ runtime support library (/system/lib/li ...

  7. AVL的旋转

    转自http://blog.csdn.net/gabriel1026/article/details/6311339 平衡二叉树在进行插入操作的时候可能出现不平衡的情况,AVL树即是一种自平衡的二叉树 ...

  8. next_permutation()函数 和 prev_permutation() 按字典序求全排列

    next_permutation功能:    求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm> 与之完全相反的函数还有prev_permutation 这个 ...

  9. UVa 11997 (优先队列 多路归并) K Smallest Sums

    考虑一个简单的问题,两个长度为n的有序数组A和B,从每个数组中各选出一个数相加,共n2中情况,求最小的n个数. 将这n2个数拆成n个有序表: A1+B1≤A1+B2≤... A2+B1≤A2+B2≤. ...

  10. UVa 10837 (欧拉函数 搜索) A Research Problem

    发现自己搜索真的很弱,也许做题太少了吧.代码大部分是参考别人的,=_=|| 题意: 给出一个phi(n),求最小的n 分析: 回顾一下欧拉函数的公式:,注意这里的Pi是互不相同的素数,所以后面搜索的时 ...