• 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 ...

  • 相关阅读:
    UVA
    UVA
    UVA
    UVA
    POJ
    Yahoo Programming Contest 2019 自闭记
    Codeforces Global Round 1 自闭记
    CodeCraft-19 and Codeforces Round #537 Div. 2
    BZOJ4912 SDOI2017天才黑客(最短路+虚树)
    BZOJ2877 NOI2012魔幻棋盘(二维线段树)
  • 原文地址:https://www.cnblogs.com/pprp/p/7399317.html
Copyright © 2020-2023  润新知