zoukankan      html  css  js  c++  java
  • Clear Symmetry CodeForces

    Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.

    Let's call matrix A clear if no two cells containing ones have a common side.

    Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i, j) (1 ≤ i, j ≤ n) both of the following conditions must be met: Ai, j = An - i + 1, j and Ai, j = Ai, n - j + 1.

    Let's define the sharpness of matrix A as the number of ones in it.

    Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x.

    Input

    The only line contains a single integer x (1 ≤ x ≤ 100) — the required sharpness of the matrix.

    Output

    Print a single number — the sought value of n.

    Example

    Input
    4
    Output
    3
    Input
    9
    Output
    5

    Note

    The figure below shows the matrices that correspond to the samples

    题解:①当n是偶数时,n-1所用到1的个数比n多。

       ②当n是奇数时,最多能用(n*n+1)/2个1。

       ③能用奇数构成所有的x。

    ①和③没证明出来,画图归纳的。。。。。

    注意:x=1,n=1; x=2,n=3; x=3,n=5;

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int x;
     5 int a[]={1,5,13,25,41,61,85,113};
     6 int b[]={1,3,5,7,9,11,13,15};
     7 
     8 int main()
     9 {   cin>>x;
    10     int p=0;
    11     if(x==3){ cout<<"5"<<endl; return 0; }
    12     while(a[p]<x) p++;
    13     cout<<b[p]<<endl;
    14 } 
  • 相关阅读:
    Linux内核中的信号机制--一个简单的例子【转】
    国际C语言混乱代码大赛代码赏析(一)【转】
    宏内核与微内核【转】
    Linux内核USB驱动【转】
    USB驱动开发大全【转】
    Linux驱动程序学习【转】
    GPIO口及中断API函数【转】
    Linux的fasync驱动异步通知详解【转】
    request_irq() | 注册中断服务函数【转】
    混杂设备动态次设备号分析【转】
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7847049.html
Copyright © 2011-2022 走看看