标签:const tor first vector cos main int using std
将前两组求和n^2sort,后两个组枚举二分(upper-lower)每个数字的相反数,求和
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<utility>
#include<queue>
#include<vector>
#include<cctype>
using namespace std;
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define forb(i,a,b) for(int i=a;i>=b;i--)
#define fir first
#define sec second
#define ABS(a) ((a)>0?(a):-(a))
#define PI acos(-1,0)
typedef long long ll;
typedef long double ld;
const int MAXN=4005;
int nums[MAXN*4];
int sorn[MAXN*MAXN];
int tot;
int main(){
int n;
cin>>n;
fore(i,1,4*n){
scanf("%d",&nums[i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
sorn[++tot]=nums[4*i-3]+nums[4*j-2];
}
}
sort(sorn+1,sorn+tot+1);
//cout<<tot;
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ans+=upper_bound(sorn+1,sorn+tot+1,-(nums[i*4-1]+nums[j*4]))-lower_bound(sorn+1,sorn+tot+1,-(nums[i*4-1]+nums[j*4]));
}
}
printf("%lld",ans);
return 0;
}
【SWERC2005】4 values whose sum is 0
标签:const tor first vector cos main int using std
原文地址:https://www.cnblogs.com/rign/p/10376694.html