题解:

虽然是过了,不过做的十分智障

首先是有 2根 2 1 1 , 3根 1 1 1

这两种方法

然后考虑2 2 1 1

two-point-two没啥好说的

3 1 1 1

我很智障的以为数据范围是1e9

然后写了hash,刚开始还开错范围

把int换short int才卡过了空间

首先枚举 1 1 1

然后枚举3 中的一条边

既然1e7直接记录每个数能由两个数组成的方案数

另外再减去这条边参与的方案数(直接两个数减一下查有几个就好了)

然后细节还挺多的搞个对拍就可以了

#pragma G++ optimize (2)
#include <bits/stdc++.h>
using namespace std;
#define N 6000
#define rg register
#define IL inline
#define ll long long
int a[N],n;
unsigned ll ans,ans3;
#define js(x) x*(x-1)/2*(x-2)/3*(x-3)/4
const int mo1=1.3e7+;
const int NN=1.3e7+1e5;
const int mo2=2.6e7+;
const int N2=2.6e7+1e5;
int hash1[NN],hash2[NN],hash4[N2];
short int hash3[N2],hash5[N2];
char ss[<<],*A=ss,*B=ss;
inline char gc(){return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;}
template<class T>void read(T&x){
rg int f=,c;while(c=gc(),c<||<c)if(c=='-')f=-;x=c^;
while(c=gc(),<c&&c<)x=(x<<)+(x<<)+(c^);x*=f;
}
IL void push(int x)
{
int y=x%mo1;
while (hash1[y]&&hash1[y]!=x) y++;
hash1[y]=x; hash2[y]++;
}
IL int find1(int x)
{
int y=x%mo1;
while (hash1[y]&&hash1[y]!=x) y++;
if (hash1[y]==x) return(hash2[y]);
else return();
}
IL void push2(int x,int y)
{
int z=(1ll*y*+x)%mo2;
while (hash3[z]&&!(hash3[z]==x&&hash4[z]==y)) z++;
hash3[z]=x; hash4[z]=y; hash5[z]++;
}
IL int find2(int x,int y)
{
int z=(1ll*y*+x)%mo2;
while (hash3[z]&&!(hash3[z]==x&&hash4[z]==y)) z++;
if (hash3[z]==x&&hash4[z]==y) return(hash5[z]);
else return();
}
IL bool cmp(int a,int b)
{
return(a<b);
}
int now,cnt;
#define INF 1e9
int main()
{
freopen("noi.in","r",stdin);
freopen("noi.out","w",stdout);
read(n);
for (rg int i=;i<=n;i++) read(a[i]);
sort(a+,a+n+,cmp);
for (rg int i=;i<=n;i++)
for (rg int j=i+;j<=n;j++)
push(a[i]+a[j]);
a[]=INF;
for (rg int i=;i<=n;i++)
for (rg int j=i+;j<=n;j++)
push2(i,a[i]+a[j]),push2(j,a[i]+a[j]);
now=;
while (++now<=n)
{
cnt=;
while (now<n&&a[now+]==a[now]) cnt++,now++;
if (cnt>=)
{
int h=,t=n;
ll ans2=;
while (h<t)
{
int h1=h,t1=t;
while (a[h]==a[h+]&&h<t) h++;
while (a[t]+a[h]>a[now]&&h<t) t--;
if (a[t]+a[h]!=a[now])
{
h++;
continue;
}
t1=t;
while (a[t]==a[t-]&&h<t) t--;
if (h==t)
{
int xx=t1-h1+;
if (t1-h1+>=) ans+=1ll*cnt*(cnt-)/*js(xx);
ans+=1ll*ans2*cnt*(cnt-)/*(t1-h1+)*(t1-h1)/;
break;
}
if (h-h1>=&&t1-t>=)
{
ans+=1ll*cnt*(cnt-)/*(h-h1)*(h-h1+)/*(t1-t)*(t1-t+)/;
}
ans+=1ll*cnt*(cnt-)/*ans2*(t1-t+)*(h-h1+);
ans2+=(t1-t+)*(h-h1+);
h++;
}
}
if (cnt>=)
{
rg ll ans2=1ll*cnt*(cnt-)*(cnt-)/;
unsigned rg ll ans4=;
for (rg int i=;i<=n;i++)
{
if (a[now]>a[i])
{
int x=find1(a[now]-a[i]);
int y=find2(i,a[now]-a[i]);
ans4+=1ll*(x-y)*ans2;
}
}
ans3+=ans4/;
}
}
//ans3/=3;
cout<<ans+ans3<<endl;
return ;
}

对拍 n^6

#include <bits/stdc++.h>
using namespace std;
#define rg register
#define N 10000
#define rep(i,x,y) for (rg int i=x;i<=y;i++)
int b[];
bool cmp(int x,int y)
{
return(x<y);
}
int a[N],n;
bool pd1(int x1,int x2,int x3,int x4,int x5,int x6)
{
b[]=a[x1],b[]=a[x2],b[]=a[x3],b[]=a[x4],b[]=a[x5],b[]=a[x6];
sort(b+,b++,cmp);
if (b[]+b[]==b[]+b[]&&b[]+b[]==b[]&&b[]==b[])
return(); else return();
}
bool pd2(int x1,int x2,int x3,int x4,int x5,int x6)
{
b[]=a[x1],b[]=a[x2],b[]=a[x3],b[]=a[x4],b[]=a[x5],b[]=a[x6];
sort(b+,b++,cmp);
if (b[]+b[]+b[]==b[]&&b[]==b[]&&b[]==b[])
return(); else return();
}
int main()
{
freopen("noi.in","r",stdin);
freopen("noi2.out","w",stdout);
std::ios::sync_with_stdio(false);
cin>>n;
for (int i=;i<=n;i++) cin>>a[i];
int cnt=,cnt2=;
rep(i1,,n)
rep(i2,i1+,n)
rep(i3,i2+,n)
rep(i4,i3+,n)
rep(i5,i4+,n)
rep(i6,i5+,n)
if (pd1(i1,i2,i3,i4,i5,i6))
{ cnt++;
}
rep(i1,,n)
rep(i2,i1+,n)
rep(i3,i2+,n)
rep(i4,i3+,n)
rep(i5,i4+,n)
rep(i6,i5+,n)
if (pd2(i1,i2,i3,i4,i5,i6))
{
// cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<endl;
cnt++;
}
cout<<cnt+cnt2<<endl;
return ;
}

【BZOJ4927】第一题 双指针+DP的更多相关文章

  1. 【BZOJ4927】第一题 双指针+DP(容斥?)

    [BZOJ4927]第一题 Description 给定n根直的木棍,要从中选出6根木棍,满足:能用这6根木棍拼 出一个正方形.注意木棍不能弯折.问方案数. 正方形:四条边都相等.四个角都是直角的四边 ...

  2. 【2019多校第一场补题 / HDU6578】2019多校第一场A题1001Blank——dp

    HDU6578链接 题意 有一串字符串,仅由 {0,1,2,3}\{0, 1, 2, 3\}{0,1,2,3} 组成,长度为 nnn,同时满足 mmm 个条件.每个条件由三个整数组成:l.r.xl.r ...

  3. hdu 1520 Anniversary party(第一道树形dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...

  4. [算法 笔记]2014年去哪儿网 开发笔试(续)第一题BUG修正

    上一篇的blog地址为:http://www.cnblogs.com/life91/p/3313868.html 这几天又参加了一个家公司的笔试题,在最后的编程题中竟然出现了去哪儿网开发的第一题,也就 ...

  5. 《学习OpenCV》练习题第五章第一题ab

    这道题是载入一幅带有有趣纹理的图像并用不同的模板(窗口,核)大小做高斯模糊(高斯平滑),然后比较用5*5大小的窗口平滑图像两次和用11*11大小的窗口平滑图像一次是否接近相同. 先说下我的做法,a部分 ...

  6. 《学习OpenCV》练习题第四章第一题b&c

    #include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...

  7. 《学习OpenCV》练习题第四章第一题a

    #include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...

  8. Google Code Jam 第一题

    通过的第一题,留做纪念,呵呵,非常简单,Africa 2010, Qualification Round: Store Credit. #include <stdio.h> #includ ...

  9. 图论测试题(一)第一题:longest

    第一题:longest 乌托邦有n个城市,某些城市之间有公路连接.任意两个城市都可以通过公路直接或者间接到达,并且任意两个城市之间有且仅有一条路径(What does this imply? A tr ...

随机推荐

  1. luogu P1081 开车旅行

    传送门 这题的暴力做法显然是照题意模拟,从每个点出发暴力跳.而这个暴跳显然是可以倍增优化的,就是预处理出从每个点,(一开始是A)往后跳\(2^k\)步,能到哪里,以及\(A\)和\(B\)的路程,然后 ...

  2. CF28D Don't fear, DravDe is kind

    传送门 题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求 ...

  3. Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;

    Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/l ...

  4. shell 终端常用插件

    参考链接: http://get.ftqq.com/992.get 1.zsh 2.autojump 3.apt-get install lamp-server^ 4.tldr 5.tree (显示目 ...

  5. F - 回转寿司 (权值线段树)

    题目链接:https://cn.vjudge.net/contest/281960#problem/F 题目大意:中文题目 具体思路:权值线段树,我们每次寻找的是满足 (i<j)   L< ...

  6. python3字符串与文本处理

    每个程序都回涉及到文本处理,如拆分字符串.搜索.替换.词法分析等.许多任务都可以通过内建的字符串方法来轻松解决,但更复杂的操作就需要正则表达式来解决. 1.针对任意多的分隔符拆分字符串 In [1]: ...

  7. Python 3.x 格式化输出字符串 % & format 笔记

    Python 3.x 格式化输出字符串 % & format 笔记 python格式化字符串有%和{}两种 字符串格式控制符. 字符串输入数据格式类型(%格式操作符号) %%百分号标记 %c字 ...

  8. Django 利用 Pagination 简单分页

    Django自身提供了一些类来实现管理分页,数据被分在不同的页面中,并带有“上一页/下一页”标签.这个类叫做Pagination,其定义位于 django/core/paginator.py 中. 一 ...

  9. centos6.5 nfs实时共享

    一.什么时NFS NFS(Network File System)——网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,NF ...

  10. MVC自定义视图引擎地址

    先看结构 1.RouteConfig 文件(注意顺序) public static void RegisterRoutes(RouteCollection routes) { routes.Ignor ...