【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 ...
随机推荐
- 【转】Eclipse插件收藏列表
使用了多年了Eclipse每个人都有自己的插件私藏列表,本系列文章会记录Eclipse市场推荐的个人私藏插件列表,希望对大家有帮助. 这一期的主人公是Zous Pantalons. viPlugin ...
- Java 第一次课堂测验
周一下午进行了开学来java第一次课堂测验,在课堂上我只完成了其中一部分,现代码修改如下: 先定义 ScoreInformation 类记录学生信息: /** * 信1805-1 * 胡一鸣 * 20 ...
- 基于Netty和SpringBoot实现一个轻量级RPC框架-Server篇
前提 前置文章: Github Page:<基于Netty和SpringBoot实现一个轻量级RPC框架-协议篇> Coding Page:<基于Netty和SpringBoot实现 ...
- Scala与Mongodb实践3-----运算环境的搭建
目的:使的在IDEA中编辑代码,令代码实现mongodb运算,且转换较为便捷 由实验2可知,运算环境的搭建亦需要对数据进行存储和计算,故需要实现类型转换,所以在实验2的基础上搭建环境. 由菜鸟教程可得 ...
- Spring Boot2 系列教程 (十) | 实现声明式事务
前言 如题,今天介绍 SpringBoot 的 声明式事务. Spring 的事务机制 所有的数据访问技术都有事务处理机制,这些技术提供了 API 用于开启事务.提交事务来完成数据操作,或者在发生错误 ...
- play framework 相关
1.下载 官网下载解压,安装有jkd即可使用 2.helloworld $ activator new my-first-app play-java https://www.playframework ...
- [3.0] 一个人开发一个App,小程序从0到1,删减添加
在这个黄道吉日,咱们将要干一件,惊天地泣鬼神,妇孺皆知的大事,那就是删掉微信开发工具自动生成的源代码. 删掉pages下的index.logs目录,啥都不留: 删掉utils下的util.js,只流空 ...
- Java中整数值的4中表示方式u
Java中整数值有4中表示方式:十进制.二进制.八进制和十六进制,其中二进制的整数以0b或0B开头:八进制的整数以0开头: 十六进制的整数以0x或0X开头,其中10-15分别以a-f(此处的a-f不区 ...
- 玩转Django2.0---Django笔记建站基础十(一)(常用的Web应用程序)
第十章 常用的Web应用程序 Django为开发者提供了常见的Web应用程序,如会话控制.高速缓存.CSRF防护.消息提示和分页功能.内置的Web应用程序大大优化了网站性能,并且完善了安全防护机制,而 ...
- 如何取消chrome的自动翻译
设置中搜索“翻译” 然后关掉“询问是否翻译非您所用语言的网页”的选项即可 需要翻译的时候在目标网页右键“翻译成中文”即可 用github的时候烦的要死,翻译的贼不准.