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. Mysql隔离级别,锁与MVCC

    关键词:事务,ACID,隔离级别,MVCC,共享锁,排它锁 阅读本文前请先阅读http://hedengcheng.com/?p=771 http://www.hollischuang.com/arc ...

  2. ionic2 安装与cordova打包

    1.安装: cnpm install -g cordova ionic ionic start name cd name cnpm install   2.环境配置: http://www.cnblo ...

  3. UE4 unreliable 同步问题

    今天发现了一个问题,标记为unreliable的函数从来不执行,但是官方文档上的说明是只有在网络负载重时才不执行此类函数,哎哎哎.

  4. Runtime之NSCoding的自动归档、接档

    为什么要有Runtime的NSCoding的自动归档.接档 大家所熟知的方法 //归档方法 - (void)encodeWithCoder:(NSCoder *)aCoder { //当学生被归档,学 ...

  5. 转:绝对干货--WordPress自定义查询wp_query所有参数详细注释

    <?php /** * WordPress 查询综合参考 * 编译:luetkemj - luetkemj.com * * 官方文档: http://codex.wordpress.org/Cl ...

  6. 【Asp.net Core】在 Linux 子系统中安装 nginx 并配置反向代理

    上一篇鸟文中,老周已经介绍过在 Ubuntu 子系统中安装 dotnet-sdk 的方法,本文老周给大伙伴们说说安装 nginx 服务,并配置反向代理.同样,老周假设你从来没有用过 Linux,所以老 ...

  7. CSS background-clip 属性

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. SuperSocket基础一

    SuperSocket基础(一)——————基本概念 项目中之前一直使用TCP socket服务框架,但是不利于扩展.最近刚接触到开源的superSocket感觉很不错,特记录一下.官方开源地址:ht ...

  9. Redis跟Spring整合,sentinel模式

    普通模式整合 一.在pom.xml中引入redis的依赖 <dependency> <groupId>org.springframework.data</groupId& ...

  10. pipeline结合GridSearchCV的一点小介绍

    clf = tree.DecisionTreeClassifier() ''' GridSearchCV search the best params ''' pipeline = Pipeline( ...