#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 ...
随机推荐
- 初识Spider_Man(爬爬虫)
一:引子
- iOS微信自动抢红包插件(支持后台和锁屏下抢红包)
前言:本文主要讲述使用hook方式实现红包插件,涉及到tweak相关知识,如果你不想了解具体实现细节可直接到我的Github地址参考安装(包含越狱和非越狱两种方法) 转眼间2017即将过去,又到了 ...
- logback的使用和logback.xml详解
一.logback的介绍 Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch.它当前分为下面下个模块: logback-core:其它两 ...
- str_repeat() 函数把字符串重复指定的次数。
str_repeat() 函数把字符串重复指定的次数. str_repeat(string,repeat) 参数 描述 string 必需.规定要重复的字符串. repeat 必需.规定字符串将被重复 ...
- -pie can only be used when targeting iOS 4.2 or later错误解决
在工程的build setting里,把IPHONEOS_DEPLOYMENT_TARGET改成4.2或以上就行了
- TCP是什么? 最简单的三次握手说明
TCP是什么? TCP(Transmission Control Protocol 传输控制协议)是一种面向连接(连接导向)的.可靠的. 基于IP的传输层协议.TCP在IP报文的协议号是6.TCP是一 ...
- c语言一个处理文本文件的例子
功能 读取一个文本文件,将其中的文本按规则转换为int数据,然后对数据进行处理.文本的格式类似36 565 233... 代码 #include <stdio.h> #include &l ...
- 转:Python之路,Day6 - 面向对象学习
这篇文章写的不错,转来收了 转自:http://www.cnblogs.com/alex3714/articles/5188179.html 本节内容: 面向对象编程介绍 为什么要用面向对象进 ...
- mybatis-XML配置文件
<?xml version="1.0" encoding="UTF-8" ?><!--plugins在配置文件中的位置必须要符合要求,否则会报 ...
- pycharm python模版样式
问题: 我想在创建新的一些python程序的时候,希望在新文件开头添加python版本声明和一些关于时间相关的模版数据 那,如何解决? 1. pycharm ---> setting ---&g ...