UVa 1152 4 Values whose Sum is 0——二分
灵活使用STL
#include #include #include #include using namespace std;const int maxn = 4000 + 10;int a[maxn], b[maxn], c[maxn], d[maxn], x[maxn*maxn];int main(){ int T, n; cin >> T; while (T--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { x[cnt++] = a[i] + b[j]; } } sort(x, x + cnt); int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans += upper_bound(x, x + cnt, -c[i]-d[j]) - lower_bound(x, x + cnt, -c[i]-d[j]); } } printf("%d\n", ans); if (T) printf("\n"); } return 0;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~