Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力
A. Lala Land and Apple Trees
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/558/problem/A
Description
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Sample Input
2
-1 5
1 5
Sample Output
10
HINT
题意
有一个人,一开始会往左边走或者往右边走,碰到苹果树就会拾起这棵苹果树的所有果子,然后再交换方向,重复这个过程
问你这个人最多能拿多少个果子
题解:
先左右按着坐标排一个序,很显然只有两种走法,挨个判一下谁最大就好了
代码
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std; struct node
{
int x,y;
};
node a[];
node b[];
bool cmp(node aa,node bb)
{
return aa.x<bb.x;
}
int main()
{
int n;
scanf("%d",&n);
int num1=,num2=;
for(int i=;i<n;i++)
{
int c,d;
cin>>c>>d;
if(c<)
a[num1].x=-c,a[num1++].y=d;
else
b[num2].x=c,b[num2++].y=d;
}
sort(a,a+num1,cmp);
sort(b,b+num2,cmp);
int num=min(num1,num2);
int ans=;
for(int i=;i<num;i++)
ans+=(a[i].y+b[i].y);
if(num1>num2)
ans+=a[num2].y;
else if(num2>num1)
ans+=b[num1].y;
cout<<ans<<endl; }
Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力的更多相关文章
- 【打CF,学算法——二星级】Codeforces Round #312 (Div. 2) A Lala Land and Apple Trees
[CF简单介绍] 提交链接:A. Lala Land and Apple Trees 题面: A. Lala Land and Apple Trees time limit per test 1 se ...
- Codeforces Round #312 (Div. 2) A.Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力
B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- Codeforces Round #312 (Div. 2)
好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...
- codeforces 558A A. Lala Land and Apple Trees(水题)
题目链接: A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes ...
- 【42.07%】【codeforces 558A】Lala Land and Apple Trees
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...
随机推荐
- Php 笔记3-----php与 asp的等价关系
对比asp.net 与 php的对比 ,有助于进一步理解 php. 1 输出. asp.net 输出 Response.Write(str); // 将string 写入到 服务器向浏 ...
- selenium python (十)浏览器多窗口处理
#!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip'#在测试过程中有时候会遇到出现多个浏览器窗口的情况,这时候我们可以通过窗口 ...
- LoadRunner error -27728
错误现象1:Action.c(16): Error -27728: Step download timeout (120 seconds) has expired whendownloading no ...
- 如何使用Fiddler调试线上JS代码
大家平时肯定都用过火狐的Firebug或者谷歌的调试工具来调试JS,但遗憾的是我们不能像编辑html,css那样来直接新增或者删除JS代码. 虽然可以通过调试工具的控制台来动态执行JS代码,但有时候却 ...
- 基于OSGI.Net的图形界面系统
在2013年的十月份有幸接触了osgi.net和iopenworks的创始人,了解和学习的插件式开发,开始了后台数据的处理生涯. 第一个有图形界面的系统——智能农业的环境监测系统,其实在这个系统中所有 ...
- 使用ncc分析代码
1 ncc是一个编译器, 用于输出程序的一些调用信息等, 可以查看函数调用关系, 支持函数指针, 查看数据结构和代码. 可以用来分析和理解代码. “" ... with ncc, in le ...
- 详解centos下vi的用法
vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的任何版本,vi编辑器是完全相 ...
- CDH4.1基于Quorum-based Journaling的NameNode HA
几个星期前, Cloudera发布了CDH 4.1最新的更新版本,这是第一个真正意义上的独立高可用性HDFS NameNode的hadoop版本,不依赖于特殊的硬件或外部软件.这篇文章从开发者的角度来 ...
- 开着奥迪做Uber司机是什么心态?
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Collection Operators
[Collection Operators] Collection operators are specialized key paths that are passed as the paramet ...