POJ 2785
Time Limit: 15000MS | Memory Limit: 228000K | |
Total Submissions: 14475 | Accepted: 4138 | |
Case Time Limit: 5000MS |
Description
Input
Output
Sample Input
6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
Sample Output
5
Hint
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX = ; typedef long long ll; int N;
int a[][MAX];
int cd[MAX * MAX]; void solve() {
ll res = ; for(int i = ; i <= N; ++i) {
for(int j = ; j <= N; ++j) {
cd[(i - ) * N + j] = a[][i] + a[][j];
}
}
sort(cd + ,cd + N * N + ); for(int i = ; i <= N; ++i) {
for(int j = ; j <= N; ++j) {
int x = -(a[][i] + a[][j]);
res += upper_bound(cd + ,cd + N * N + ,x) -
lower_bound(cd + ,cd + N * N + ,x); }
} printf("%I64d\n",res); } int main()
{
// freopen("sw.in","r",stdin);
scanf("%d",&N);
for(int i = ; i <= N; ++i) {
for(int j = ; j <= ; ++j) {
scanf("%d",&a[j][i]);
}
} solve(); return ;
}
POJ 2785的更多相关文章
- POJ 2785 HASH
题目链接:http://poj.org/problem?id=2785 题意:给定n行数字,每行4个数分别是a,b,c,d,现在要求能有多少个(a,b,c,d)组合并且和为0 思路:n^2统计所有(a ...
- [POJ] 2785 4 Values whose Sum is 0(双向搜索)
题目地址:http://poj.org/problem?id=2785 #include<cstdio> #include<iostream> #include<stri ...
- poj 2785 让和为0 暴力&二分
题目链接:http://poj.org/problem?id=2785 大意是输入一个n行四列的矩阵,每一列取一个数,就是四个数,求有多少种着四个数相加和为0的情况 首先脑海里想到的第一思维必然是一个 ...
- POJ 2785 4 Values whose Sum is 0(哈希表)
[题目链接] http://poj.org/problem?id=2785 [题目大意] 给出四个数组,从每个数组中选出一个数,使得四个数相加为0,求方案数 [题解] 将a+b存入哈希表,反查-c-d ...
- POJ 2785 4 Values whose Sum is 0 Hash!
http://poj.org/problem?id=2785 题目大意: 给你四个数组a,b,c,d求满足a+b+c+d=0的个数 其中a,b,c,d可能高达2^28 思路: 嗯,没错,和上次的 HD ...
- poj 2785(折半枚举+二分搜索)
传送门:Problem 2785 题意: 给定 n 行数,每行都有 4 个数A,B,C,D. 要从每列中各抽取出一个数,问使四个数的和为0的所有方案数. 相同数字不同位置当作不同数字对待. 题解: 如 ...
- POJ 2785 4 Values whose Sum is 0(想法题)
传送门 4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 20334 A ...
- Divide and conquer:4 Values whose Sum is 0(POJ 2785)
找四个数的和为0 题目大意:给定四个集合,要你每个集合选4个数字,组成和为0 这题是3977的简单版,只要和是0就可以了 #include <iostream> #include < ...
- POJ 2785 4 Values whose Sum is 0
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 13069 Accep ...
随机推荐
- 《高性能javascript》读书笔记
1.每个<script>加载时都会阻塞其他文件(图片.音乐等)的同时加载,同时浏览器会在js代码执行时停止渲染Dom.所以为了减少界面加载的卡顿和空白发生,应尽力将js代码或者文件放在&l ...
- Python input()
在Python语言中,我们经常需要与用户实现交互,下面是一个小实例 # -*- coding:UTF-8 -*- #获取输入参数,并将输入的值存储到txt文件中 String1 = input(&qu ...
- 通过DB_LINK按照分区表抽取数据
DB:11.2.0.3.0OS:oracle-linux 5.7 建表语句:create table YOON.YOON_HIS( c_id NUMBER not null ...
- 编写可维护的JavaScript之简易模版
/* * 正则替换%s * @para arg1(text) 需要替换的模版 * @para arg2 替换第一处%s * @para arg3 替换第二处%s * 返回替换后的字符串 */ var ...
- 3.Knockout.Js(属性绑定)
前言 让visible绑定到DOM元素上,使得该元素的hidden或visible取决于绑定的值. 简单的绑定 首先还是先定义一个ViewModel var AppViewModel = { shou ...
- 可综合风格的VerilogHDL模块实例
1.赋值语句:assign{cout,sum}=a+b+cin; 2.利用电平敏感的always块设计组合逻辑电路 3.always块中如果含有局部变量,就必须在begin后加模块名,是必须加,同样的 ...
- [原]项目进阶 之 集群环境搭建(二)MySQL集群
上次的博文中我们介绍了一下集群的相关概念,今天的博文我们介绍一下MySQL集群的相关内容. 1.MySQL集群简介 MySQL群集技术在分布式系统中为MySQL数据提供了冗余特性,增强了安全性,使得单 ...
- NSNumber、NSValue、NSDate、NSObject
注:OC中数组和字典只能存储OC对象不能存放基本数据类型. NSNumber NSNumber可以用来把一个基本数据类型包装成一个NSNumber类型的对象. NSNumber *number = [ ...
- 团队作业php
<?php$kouwei=$_GET["select"];$daxiao=$_GET["RadioGroup1"];$peiliao=$_GET[&quo ...
- 阿里云服务器mysql修改编码问题
最近在学习struts+spring+hibernate,强烈推荐新手一本书:陈天河<轻量级web应用开发>,这本书是我见过的国内最好的书,初学者可以买本读读. 不说这个了,来说说我的问题 ...