tle弃疗了

等着回学校找个标程拍一下吧

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
inline int read(){
char c=getchar(); int x=0,f=1;
while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
} int n, a[50], m, mid;
struct meow {
int w; double v;
meow() {}
meow(int a, double b) : w(a), v(b) {}
//bool operator <(const meow &a) const {return w == a.w ? v < a.v : w < a.w;}
} li[50];
vector<double> q1[50], q2[50]; void dfs(int u, int tar, int now_w, double now_v, vector<double> *q) { //printf("dfs %d %d\n", u, tar);
if(u == tar || (u != 1 && u != mid+1)) q[now_w + 20].push_back(now_v);
// printf("hi %d %lf\n", now_w, now_v);
if(u == tar) return;
for(int i=u; i<tar; i++) dfs(i+1, tar, now_w + li[i].w, now_v + li[i].v, q);
} int ans;
void solve(int l, int r) { //printf("\nsolve %d %d\n", l, r);
int _ans = 0;
m = 0; double aver = (double)(a[l] + a[r]) / 2.0;
for(int i=1; i<l; i++) li[++m] = meow(-1, a[i] - aver);
for(int i=r+1; i<=n; i++) li[++m] = meow(1, a[i] - aver);
//for(int i=1; i<=m; i++) printf("li %d %d %lf\n", i, li[i].w, li[i].v);
mid = m>>1;
for(int i=0; i<=40; i++) q1[i].clear(), q2[i].clear();
//printf("mmmm %d %d\n", m, mid);
if(mid) dfs(1, mid+1, 0, 0, q1);
if(m) dfs(mid+1, m+1, 0, 0, q2);
for(int i=0; i<=40; i++) {
int j = 40 - i;
vector<double> &a = q1[i], &b = q2[j];
if(a.empty() || b.empty()) continue; sort(a.begin(), a.end()); sort(b.begin(), b.end());
//printf("now %d %d\n", i-20, j-20);
//for(int i=0; i<a.size(); i++) printf("%lf ", a[i]); puts("");
//for(int i=0; i<b.size(); i++) printf("%lf ", b[i]); puts("");
int p1 = 0, p2 = b.size() - 1;
for(p1 = 0; p1 < a.size(); p1++) {
while(p2 >= 0 && a[p1] + b[p2] > 0) p2 --;
}
_ans += p2 + 1;
}
_ans += q1[20].size() + q2[20].size();
//printf("_ans %d\n", _ans);
_ans++;
ans += _ans;
} int main() {
freopen("in", "r", stdin);
n = read();
for(int i=1; i<=n; i++) a[i] = read();
sort(a+1, a+1+n);
for(int l=1; l<=n; l++) for(int r=l; r<=n; r++) solve(l, r);
//solve(2, 2);
printf("%d\n", ans);
}

#1280 : Rikka with Sequence II [meet int the middle]的更多相关文章

  1. 「10.13」毛一琛(meet in the middle)·毛二琛(DP)·毛三琛(二分+随机化???)

    A. 毛一琛 考虑到直接枚举的话时间复杂度很高,我们运用$meet\ in\ the\ middle$的思想 一般这种思想看似主要用在搜索这类算法中 发现直接枚举时间复杂度过高考虑枚举一半另一半通过其 ...

  2. HDU 5831 Rikka with Parenthesis II(六花与括号II)

    31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  3. HDU 5831 Rikka with Parenthesis II (栈+模拟)

    Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...

  4. hdu 5831 Rikka with Parenthesis II 线段树

    Rikka with Parenthesis II 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...

  5. HDU 5831 Rikka with Parenthesis II (贪心)

    Rikka with Parenthesis II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  6. hdu 5831 Rikka with Parenthesis II 括号匹配+交换

    Rikka with Parenthesis II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  8. HDU 5919 Sequence II 主席树

    Sequence II Problem Description   Mr. Frog has an integer sequence of length n, which can be denoted ...

  9. HDU 5919 Sequence II(主席树+逆序思想)

    Sequence II Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

随机推荐

  1. Sublime Text 3.0版本的傻瓜式汉化步骤

    Sublime text 3是非常好的文本编辑器,在试用过N款文本编辑器(Notepad.Notepad++.Notepad2.Programmer's notepad.EditPlus,Vim, T ...

  2. [国嵌笔记][012][GCC程序编译]

    GCC特点 GCC(GUN C Compiler)是GUN推出的功能强大.性能优越的多平台编译器.其执行效率与一般编译器相比平均效率要高20%~30%. GCC基本用法 gcc [options] f ...

  3. 初窥React Native

    这两天在学习react native,被虐得布耀布耀的,运行一个hello world花了一天时间(手动捂脸). 由于是跟着官网走,所以一开始便是开发环境的搭建.其他的就不说了(详情见 React N ...

  4. vuex的使用

    vue现在越来越火,不单单可以写简单的小项目,也可以写大中型的项目.但是项目大了,项目之间的数据传递就会变得复杂,那么问题来了?在一个大型项目中,多个组件要公用同一个或多个数据,我们如何保证每个组件获 ...

  5. Spark学习笔记2(spark所需环境配置

    Spark学习笔记2 配置spark所需环境 1.首先先把本地的maven的压缩包解压到本地文件夹中,安装好本地的maven客户端程序,版本没有什么要求 不需要最新版的maven客户端. 解压完成之后 ...

  6. php匹配图片、视频文件、音乐文件的正则表达式

    $pattern_video = "/(src)=(\\\?)([\"|']?)([^ \"'>]+\.(swf|flv|mp4|rmvb|avi|mpeg|ra| ...

  7. 学习总结:libevent--简单入门

    libevent--简单入门 一.简介 libevent是一个c语言写的事件驱动库,轻量级,专注于网络,跨平台特性好,支持多种 I/O 多路复用.支持I/O,定时器和信号等事件,允许设置注册事件优先级 ...

  8. 那些年~~~我们的C#笔试内测题目

    <深入.NET平台和C#编程>内部测试题-笔试试卷 一 选择题 1) 以下关于序列化和反序列化的描述错误的是( C). a) 序列化是将对象的状态存储到特定存储介质中的过程 b) 二进制格 ...

  9. 新版Azure Automation Account 浅析(一) --- 创建和Run As Account

    去年年底Azure中国的Automation Account悄悄做了升级.新版本不管从功能还是end user experience方面都让人耳目一新.如果说升级前只是一个运行脚本的小工具,升级后的A ...

  10. Hadoop问题:apt-get install docker-engine -> Depends: init-system-helpers (>= 1.18~) but 1.14 is to be installed

    问题描述:$ apt-get install docker-engine -> Depends: init-system-helpers (>= 1.18~) but 1.14 is to ...