BZOJ3544 [ONTAK2010]Creative Accounting
看不懂题,就不能写的稍微像人话点吗我去。。。
题目就是要找一段区间使得Σai mod m的值最大。
于是嘛。。。前缀和一下再贪心就好了。
先求出前i个数的前缀和s,然后用s更新解。
还有可能就是前面的某个前缀和s1刚好在mod m意义下大于s且是最小的一个,那么这一段的和就是m + s - s1,再用它来更新解。
/**************************************************************
Problem: 3544
User: rausen
Language: C++
Result: Accepted
Time:2056 ms
Memory:7012 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <set> using namespace std;
typedef long long ll;
int n;
ll mod, s, a, ans, p;
set <ll> S; inline ll read(){
ll x = , sgn = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-') sgn = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = (ll) x * + ch - '';
ch = getchar();
}
return sgn * x;
} int main(){
scanf("%d", &n); mod = read();
for (int i = ; i <= n; ++i){
a = read();
if (a < ) a += (abs(a / mod) + ) * mod;
s += a, s %= mod;
ans = max(ans, s);
if (S.upper_bound(s) != S.end()){
p = *(S.upper_bound(s));
ans = max(ans, (s + mod - p) % mod);
}
S.insert(s);
}
printf("%lld\n", ans);
return ;
}
(p.s. 无耻的我又用了set。。。)
BZOJ3544 [ONTAK2010]Creative Accounting的更多相关文章
- 【BZOJ3544】[ONTAK2010]Creative Accounting 前缀和+set
[BZOJ3544][ONTAK2010]Creative Accounting Description 给定一个长度为N的数组a和M,求一个区间[l,r],使得(\sum_{i=l}^{r}{a_i ...
- BZOJ 3544: [ONTAK2010]Creative Accounting( BST )
题意 : 一段序列 , 求一段子序列和取余 M 的最大值 其实是一道水题... 前缀和 , 然后就是找 ( sum( r ) - sum( l ) ) % M 的最大值 . 考虑一个 sum( r ) ...
- 【bzoj3544】[ONTAK2010]Creative Accounting 前缀和+STL-set
题目描述 给定一个长度为N的数组a和M,求一个区间[l,r],使得$(\sum\limits_{i=l}^{r}{a_i})\ mod\ M$的值最大,求出这个值,注意这里的mod是数学上的mod(即 ...
- BZOJ 3544: [ONTAK2010]Creative Accounting [set]
给定一个长度为N的数组a和M,求一个区间[l,r],使得$(\sum_{i=l}^{r}{a_i}) mod M$的值最大,求出这个值,注意这里的mod是数学上的mod 这道题真好,题面连LaTeX都 ...
- BZOJ 3544 [ONTAK2010]Creative Accounting(set)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3544 [题目大意] 找一段区间使得Σai mod m的值最大. [题解] 首先计算前缀 ...
- bzoj 3544 [ONTAK2010]Creative Accounting 贪心
Description 给定一个长度为N的数组a和M,求一个区间[l,r],使得(\sum_{i=l}^{r}{a_i}) mod M的值最大,求出这个值,注意这里的mod是数学上的mod Input ...
- noip知识点总结之--贪心
一.什么是贪心 贪心算法嘛... 就是在对某个问题求解时,总是做出在当前看来是最好的选择 In other wors,并不是从整体最优上加以考虑,而是在获得某种意义上的局部最优解 二.贪心算法的适用前 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
随机推荐
- 20145304 Exp8 Web基础
20145304 Exp8 Web基础 实验后回答问题 (1)什么是表单 表单用于搜集不同类型的用户输入,由三个基本组成部分表单标签.表单域.表单按钮.表单提交有两种方法,分别是get和post,使用 ...
- 20145335郝昊《网络对抗技术》Exp6 信息搜集技术
20145335郝昊<网络对抗技术>Exp6 信息搜集技术 实验内容 本次实验的目标是掌握信息搜集的最基础技能.具体有(1)各种搜索技巧的应用(2)DNS IP注册信息的查询 (3)基本的 ...
- 20165310 预备作业3 Linux安装及学习
预备作业3 Linux安装及学习 安装虚拟机 之前在win7系统下通过EasyBCD安装过Ubuntu虚拟机,这次阅读<基于VirtualBox虚拟机安装Ubuntu图文教程>又学习到了一 ...
- DSDS,双模,双卡,双待,单待,双通,单通,概念及相互关系?【转】
本文转载自:https://blog.csdn.net/dirk_it/article/details/7178058?utm_source=blogxgwz9 DSDS:双卡双待 DualSimDu ...
- C语言通过枚举网卡,API接口可查看man 7 netdevice--获取接口IP地址
/*代码来自StackOverflow: http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-c ...
- Tex: The top-level auxiliary file: *.aux I couldn't open style file IEEEtran.bst 解决方法
参考: Bibliography is not printed using Kile on Ubuntu Tex: The top-level auxiliary file: *.aux I coul ...
- LCA在线算法详解
LCA(最近公共祖先)的求法有多种,这里先介绍第一种:在线算法. 声明一下:下面的内容参考了http://www.cnblogs.com/scau20110726/archive/2013/05/26 ...
- java 从List中随机取出一个元素
java 从List中随机取出一个元素 List<Integer> list = new ArrayList<>(); Random random = new Random() ...
- jenkins 插件,下载地址
http://updates.jenkins-ci.org/download/plugins/ 通常我们需要下载的插件有如下几个:
- 团队项目用户验收评审——《WAP团队》
团队项目用户验收评审——<WAP团队> 1.验收准备的相关文档链接:https://github.com/LVowe999/xiangmubaogao.git ...