CodeForces 131B Opposites Attract
2016-07-19 15:31
351 查看
两重for循环妥妥超时
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int maxn=1250;
int a[15],b[15],z=0;
int main() {
int n,t;
scanf ("%d",&n);
for (int i=0; i<n; ++i) {
scanf ("%d",&t);
if (t>0) {++a[t];}
else if (t<0) {++b[-t];}
else { ++z; }//统计0的个数
}//two for loop will TLE
uLL cnt=0;
for (int i=0; i<11; ++i) {cnt+= (uLL) a[i]*b[i];}//匹配正负
cnt+= (uLL) z* (z-1) /2;//0 and other 0
cout<<cnt<<endl;
return 0;
}
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int maxn=1250;
int a[15],b[15],z=0;
int main() {
int n,t;
scanf ("%d",&n);
for (int i=0; i<n; ++i) {
scanf ("%d",&t);
if (t>0) {++a[t];}
else if (t<0) {++b[-t];}
else { ++z; }//统计0的个数
}//two for loop will TLE
uLL cnt=0;
for (int i=0; i<11; ++i) {cnt+= (uLL) a[i]*b[i];}//匹配正负
cnt+= (uLL) z* (z-1) /2;//0 and other 0
cout<<cnt<<endl;
return 0;
}
相关文章推荐
- 【OPENCV笔记】一些总结
- shell中&&和||的使用方法
- thinkphp pathinfo nginx 无法加载模块:Index
- Linux修改ssh远程端口
- 安装centos7.0时电脑进入黑屏的解决方法
- Linux里设置环境变量的方法(export PATH)
- linux shell 和 vim快捷键
- org.apache.hadoop.security.AccessControlException 解决办法
- [备注] Linux系统结构 详解
- SSH Secure Shell Client乱码问题
- 贝叶斯分类数据集的网站
- linux内核input子系统解析
- [备注] 关于openssl的系统介绍
- leetcode 185. Department Top Three Salaries
- 用powershell+excel行列转置三步走
- OpenGL笔记2.1 角的顶点
- UNIX/Linux系统管理技术手册(2)----bash脚本编程
- Linux收藏
- centos yum 安装
- 高效学习OpenGL之执行多个显示列表glListBase(),glCallLists()