A-codeforces558A
来源:互联网 发布:免费速读训练软件 编辑:程序博客网 时间:2024/05/19 19:14
题目链接:Codeforces558A
水题,第一次运行超时,用结构体快排。
不知道为什么不能一起算,要正负分开算,不然超时。
#define _CRT_SECURE_NO_DEPRECATE#include<stdio.h>#include<algorithm>#include<cstring>using namespace std;struct node{int x, a;}nor[105], nol[105];bool cmpr(const node &a, const node &b){return a.x < b.x;}bool cmpl(const node &a, const node &b){return a.x > b.x;}int main(){int n;while (scanf("%d", &n) != EOF){int ans = 0;int aa, b;int r = 0, l = 0;for (int i = 0; i < n; i++){scanf("%d %d", &aa, &b);if (aa > 0){nor[r].x = aa;nor[r].a = b;r++;}else{nol[l].x = aa;nol[l].a = b;l++;}}sort(nor, nor + r, cmpr);sort(nol, nol + l, cmpl);if (l == 0)ans = nor[0].a;else if (r == 0)ans = nol[0].a;else {int pl = 0, pr = 0;if (l > r){while (1){ans += nol[pl++].a;if (pr == r)break;ans += nor[pr++].a;if (pl == l)break;}}else{while (1){ans += nor[pr++].a;if (pl == l)break;ans += nol[pl++].a;if (pr == r)break;}}}printf("%d\n", ans);}return 0;}
0 0
- A-codeforces558A
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- A
- A*
- a
- A
- xcode终于找到如何对单个文件进行编译了
- 设计模式(5)-策略模式Strategy
- 编程图记(1): 引言
- spring applicationContext.xml的配置文件详解
- jQuery插件之TreeMultiselect 多用于权限配置
- A-codeforces558A
- Hashtable、HashMap、TreeMap
- 第3周项目4 顺序表应用(1)
- 4、深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- Eclipse自动生成作者、日期注释等功能设置
- [C++]内存分配的概念
- JSTL中的核心标签库(EL)
- Edius简易教程
- 最优化方法的Matlab实现