【Codeforces #312 div2 A】Lala Land and Apple Trees
【Codeforces #312 div2 A】Lala Land and Apple Trees
首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原点开始走,方向自选(<- or ->),在过程中,若遇到一个权值>0的点,则将此权值计入答案,并归零。当次、此方向上的所有点均为0后,输出此时的答案。
然后,进行分析:
我们很容易想到这是一个贪心,我们将正的和负的分别存入两个数组,最初的方向为: \(zhengsum > fusum ? zheng : fu\)即正负两边那边权值 > 0的点多就先往哪个方向走,然后,就成模拟题了……
Code:
#include<bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
const int M = 100001;
int n,dir,l[M],r[M],lsum,rsum,ans;
int markjia[M] = {0},markjian[M] = {0};
int check()
{
if(dir == -1)
{
for(int i=1;i<=100000;i++)
{
if(markjian[i])return i;
}
return 0;
}else{
for(int i=1;i<=100000;i++)
{
if(markjia[i])return i;
}
return 0;
}
}
int main()
{
scanf("%d",&n);
int x,a;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&x,&a);
if(x < 0){x *= -1;l[x] = a,markjian[x] = 1,lsum++;}
else r[x] = a,markjia[x] = 1,rsum++;
}
if(lsum >= rsum)dir = -1;
else dir = 1;
for(int i=1;i<=n;i++)
{
if(check() == 0)break;
if(dir == -1)
{
ans += l[check()];
markjian[check()] = 0;
dir = 1;
}else{
ans += r[check()];
markjia[check()] = 0;
dir = -1;
}
}
cout << ans;
return 0;
}
\(End.\)
【Codeforces #312 div2 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 暴力
A. Lala Land and Apple Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/cont ...
- 【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) 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 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 ...
- 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 ...
- 【一天一道LeetCode】#96. Unique Binary Search Trees
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...
- 【SRM 717 DIV2 C】DerangementsDiv2
Problem Statement You are given two ints: n and m. Let D be the number of permutations of the set {1 ...
- 【SRM 717 div2 B】LexmaxReplace
Problem Statement Alice has a string s of lowercase letters. The string is written on a wall. Alice ...
随机推荐
- 使用Jenkins进行前端UVE项目部署
操作步骤 1.用 Jenkins 管理员账号下载 NodeJS Plugin 2.系统管理 ---> 全局工具配置 ---> NodeJS ---> 安装 ---> 自动安装 ...
- python可变对象
- 每个对象中都保存了三个数据: id(标识) type(类型) value(值) - 列表就是一个可变对象 a = [1,2,3] - a[0] = 10 (改对象) - 这个操作是在通过变量去修改 ...
- 6441. 【GDOI2020模拟01.17】小 ω 维护序列
Description Input Output 输出到标准输出流中. 若干行,对于每个操作 1 和操作 5,输出一个数表示答案. Sample Input Sample Input1 5 8 1 2 ...
- 如何实施DevOps
对于长期在孤立的架构下工作的组织来说,转移到协作式DevOps系统似乎是难以成功的.为了进一步提高效率,必须改变观念,并进行团队文化改变.例如:许多人认为只有自动化工具才能解决DevOps,其实这是不 ...
- DP-01背包 (题)
nyoj 325 http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms | 内存限制:65535 KB ...
- day6 相对定位:position:relative
相对定位:position:relative 特点:a.相对于自己原来位置的定位,以自己的左上角为基准. b.相对定位原来的位置仍然算位置,不会出现浮动现象. 以下为初始位置:(可以看出设置margi ...
- kaggle预测房价的代码步骤
# -*- coding: utf-8 -*- """ Created on Sat Oct 20 14:03:05 2018 @author: 12958 " ...
- java面试题-spring篇
这次是关于spring的面试题,和上次一样依旧挑了几个具有代表性的. 一. 谈谈你对 Spring 的理解 Spring 是一个开源框架,为简化企业级应用开发而生.Spring 可以是使简单的 Ja ...
- (分块暴力)Time to Raid Cowavans CodeForces - 103D
题意 给你一段长度为n(1 ≤ n ≤ 3·1e5)的序列,m (1 ≤ p ≤ 3·1e5)个询问,每次询问a,a+b,a+2b+...<=n的和 思路 一开始一直想也想不到怎么分,去维护哪些 ...
- 手把手写一个基于Spring Boot框架下的参数校验组件(JSR-303)
前言 之前参与的新开放平台研发的过程中,由于不同的接口需要对不同的入参进行校验,这就涉及到通用参数的校验封装,如果不进行封装,那么写出来的校验代码将会风格不统一.校验工具类不一致.维护风险高等其它因素 ...