Codeforces 617B:Chocolate(思维)
题目链接http://codeforces.com/problemset/problem/617/B
题意
有一个数组,数组中的元素均为0或1 。要求将这个数组分成一些区间,每个区间中的1的个数均为1。问有多少种分法
思路
将数组中的0全部去掉,用一个数组记录原数组中的每个1的位置,相邻的两个1的位置差为两个1之间的0的个数,让这些0的个数一次相乘就行了。但是要注意原数组中全是0的情况,还要注意数据类型,会爆int
AC代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
int a[maxn];
int main(int argc, char const *argv[])
{
int n;
cin>>n;
int x;
int j=0;
for(int i=0;i<n;i++)
{
cin>>x;
if(x==1)
a[++j]+=i;
}
ll ans=1;
if(j==0)
cout<<"0"<<endl;
else
{
for(int i=1;i<j;i++)
{
ans=ans*(a[i+1]-a[i]);
}
cout<<ans<<endl;
}
return 0;
}
Codeforces 617B:Chocolate(思维)的更多相关文章
- codeforces 617B Chocolate
题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...
- CodeForces 604C 【思维水题】`
题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...
- Minimum Integer CodeForces - 1101A (思维+公式)
You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...
- Codeforces 1038D - Slime - [思维题][DP]
题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...
- AND Graph CodeForces - 987F(思维二进制dfs)
题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...
- CodeForces - 631C ——(思维题)
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
- Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)
Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...
- Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)
Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...
- Codeforces 490D Chocolate
D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- SPP Net(Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition)论文理解
论文地址:https://arxiv.org/pdf/1406.4729.pdf 论文翻译请移步:http://www.dengfanxin.cn/?p=403 一.背景: 传统的CNN要求输入图像尺 ...
- (转帖整理)Linux下的Autoconf和AutoMake(理论篇) 1
在搜索网上资料过程中,这是感觉最简洁有效的一篇文章,特进行转帖记录,并根据情况对部分内容进行了修改.原帖传送门:Linux下的Autoconf和AutoMake 1.工具安装在开始使用autoconf ...
- English trip -- VC(情景课)10 C I like to watch TV. 我爱看电视
Grammar focus 语法点: like to do you do they What does he like to do? does she Practice 练习 ...
- Codeword CodeForces - 666C (字符串计数)
链接 大意:求只含小写字母, 长度为n, 且可以与给定模板串匹配的字符串个数 (多组数据) 记模板串为P, 长为x, 总串为S. 设$f_i$为S为i时的匹配数, 考虑P最后一位的首次匹配位置. 若为 ...
- ajax post data 获取不到数据,注意contentType
$.ajax({ url:'/web/register/', type:"POST", data:{'user':'66'}, dataType:'json', 这个东西困惑我一天 ...
- How do you add?(递推)
题意:求将n分为k个数相加的种数. 如:n=20,k=2,则可分为: 0+20=20 1+19=20 2+18=20 ....... 20 +0=20 共21种方案. 解析:令f(n,m)表示将n分为 ...
- 遍历页面上主从表中从table中的内容
//如果在建VL的时候没有建访问器.从主表行拿到从表VO的行级不太好搞的 OAAdvancedTableBean innerTable = (OAAdvancedTableBean)webBean.f ...
- C语言按行读文件及字符串分割
#include<stdio.h> #include<iostream> using namespace std; int main() { char s[50]; char ...
- dubbo的ExtensionLoader
了解4个概念:接口,实现类,wrapper,adaptive. 扩展是接口实现类被wrap之后的对象,adaptive扩展是动态生成的类(例如Dubbo$Adaptive类). dubbo框架为接口指 ...
- 关于PermGen space内存溢出错误解决方法
1.参考: http://blog.csdn.net/fox009/article/details/5633007 http://hi.baidu.com/like_dark/blog/item/19 ...