2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154

题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条。

解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab。最优解肯定是离 sqrt(n/2)很近的位置。想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了。我给一张做题时画的图

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        LL n;
        scanf("%lld", &n);
        if(n == 1 || n == 2){
            puts("4");
        }
        else if(n == 3 || n == 4){
            puts("6");
        }
        else if(n==5){
            puts("7");
        }
        else if(n>=6&&n<=8){
            puts("8");
        }
        else{
            LL m = floor(sqrt(n/2));
            LL tmp = m*4;
            LL x = m*m*2;
            if(n==x){
                printf("%lld\n", tmp);
            }
            else if(n<=x+m-0.5){
                printf("%lld\n", tmp+1);
            }
            else if(n<=x+2*m){
                printf("%lld\n", tmp+2);
            }
            else if(n<=x+3*m+0.5){
                printf("%lld\n", tmp+3);
            }
            else printf("%lld\n", tmp+4);
        }
    }
    return 0;
}

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维

时间: 2024-08-02 02:47:24

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维的相关文章

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff(几何找规律)

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,hi

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/7398272.html 先考虑dp求01串的不同子序列的个数. dp[i][j]表示用前i个字符组成的以j为结尾的01串个数. 如果第i个字符为0,则dp[i][0] = dp[i-1][1] + dp[i-1][0] + 1,dp[i][1] = dp[i-1][1] 如果第i个字符为1,则dp[i][1

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6153 A Secret KMP,思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意:给了串s和t,要求每个t的后缀在在s中的出现次数,然后每个次数乘上对应长度求和. 解法:关键在于想到把s和t都翻转之后,把t求next,然后用t去匹配s,在匹配过程中把fail指针跳到的地方加1,但是还没完,最后需要反向遍历第二个串将大串对小串的贡献加上去就可以了. 这道题是很多现场AC的代码是有漏洞的,比如bazbaba,bazbaba这个答案是34,但是很多现场AC的代码会输出31.

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6150 Vertex Cover 二分图,构造

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6150 题意:"最小点覆盖集"是个NP完全问题 有一个近似算法是说-每次选取度数最大的点(如果有多个这样的点,则选择最后一个) 让你构造一个图,使得其近似算法求出来点数是你给定的覆盖点数的至少3倍. 解法: 可以把左边的点编号1~n,将左边的点进行n次分块,第i次分块中每块的大小为i,对于每一块的点,都在右边创建一个新节点与这些点相连. ①右边的点的度数为n,n-1,n-2,...,n/2,

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做一个数位DP就好了.dp[jz][start][cur][state]表示jz进制下以start位起始到cur位状态为state(1表示已经回文,0表示没有回文)时回文数的个数. #include <bits/stdc++.h> using namespace std; typedef long

2017中国大学生程序设计竞赛 - 网络选拔赛 1004

A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which h

2017中国大学生程序设计竞赛 - 网络选拔赛 1005

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 Cao

2017中国大学生程序设计竞赛 - 网络选拔赛

Friend-Graph Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6514    Accepted Submission(s): 1610 Problem Description It is well known that small groups are not conducive of the development of

HDU 5833 Zhu and 772002(高斯消元)——2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 48    Accepted Submission(s): 16 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the abili