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. 状压dp初探

    写了几道状压...然后就一直在颓废... 2064: 分裂 http://www.lydsy.com/JudgeOnline/problem.php?id=2064 初始的为正,最后的为负,假设我们能 ...

  2. UVA 572 dfs求连通块

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  3. 访问 Tomcat支配项目去除项目名和端口号通过IP地址(或域名)访问

    Tomcat去除项目名称和端口号 1. 去除端口号 将端口设为80: <Connector port="80" protocol="HTTP/1.1" c ...

  4. 基于 fireasy 构建的 asp.net core 示例

    最近花时间弄了一个关于fireasy使用的demo,已放到 github 上供大家研究,https://github.com/faib920/zero 该 demo 演示了如何使用 fireasy 创 ...

  5. JavaScript八张思维导图—编程实践

    JS基本概念 JS操作符 JS基本语句 JS数组用法 Date用法 JS字符串用法 JS编程风格 JS编程实践 不知不觉做前端已经五年多了,无论是从最初的jQuery还是现在火热的Angular,Vu ...

  6. 访问网站出现 Directory Listing Denied This Virtual Directory 

    出现这个提示是指没有在您指定的目录找到默认首页,比如您直接输入域名访问空间, 但是出现以上提示,那么请检查目录下是否有 index.htm,index.html,index.asp,default.a ...

  7. ==和equals详解+例子

    一开始遇见==和equals我也是分不清,后来看了很多博客,收益匪浅, 担心以后给忘了,所以写下这个,以后复习可以用. (有哪里写得不对的,希望可以留言帮忙改进,大家一起共同进步) 一.Java数据类 ...

  8. Vuejs技术栈知识点小结

    前言 上家公司的项目主要是使用jQuery和Angular1,然后自己学了React,没想到来到这家公司突然开始做vue,不过vue还是挺容易上手的.下面是vue技术栈的一些总结,都是来自官网,主要是 ...

  9. HTTP常用状代码

    2XX 成功 204 Not Content 请求处理成功,但没有资源可以返回. 1 put请求:该资源已存在于服务器上 2 delete请求:该资源已从服务器上删除 200 OK 请求正常处理 20 ...

  10. JS的for循环小例子

    1.输出1-100的和 var sum = 0; for(var i=1;i<=100;i++){ sum = sum + i; } document.write(sum); 2.输出1-100 ...