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 ...
随机推荐
- jq 插件写法
1.一次声明一个函数 $.fn.函数名 = function([options]){} $.fn.red=function(options){ var defaults = { 'color': 'r ...
- 在线客服 分享 qq 一键加好友 一键入群
1.在线客服 <a href="tencent://message/?uin=qqnum&Site=&menu=yes">qq客服</a> ...
- HTTP请求GET/POST查看工具
当你有一个http的get请求需要知道结果,可以直接在浏览器上输入,然后等待查看结果. 那如果是一个post请求呢?推荐使用一个国外工具Send HTTP Tool. 传送门:http:/ ...
- 如何查看DNS?
查看dns服务ip: 命令: ipconfig/all 查看dns缓存: 命令:ipconfig/displaydns 强制更新缓存: 命令:ipconfig /flush ...
- Git工作区、暂存区和版本库
基本概念 我们先来理解下Git 工作区.暂存区和版本库概念 工作区:就是你在电脑里能看到的目录. 暂存区:英文叫stage, 或index.一般存放在 ".git目录下" 下的in ...
- JDBC 与 Bean Shell的使用(一)获取值,并且传递
1.在使用Jmeter进行接口测试的时候,会使用到JDBC,连接数据库,操作数据库其得到的数据后续操作需要使用,这里我们使用了BeanShell的概念来获取JDBC的返回值 如下说明了联合使用的2种方 ...
- Java 主要特性
Java 有下面的一些主要特性. 面向对象 在 Java 中,所有的都是对象.正式因为 Java 基于对象模型,所以 Java 更加容易进行扩展. Java语言提供类.接口和继承等面向对象的特性,为了 ...
- Hackintosh Power Management
Also, be aware that hibernation (suspend to disk or S4 sleep) is not supported on hackintosh. You sh ...
- ubuntu64位库
安装 12.04ubuntu32位库:sudo apt-get install ia32-libs
- SQL Server日志清空方法
1.清空日志:DUMP TRANSACTION databasename WITH NO_LOG 2.截断事务日志:BACKUP LOG databasename WITH ...