【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 ...
随机推荐
- Sample Code之Web scene-slides
这是我的第一篇随笔,在开始正文前说几句. 这个系列会记录我学习Arcgis js API 4.10的全过程,希望能对自己也对其他有需要的人有帮助.很多时候上网看一些大神的帖子会感到一头雾水,一是自己水 ...
- django框架中的静态文件引入
首先在项目文件中新建文件夹static 之后在settings.py中配置路径 如下图所示: 下一步在你刚创建的static文件夹中添加app的文件夹名称,例如:teacher,如下图: 之后在tea ...
- C++乱码从入门到放弃
前几天在一篇文章中看见一段用大括号包裹的C++代码(大概长下面这样) { //一些必要的预处理代码...吧啦吧啦吧啦... int main() { //代码主体...吧啦吧啦吧啦... } } 当时 ...
- stars-one原创工具——m3u8视频下载合并器(kotlin)
一款可以下载m3u8.解密ts文件及合并ts文件的视频下载工具 蓝奏云下载地址 github地址 软件对你有帮助的话,不妨赞赏一波!感谢! 程序说明 采用多线程下载,可有效的提高下载速度 内置解密程序 ...
- P4513 小白逛公园 动态维护最大子段和
题目链接:https://www.luogu.org/problem/P4513 #include<iostream> #include<cstdio> #include< ...
- Android栈溢出漏洞利用练习
在Github上看到一个Linux系统上的栈溢出漏洞利用练习项目: easy-linux-pwn.在原项目基础上,我稍微做了一些改动,将这个项目移植到了Android 9.0系统上: easy-and ...
- Java单体应用 - 开发工具 - 02.Maven
原文地址:http://www.work100.net/training/monolithic-tools-maven.html 更多教程:光束云 - 免费课程 Maven 序号 文内章节 视频 1 ...
- 从0开发3D引擎(九):实现最小的3D程序-“绘制三角形”
目录 上一篇博文 运行测试截图 需求分析 目标 特性 头脑风暴 确定需求 总体设计 具体实现 新建Engine3D项目 实现上下文 实现_init 实现"获得WebGL上下文" 实 ...
- WeihanLi.Npoi 根据模板导出Excel
WeihanLi.Npoi 根据模板导出Excel Intro 原来的导出方式比较适用于比较简单的导出,每一条数据在一行,数据列虽然自定义程度比较高,如果要一条数据对应多行就做不到了,于是就想支持根据 ...
- 解决 C# GetPixel 和 SetPixel 效率问题(转)
在对Bitmap图片操作的时候,有时需要用到获取或设置像素颜色方法:GetPixel 和 SetPixel, 如果直接对这两个方法进行操作的话速度很慢,这里我们可以通过把数据提取出来操作,然后操作完在 ...