sgu246:Black & White(打表找规律)

来源:互联网 发布:js开头注释怎么写 编辑:程序博客网 时间:2024/05/15 01:26

题目大意:
      对于长度为2n101序列,有k1,求出最小的k使得所有这样的序列从中任取两个1(可以一样)之间夹着的两边元素个数有一个为n

分析:
      我弄出了个O(n)的暴力打个表找出了规律…

AC code:

#include <cstdio>using namespace std;int main(){    #ifndef ONLINE_JUDGE    freopen("input.txt", "r", stdin);    freopen("output.txt", "w", stdout);    #endif    int n;    scanf("%d", &n);    n = (n>>1)+1;    if(n%3 == 0 || n%3 == 1) printf("%d\n", n);    else printf("%d\n", n-1);    #ifndef ONLINE_JUDGE    fclose(stdin);    fclose(stdout);    #endif    return 0;}
0 0
原创粉丝点击