#1280 : Rikka with Sequence II [meet int the middle]
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]的更多相关文章
- 「10.13」毛一琛(meet in the middle)·毛二琛(DP)·毛三琛(二分+随机化???)
A. 毛一琛 考虑到直接枚举的话时间复杂度很高,我们运用$meet\ in\ the\ middle$的思想 一般这种思想看似主要用在搜索这类算法中 发现直接枚举时间复杂度过高考虑枚举一半另一半通过其 ...
- HDU 5831 Rikka with Parenthesis II(六花与括号II)
31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- HDU 5831 Rikka with Parenthesis II (栈+模拟)
Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...
- hdu 5831 Rikka with Parenthesis II 线段树
Rikka with Parenthesis II 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...
- HDU 5831 Rikka with Parenthesis II (贪心)
Rikka with Parenthesis II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- hdu 5831 Rikka with Parenthesis II 括号匹配+交换
Rikka with Parenthesis II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- HDU 5919 Sequence II(主席树+逆序思想)
Sequence II Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
随机推荐
- BZOJ3109: [cqoi2013]新数独
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...
- oracle erp 表结构
BOM模块常用表结构 表名: bom.bom_bill_of_materials 说明: BOM清单父项目 BILL_SEQUENCE_ID NUMBER 清单序号(关键字)ASSEMBLY_ITEM ...
- net+Oracle开发过程中遇到的小问题
最新的项目开始使用Oracle后,5个月之间遇到一些在SqlServer中没有遇到的问题,这里记录并贴上一些常用的解决办法. Oracle相关 一.数据库不同版本还原: 刚开始我们一直使用Oracle ...
- 《SpringMVC从入门到放肆》四、SpringMVC配置式开发(处理器映射器)
上一篇我们讲解了DispatcherServlet的url-pattern配置详解,今天我们来真正对SpringMVC进行配置式开发.所谓配置式开发是指“处理器类是程序员自己定义的.实现了特定接口的类 ...
- python面向对象进阶
前言 上节大话python面向对象对面向对象有了一些了解,这次就不用大话风格了 (ps:真心不好扯啊) isinstance与issubclass isinstance(obj,cls)检查是否obj ...
- kali中的webshell
webacoo -g 生成一句话 -o 输出文件 -r 不混淆代码 -t 连接模式 -u 制定URL 生成一句话 webacoo -g -o a.php 连接一句话 webacoo -t -u htt ...
- 织梦dedecms中arclist标签下无法嵌套图片
版权声明:本文为博主原创文章,未经博主允许不得转载. 错误代码: {dede:arclist row=10 orderby=click titlelen=35} [field:title/] {/de ...
- Linux 将本地文件上传Linux服务器, 即ssh 命令上传本地文件
http://blog.csdn.net/rodulf/article/details/71169996 利用ssh传输文件 在linux下一般用scp这个命令来通过ssh传输文件. 1.从服务器上下 ...
- SSL协议之数据加密过程详解
前言 总括: 原文博客地址:SSL协议之数据加密过程详解 知乎专栏&&简书专题:前端进击者(知乎)&&前端进击者(简书) 博主博客地址:Damonare的个人博客 生活 ...
- Linuxc - gdb调试程序
指针实现变量交换值 #include <stdio.h> void change(int *a,int *b) { int tmp = *a; *a = *b;// 将指针a所在地址的值, ...