zoukankan      html  css  js  c++  java
  • 2017中国大学生程序设计竞赛

    CaoHaha's staff

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 0    Accepted Submission(s): 0


    Problem Description
    "You shall not pass!"
    After shouted out that,the Force Staff appered in CaoHaha's hand.
    As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
    But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
    Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
    The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
    If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
    CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help.
     
    Input
    The first line contains one integer T(T<=300).The number of toys.
    Then T lines each contains one intetger S.The size of the toy(N<=1e9).
     
    Output
    Out put T integer in each line ,the least time CaoHaha can send the toy.
     
    Sample Input
    5 1 2 3 4 5
     
    Sample Output
    4 4 6 6 7
    问面积为s的最少需要多少根线段,在坐标里,每根线段长度可以是1或sqrt(2),在一侧或者对角线。
    其实就是找规律题目。求s根线最大可以构成多大的面积(面积向下取整)。有四种情况。
    1、s = 4*n 这种情况是构成一个正方形,都是在对角线上的:

    最大面积是2*n*n

    2、s = 4*n + 1:

    面积为2*n*n+n-1

    3、s = 4*n + 2:

    面积为2*n*n+2*n

    4、s = 4*n + 3:

    面积为2*n*n+3*n

    所以每询问一个s,只要从4开始循环找到一个最小的n使的面积大于s就行。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <vector>
     5 #include <map>
     6 #include <set>
     7 #define ll long long
     8 using namespace std;
     9 ll solve(ll y) {
    10     ll n = y / 4, ans = y % 4, x;
    11     if(ans == 0) {
    12         x = 2*n*n;
    13     }else if(ans == 1) {
    14         x = 2*n*n+n-1;
    15     }else if(ans == 2) {
    16         x = 2*n*n+2*n;
    17     }else if(ans == 3) {
    18         x = 2*n*n+3*n;
    19     }
    20     return x;
    21 }
    22 int main() {
    23     ll t, x;
    24     scanf("%lld", &t);
    25     while(t--) {
    26         scanf("%lld", &x);
    27         for(ll i = 4; ; i ++) {
    28             if(solve(i) >= x) {
    29                 printf("%lld
    ",i);
    30                 break;
    31             }
    32         }
    33     }
    34     return 0;
    35 }
     
  • 相关阅读:
    关于二进制包安装MySQL出现yum安装保护多库场景解决
    关于 Fatal NI connect error 12170 错误
    调优排故笔记1-利用等待事件及相关文件和视图-Oracle内核揭秘
    MySQL的四种隔离级别
    Oracle绑定变量
    接口加密测试
    接口测试用例设计
    学习总结——接口测试中抓包工具的使用
    学习总结——JMeter做WebService接口功能测试
    JMeter做http接口压力测试
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7397373.html
Copyright © 2011-2022 走看看