poj 2231 Moo Volume
来源:互联网 发布:叙永网络歌手大赛歌名 编辑:程序博客网 时间:2024/06/01 09:50
n*n的做法会超时,10^8居然会超时时间大于1s,是poj编译器的问题?
需要减少操作的步数。简单的模拟
#include<iostream>#include<string.h>#include<math.h>#include<fstream>#include<algorithm>#include<stdio.h>#include<queue>#include<vector> #define MAXSIZE 100using namespace std;#define max(a, b) ((a) > (b) ? (a) : (b))#define min(a, b) ((a) < (b) ? (a) : (b)) typedef long long int ll;int N = 0;ll dat[10010];ll ans = 0;int main(){ //freopen("data_2231.txt","r",stdin); while(scanf("%d", &N) != EOF) { ans = 0; for (int i = 0; i < N; i++) { scanf("%lld", &dat[i]); } sort (dat, dat + N); for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { ans += (long)abs ((long)(dat[j] - dat[i])); } } printf("%lld\n", 2 * ans); } return 0;}
0 0
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume
- POJ -- 2231 Moo Volume
- POJ 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume
- poj 2231Moo Volume
- POJ 2231 Moo Volume
- POJ 2231-Moo Volume
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume (暴力)
- poj 杂题 - 2231 Moo Volume
- POJ 2231:Moo Volume【细心】
- POJ 2231 Moo Volume【求和】
- POJ 2231 Moo Volume 笔记
- Hibernate检索方式
- LeetCode---(8)String to Integer (atoi)
- 为 JIRA 6.x 安装中文语言包
- 最小生成树之Kruskal算法
- 2015年7月10日 UITableView 2
- poj 2231 Moo Volume
- 含有过滤功能的android流式布局
- 新增button控件为其添加onClick事件及Text
- 7.10垫底总结
- View Controller、Delegate、TextField——《iOS编程》第六、七章学习笔记
- Jsp 自定义tag标签
- CodeForces 321 A - Ciel and Robot
- IOS 整体框架类图值得收藏
- 学习到的一下技巧