cf 558A Lala Land and Apple Trees

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

struct data
{
    int x;
    int a;
};
data l[1024],r[1024];
bool c1(data q,data p)
{
    return q.x<p.x;
}

bool c2(data q,data p)
{
    return q.x>p.x;
}

int main()
{
    int n,i,t,p,ans1,ans2,p1,p2;
    while(~scanf("%d\n",&n))
    {
        p1=p2=0;
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&t,&p);
            if(t>0)
            {
                r[p2].x=t;
                r[p2].a=p;
                p2++;
            }
            else
            {
                l[p1].x=t;
                l[p1].a=p;
                p1++;
            }

        }
        sort(l,l+p1,c2);
        sort(r,r+p2,c1);
        int u1[1024],u2[1024];
        memset(u1,0,sizeof(u1));
        memset(u2,0,sizeof(u2));
        for(ans1=0,i=0;;i++)
        {
            if(i%2==0)
            {
                if(i/2>=p1) break;
                ans1+=l[i/2].a;
            }
            else
            {
                if(i/2>=p2) break;
                ans1+=r[i/2].a;
            }
        }
        for(ans2=0,i=0;;i++)
        {
            if(i%2==1)
            {
                if(i/2>=p1) break;
                ans2+=l[i/2].a;
            }
            else
            {
                if(i/2>=p2) break;
                ans2+=r[i/2].a;
            }
        }
        printf("%d\n",max(ans1,ans2));
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-09-01 00:53:32

cf 558A Lala Land and Apple Trees的相关文章

Codeforces 558A Lala Land and Apple Trees(Sort快排)

A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is

CF 558A(Lala Land and Apple Trees-暴力)

A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is

Codeforces 558A Lala Land and Apple Trees 摘苹果

题意:n棵苹果树在x轴上排成一排,每棵苹果树有一个坐标值(均不为0)和苹果数量.现在某人从0开始任意选择一个方向走,每遇到一颗新的苹果树就摘下所有苹果,然后掉转方向直到遇到下一颗之前没遇到过的苹果树然后再摘下所有苹果,如此往复直到再也遇不到新的苹果树.问最多能摘下多少个苹果. 水题.以0为中心,对坐标排序后计算左右两边的苹果树个数.如果左边小于右边,就先从左边摘,反之则先从右边摘.最后看有多少个苹果树摘不到即可. #include <iostream> #include <cstdio&

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

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. 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

Codechef December Challenge 2014 Chef and Apple Trees 水题

Chef and Apple Trees Chef loves to prepare delicious dishes. This time, Chef has decided to prepare a special dish for you, and needs to gather several apples to do so. Chef has N apple trees in his home garden. Each tree has a certain (non-zero) num

Codeforces Round #312 (Div. 2) ABC题解

[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地.拉拉土地是一个非常美丽的国家,位于坐标线.拉拉土地是与著名的苹果树越来越随处可见. 拉拉土地恰好n苹果树.树数i位于位置xi和具有人工智能的苹果就可以了增长.阿姆鲁希望从苹果树收集苹果. AMR目前维持在X =0的位置.在开始的时候,他可以选择是否去左边或右边.他会在他的方向继续下去,直到他遇见一棵苹果树,他之前没有参观.他会采取所有的苹果,然后扭转他的方向,继续走这

Codeforces Round #312 (Div. 2)

A. Lala Land and Apple Trees 题目描述: 一条坐标轴,在坐标轴上散布了一些苹果树,每棵树都有位置和所结果实数目两个属性,Amr在坐标轴0点的位置,Amr在开始的时候可以选择向左或者右走,然后遇到果树才能改变方向,问最后最多能拿到多少个苹果? 解题思路: 开两个数组,分别代表坐标正半轴和负半轴,然后对每个数组排下一序,刚开始选择苹果树多的方向,然后累加就好. 1 #include <bits/stdc++.h> 2 using namespace std; 3 str

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri