zoukankan      html  css  js  c++  java
  • NYOJ 491 幸运三角形(bitset)

     1 #include<iostream>
     2 #include<cmath>
     3 #include<cstdio>
     4 #include<bitset>
     5 using namespace std;
     6 int a[22],n;
     7 int b[] = {0,0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757};
     8 
     9 void slove()
    10 {
    11     freopen("out.txt","w",stdout);
    12     int i, j, s1, s2, n,sum, T;
    13     n = 1;
    14     while(n < 20)
    15     {
    16         T = pow(2.0, n);
    17         sum = 0;
    18         while(T--)
    19         {
    20             bitset<20> b(T);
    21             s1 = s2 = 0;
    22             for(i=0; i < n; ++i)
    23             {
    24                 a[i] = b[i];
    25                 if(a[i]) ++s1;
    26                 else     ++s2;
    27             }
    28             for(j = 0; j < n; ++j)
    29             {
    30                 for(i = 0; i < n-j-1; ++i)
    31                 {
    32                     if(a[i] == a[i+1])
    33                     {    a[i] = 1;    ++s1;  }
    34                     else
    35                     {    a[i] = 0;    ++s2;  }
    36                 }
    37             }
    38             if(s1 == s2)
    39                 ++sum;
    40         }
    41         b[n++] = sum;
    42         cout<<","<<b[n-1];
    43     }
    44     cout<<endl;
    45 }
    46 
    47 int main()
    48 {
    49 //    slove();
    50     while(~scanf("%d",&n))
    51         printf("%d\n",b[n]);
    52     return 0;
    53 }

    先暴力解开答案,然后存入数组打表即可。。。做的时候突然想到可以用bitset<>...,很方便的哦。。。

  • 相关阅读:
    LeetCode 1275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
    LeetCode 307. 区域和检索
    LeetCode 1271 十六进制魔术数字 Hexspeak
    秋实大哥与花 线段树模板
    AcWing 835. Trie字符串统计
    Leetcode 216. 组合总和 III
    Mybatis 示例之 复杂(complex)属性(property)
    Mybatis 示例之 复杂(complex)属性(property)
    Mybatis 高级结果映射 ResultMap Association Collection
    Mybatis 高级结果映射 ResultMap Association Collection
  • 原文地址:https://www.cnblogs.com/yaling/p/3043440.html
Copyright © 2011-2022 走看看