cf645c Money Transfers(贪心)

原创 2016年08月29日 19:14:16

想了很久,隔了一段时间,又想了很久,还是不会,看别人的代码,简直吓哭了。。。。。。

妙,

题意相当于:
给定一个区间[1,n],区间首尾相连,最多把它分成几块,使得每一块的和都是0.(假设答案是p,那么n-p就是这道题的答案)
所以维护一个前缀和,然后前缀和出现的最多次数就是答案,
突然觉得好蠢。。。。。。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <stack>
#include <vector>
#include <string.h>
#include <queue>
#define msc(X) memset(X,-1,sizeof(X))
#define ms(X) memset(X,0,sizeof(X))
typedef long long LL;
using namespace std;
const int MAXN=1e5+5;
int bank[MAXN];
int main(int argc, char const *argv[])
{
    int n,res=0;
    LL sum=0ll;
    map<LL,int> mmp;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",bank+i);
        sum+=bank[i];
        if(++mmp[sum]>res)
            res=mmp[sum];
    }
    printf("%d\n", n-res);
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

codeforces C. Money Transfers 贪心

C. Money Transfers time limit per test 1 second memory limit per test 256 megabytes input stan...

Codeforces Round #353 (Div. 2) C. Money Transfers 环、贪心、前缀和推广、好题

首先最多是ans = n-1次,这个时候只有sum总是0; 否则, 只有 有一个小区间是 0, 则ans就少1次; 所以要找到,尽可能多的sum == 0 的区间。 当时一直不知道,环该怎么处理, 结...

【打CF,学算法——三星级】CodeForces 645C Enduring Exodus (二分+贪心)

【CF简介】 提交链接:CF 645C 题面: C. Enduring Exodus time limit per test 2 seconds memor...

Codeforces Round #353 (Div. 2) C. Money Transfers

There are n banks in the city where Vasya lives, they are located in a circle, such that any two ban...

Codeforces Round #353 (Div. 2) C.Money Transfers

C. Money Transfers time limit per test 1 second memory limit per test 256 megabytes input stan...

Codeforces Round #353 (Div. 2) C. Money Transfers (map)

C. Money Transfers time limit per test 1 second memory limit per test 256 megabytes input stan...

Codeforces Round #353 (Div. 2) C. Money Transfers(数学题)

K - Money Transfers Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u...

codeforces 675C Money Transfers

There are n banks in the city where Vasya lives, they are located in a circle, such that any two ban...

cf645C. Enduring Exodus

C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces #353 div.2 Infinite Sequence&Restoring Painting&Money Transfers前三题题解

题目链接: A :http://codeforces.com/problemset/problem/675/A B :http://codeforces.com/problemset/proble...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:cf645c Money Transfers(贪心)
举报原因:
原因补充:

(最多只允许输入30个字)