zoukankan      html  css  js  c++  java
  • caohaha's stuff

    2017-08-20 11:12:29

    writer:pprp
    CCPC预选赛水平太菜了,去不了了

    这个是一个找规律的题目,题意一开始也很难理解

    题意描述:

    给你一个数,比如说1,在一个坐标系中你需要用多少个线段(横着竖着对角线都可以)才能围出1单位的面积

    很容易发现,当尽可能多的是对角线才能满足面积最大

    规律如图:加一个边,两个边,三个边,四个边

    这几种情况

    代码如下:(大佬的)

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        int T, S;
        scanf("%d", &T);
        while(T--)
        {
            scanf("%d", &S);
    
            int L = sqrt(S/2);   
            int area = 2*L*L;          
            
            if(S - area == 0)  //如果恰好等于
            {
                printf("%d
    ", L * 4);
            }
            else if(S - area <= L - 1)
            {
                printf("%d
    ", L * 4 + 1);
            }
            else if(S - area <= 2 * L)
            {
                printf("%d
    ", L * 4 + 2);
            }
            else if(S <= 2 * (L + 1) * (L + 1) - (L + 2))
            {
                printf("%d
    ", L * 4 + 3);
            }
            else
            {
                printf("%d
    ", (L + 1)*4);
            }
        }
    
        return 0;
    }

    orz ...

  • 相关阅读:
    git操作说明书
    python之routes入门
    python inspect库
    Python SMTP发送邮件
    Python深入:setuptools进阶
    Python打包之setuptools
    python graphviz的使用(画图工具)
    pathlib的使用
    python tempfile 创建临时目录
    python flake8 代码扫描
  • 原文地址:https://www.cnblogs.com/pprp/p/7399317.html
Copyright © 2011-2022 走看看