网站开发实习生,wordpress迁移后台打不开,中小企业网站建设与管理课后答案,太湖县住房与建设局网站题意#xff1a;给定4个n元素集合#xff0c;要求从每个集合中选择一个数#xff0c;使得ABcd0#xff0c;问存在多少种方法。 思路#xff1a;枚举hash判断。直接枚举4次方的算法会超#xff0c;那么只需要枚举ab#xff0c;然后在cd的和中查找等于-#xff08;ab给定4个n元素集合要求从每个集合中选择一个数使得ABcd0问存在多少种方法。 思路枚举hash判断。直接枚举4次方的算法会超那么只需要枚举ab然后在cd的和中查找等于-ab的值用mp或hashn2logn的算法。 Code #include bits/stdc.h
using namespace std;const int N4005;
int a[N],b[N],c[N],d[N];
struct Hash_map
{static const int m0x7fffff;int p[m1],q[m1];void cls(){for (int i0;im;i) q[i]0;}int operator[] (int k){int i;for (ikm;q[i]p[i]!k;i(i1)%m);p[i]k;return q[i];}
}has;
int main()
{int T,n;scanf(%d,T);while (T--){scanf(%d,n);for (int i1;in;i) scanf(%d %d %d %d,a[i],b[i],c[i],d[i]);int ans0;has.cls();for (int i1;in;i)for (int j1;jn;j)has[a[i]b[j]];for (int i1;in;i)for (int j1;jn;j)anshas[-(c[i]d[j])];printf(%d\n,ans);if (T) puts();}
}