Codeforces Round #353 (Div. 2) C 思维
来源:互联网 发布:java编写杨辉三角 编辑:程序博客网 时间:2024/05/17 07:12
Problem:
给你一个数列,本身是一个环且和为0,每次可以执行一个操作就是相邻的成员之间传递值,
问让该环所有成员的值都变为0,需要执行最少多少次操作?
Analyse:
- 可以转化为求环中最多和为0的块的个数.
- 然后因为没一个块的和都为0,所以在两个相邻的和为0的块之间该数列的前缀和是相同的,我们要求最多的块数,
只需要求最大的相同前缀和的频率即可
Get:
比赛的时候已经推出了第一步,不错,应该多思考,多发些性质,说不定就找到关键性质了.
/**********************jibancanyang************************** *Author* :jibancanyang *Created Time* : 二 5/17 23:44:56 2016**Code**:***********************1599664856@qq.com**********************/#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef pair<int, int> pii;typedef long long ll;typedef unsigned long long ull;vector<int> vi;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;#define pri(a) printf("%d\n",(a));#define xx first#define yy second#define sa(n) scanf("%d", &(n))#define sal(n) scanf("%lld", &(n))#define sai(n) scanf("%I64d", &(n))#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++) const int mod = int(1e9) + 7, INF = 0x3f3f3f3f;const int maxn = 1e5 + 13;int main(void){#ifdef LOCAL //freopen("/Users/zhaoyang/in.txt", "r", stdin); //freopen("/Users/zhaoyang/out.txt", "w", stdout);#endif map<ll, ll> mp; int n; cin >> n; ll mins = 0, sum = 0, x; for (int i = 0; i < n; i++) { cin >> x; mp[sum += x]++; mins = max(mins, mp[sum]); } cout << n - mins << endl; return 0;}
0 0
- Codeforces Round #353 (Div. 2) C 思维
- Codeforces Round #261 (Div. 2)C题(思维题)
- Codeforces Beta Round #32 (Div. 2) C (math+思维)
- Codeforces Round #246 (Div. 2)(C)数学,思维
- Codeforces Round #345 (Div. 2)(C)排列组合,思维
- Codeforces Round #273 (Div. 2)(C)贪心,思维
- Codeforces Round #202 (Div. 2)C. Mafia(思维)
- Codeforces Round #381 (Div. 2)C(构造,思维)
- Codeforces Round #386(Div. 2)C. Tram【思维】
- Codeforces Round #386 (Div. 2)C. Tram(模拟+思维)
- Codeforces Round #392(Div. 2) C Unfair Poll【思维+暴力】
- Codeforces Round #398(Div. 2)C. Garland【Dfs+思维】
- Codeforces Round #401(Div. 2)C. Alyona and Spreadsheet【思维】
- Codeforces Round #411(Div. 2)C. Find Amir【思维】
- Codeforces Round #418 (Div. 2) C 预处理/思维题
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes 思维
- Codeforces Round #109 (Div. 2)-C. Hometask-思维
- Leetcode 74. Search a 2D Matrix 2D矩阵查找 解题报告
- web.xml 中的过滤器(拦截器)Filter与监听器Listener的作用和区别?
- POJ 1946 DP
- Android Fragment应用及原理
- Github学习之EasyTabs打造绚丽TabLayout+ViewPager滑动动画集合库
- Codeforces Round #353 (Div. 2) C 思维
- 引导页圆点的滑动两种实现方式
- c3p0连接数据库失败No suitable driver
- 计科二班 安为 150809113 作业
- Node.js 回调函数
- 《UNIX环境高级编程》源码配置——apue.3e 安装
- hive-行转列和列转行
- 14_XML DOM 获取节点值
- 数据结构 - 二叉树的构建 (分冶)