题目链接http://codeforces.com/problemset/problem/617/B

题意

有一个数组,数组中的元素均为0或1 。要求将这个数组分成一些区间,每个区间中的1的个数均为1。问有多少种分法

思路

将数组中的0全部去掉,用一个数组记录原数组中的每个1的位置,相邻的两个1的位置差为两个1之间的0的个数,让这些0的个数一次相乘就行了。但是要注意原数组中全是0的情况,还要注意数据类型,会爆int

AC代码

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <limits.h>
  7. #include <map>
  8. #include <stack>
  9. #include <queue>
  10. #include <vector>
  11. #include <set>
  12. #include <string>
  13. #define ll long long
  14. #define ms(a) memset(a,0,sizeof(a))
  15. #define pi acos(-1.0)
  16. #define INF 0x3f3f3f3f
  17. const double E=exp(1);
  18. const int maxn=1e6+10;
  19. using namespace std;
  20. int a[maxn];
  21. int main(int argc, char const *argv[])
  22. {
  23. int n;
  24. cin>>n;
  25. int x;
  26. int j=0;
  27. for(int i=0;i<n;i++)
  28. {
  29. cin>>x;
  30. if(x==1)
  31. a[++j]+=i;
  32. }
  33. ll ans=1;
  34. if(j==0)
  35. cout<<"0"<<endl;
  36. else
  37. {
  38. for(int i=1;i<j;i++)
  39. {
  40. ans=ans*(a[i+1]-a[i]);
  41. }
  42. cout<<ans<<endl;
  43. }
  44. return 0;
  45. }

Codeforces 617B:Chocolate(思维)的更多相关文章

  1. codeforces 617B Chocolate

    题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...

  2. CodeForces 604C 【思维水题】`

    题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...

  3. Minimum Integer CodeForces - 1101A (思维+公式)

    You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...

  4. Codeforces 1038D - Slime - [思维题][DP]

    题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...

  5. AND Graph CodeForces - 987F(思维二进制dfs)

    题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...

  6. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  7. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  8. Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

    Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...

  9. Codeforces 490D Chocolate

    D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. jq 插件写法

    1.一次声明一个函数 $.fn.函数名 = function([options]){} $.fn.red=function(options){ var defaults = { 'color': 'r ...

  2. 在线客服 分享 qq 一键加好友 一键入群

    1.在线客服 <a href="tencent://message/?uin=qqnum&Site=&menu=yes">qq客服</a>  ...

  3. HTTP请求GET/POST查看工具

    当你有一个http的get请求需要知道结果,可以直接在浏览器上输入,然后等待查看结果.    那如果是一个post请求呢?推荐使用一个国外工具Send HTTP Tool.    传送门:http:/ ...

  4. 如何查看DNS?

    查看dns服务ip:    命令: ipconfig/all  查看dns缓存:    命令:ipconfig/displaydns     强制更新缓存:    命令:ipconfig /flush ...

  5. Git工作区、暂存区和版本库

    基本概念 我们先来理解下Git 工作区.暂存区和版本库概念 工作区:就是你在电脑里能看到的目录. 暂存区:英文叫stage, 或index.一般存放在 ".git目录下" 下的in ...

  6. JDBC 与 Bean Shell的使用(一)获取值,并且传递

    1.在使用Jmeter进行接口测试的时候,会使用到JDBC,连接数据库,操作数据库其得到的数据后续操作需要使用,这里我们使用了BeanShell的概念来获取JDBC的返回值 如下说明了联合使用的2种方 ...

  7. Java 主要特性

    Java 有下面的一些主要特性. 面向对象 在 Java 中,所有的都是对象.正式因为 Java 基于对象模型,所以 Java 更加容易进行扩展. Java语言提供类.接口和继承等面向对象的特性,为了 ...

  8. Hackintosh Power Management

    Also, be aware that hibernation (suspend to disk or S4 sleep) is not supported on hackintosh. You sh ...

  9. ubuntu64位库

    安装 12.04ubuntu32位库:sudo apt-get install ia32-libs

  10. SQL Server日志清空方法

    1.清空日志:DUMP   TRANSACTION   databasename   WITH   NO_LOG 2.截断事务日志:BACKUP   LOG   databasename   WITH ...