原题:  Turn the pokers
      思路:假设正面为0,反面为1。牌就像这样 000000....... 。考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面其余都为正面的状况都能实现。于是转化为考虑最终可能出现1的个数的集合有哪些。
      因为可能的个数集合是连续的(在最大最小值之内相差2的都可能), 所以每一次翻转之后的上下限都可以根据上一次所得的上下限推出。
      最后算排列组合的适合需要用到组合数递推公式和费马小定理推论\( a^{p-2} \equiv a^{-1} \bmod p \) , 通过快速幂的方法算一下逆元。

其实TLE了n次。。。。。。用位运算简化了一下。。。而且输入那个部分要用scanf才够快。

  1 #include <iostream>

  2 #include <fstream>

  3 #include <cstring>

  4 #include <cstdio>

  5 #include <algorithm>

  6 #include <cmath>

  7 //#define LOCAL

  8 #define fin cin

  9 #define fout cout

 10 #define LL long long int

 11 #define maxn 100000+5

 12 using namespace std;

 13 LL MM=;

 14 LL C[maxn];

 15 LL quickmod(LL a,int b)

 16 {

 17    LL ans=,base=a;

 18 

 19    while(b!=)

 20    {

 21      if(b&)

 22      {

 23         ans=ans*base%MM;

 24     }

 25     b>>=;

 26     base=base*base%MM;

 27 }

 28 

 29 return ans;

 30 }

 31 int main ()

 32 {

 33 #ifdef LOCAL

 34     ofstream fout ("1.out");

 35     ifstream fin ("1.in");

 36 #endif

 37 

 38     int i,j,k;

 39     int n,m,x;

 40 

 41     memset(C,,sizeof(C));

 42 

 43     while(fin>>n>>m)

 44     {

 45 

 46         int left,right,a1,a2;

 47         left=; right=;

 48 

 49         for(i=;i<n;i++)

 50         {

 51             scanf("%d",&x);

 52 

 53 

 54             if(x<=left){ a1=left-x; }

 55             else if(x<=right)

 56                 {   a1= ((left&)==(x&))?:;

 57                 }

 58                 else{

 59                     a1=x-right;

 60                 }

 61 

 62                 if(x<=m-right){ a2=right+x; }

 63                 else if(x<=m-left)

 64                 {

 65                     a2 = (((m-left)&) == (x&)?m:m-);

 66                 }

 67                 else{

 68                     a2=*m-(x+left);

 69                 }

 70 

 71                 left=a1;right=a2;

 72 

 73             }

 74 

 75 

 76             C[]=; C[m]=;

 77 

 78             for(i=;i<=m/+;i++)

 79                 {C[i]=C[i-]*(m-i+)%MM*quickmod(i,MM-)%MM;

 80 

 81                    C[m-i]=C[i];

 82                }

 83 

 84 

 85                LL sum = ;

 86                for(i = left; i<=right; i+=)

 87                 { sum+=C[i];

 88                   sum%=MM;

 89               }

 90 

 91               fout<<sum<<endl;

 92           }

 93 

 94 

 95 #ifdef LOCAL

 96           fin.close();

 97           fout.close();

 98 #endif

 99 

           return ;} 

HDU-4869 Turn the pokers的更多相关文章

  1. HDU 4869 Turn the pokers(推理)

    HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...

  2. hdu 4869 Turn the pokers (2014多校联合第一场 I)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 4869 Turn the pokers(思维+组合公式+高速幂)

    pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...

  4. HDU 4869 Turn the pokers (2014 Multi-University Training Contest 1)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. hdu 4869 Turn the pokers (思维)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4869 Turn the pokers(组合数+费马小定理)

    Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...

  8. HDU 4869 Turn the pokers (2014 多校联合第一场 I)

    HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...

  9. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

  10. HDU 4869 Turn the pokers(思维+逆元)

    考试的时候没有做出来... 想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数. 原来直接模拟一遍就可以算出来最后的端点... 剩下的就是组合数取模了,用逆元就行了... # incl ...

随机推荐

  1. Codeforces Round #385 //再遇状压

    敲完三题挂机一小时.....  也没懂DE什么意思  rank600上了一波分... A. Hongcow Learns the Cyclic Shift 给一个字符串,每次可以把最后一个字符拿到开头 ...

  2. github 添加项目

    下载git安装 ->https://git-scm.com/downloads 新建git目录 在目录下右键选择Git Bash Here 执行 git init 拷贝项目到git目录下 在gi ...

  3. 09-JAVA中的异常处理

    1. 程序执行结果: 也就是它根本就没抛出异常,更别提捕获异常了.那么,为什么会这样呢? 原来, 如上面程序展示,程序运行到k=i/j;的时候,就会直接终止,根本就不会运行到监视的程序,更不会运行到捕 ...

  4. 使用WebDriver遇到的那些坑

    在做web项目的自动化端到端测试时主要使用的是Selenium WebDriver来驱动浏览器.Selenium WebDriver的优点是支持的语言多,支持的浏览器多.主流的浏览器Chrome.Fi ...

  5. 微信公众平台创建自定义菜单中文编码导致system error

    创建包含了中文的自定义菜单时总是返回{"errcode":-1,"errmsg":"system error"},要将编码方式设置为UTF- ...

  6. java日常时间处理

    private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", & ...

  7. [linux] 默认权限修改(umask)

    1 文件默认权限 对于目录,默认权限=777-umask 对于文件,默认权限=666-umask(文件默认无执行权限) 默认权限修改: vim /etc/bashrc 71行是普通用户的更改,73是超 ...

  8. CString 字符串截取_函数

    CString res;CString str = _T("abcdefghijklmn"); res = str.Mid(2,3);  //从第3位字母开始,共取3个字符ASSE ...

  9. 20145316&20145229实验四:驱动程序设计

    20145316&20145229实验四:驱动程序设计 结对伙伴:20145316 许心远 博客链接:http://www.cnblogs.com/xxy745214935/p/6130871 ...

  10. apache和nginx开启https

    1.安装mod_ssl和openssl yum -y install mod_ssl openssl 2.建立服务器密钥 mkdir /etc/httpd/conf.d/ssl.key/ cd /et ...