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 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\n",i);
30                 break;
31             }
32         }
33     }
34     return 0;
35 }
时间: 2024-10-11 03:42:25

2017中国大学生程序设计竞赛 - 网络选拔赛 1005的相关文章

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;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 namesp

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中国大学生程序设计竞赛 - 网络选拔赛 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中国大学生程序设计竞赛 - 网络选拔赛 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中国大学生程序设计竞赛 - 网络选拔赛

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

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

solved 4/11 2016中国大学生程序设计竞赛 - 网络选拔赛