惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
博客园 - 司徒正美
博客园 - 【当耐特】
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
宝玉的分享
宝玉的分享
V
V2EX
S
SegmentFault 最新的问题
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
L
LangChain Blog
D
Docker
腾讯CDC

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
HDU 6154.CaoHaha's staff|OhYee 博客
2017-08-25 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

{% fold 点击显/隐题目 %}

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

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

Out put T integer in each line ,the least time CaoHaha can send the toy.

{% endfold %}

题解

给你一个面积,在平面坐标系中最少用多少长度为1√2的边能围出来

这种题基本上就是找规律的问题,首先画出来前几种的形状
首先要明确的原则是:

  • 周长越大围的面积也越大,也即尽可能多用√2
  • 周长相同的情况下越圆面积越大

如下图:


很容易发现,在7条边向8条边转换的时候,虽然正八边形更接近圆形,但是围出来正方形(菱形)面积更大

那么就可以看出来,其实只要是正好是4的倍数条边的时候能围成正方形面积最大
剩下只剩下3种情况,分别是向外拓展1、2、3条边,也是有规律的

打表记录有i个边能最大围出来多大,然后二分查找即可

最大面积是1e9 围成正方形需要的边是 4*√(1e9/2)=1.2e5
表只需要打到 1.5e5 即可

代码

{% fold 点击显/隐代码 %}```cpp CaoHaha's staff https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
#include
#include
using namespace std;

const int maxn = 150000;

long long f[maxn];
void calc() {
f[0] = f[1] = f[2] = f[3] = 0;
f[4] = 2;
f[5] = 2;
f[6] = 4;
f[7] = 5;
for (long long i = 2; i < (maxn / 4) - 1; ++i) {
f[i * 4] = i * i * 2;
f[i * 4 + 1] = f[i * 4] + (i + i - 1) / 2;
f[i * 4 + 2] = f[i * 4] + i * 2;
f[i * 4 + 3] = f[i * 4 + 2] + (i + i + 1) / 2;
}
}

int main() {
// freopen("out.txt","w",stdout);
int T;
scanf("%d", &T);
calc();

/*
for (int i = 1; i < 100; ++i) {
    printf("%d %d\n", i, lower_bound(f, f + maxn, i) - f);
}
*/

while (T--) {
    long long n;
    scanf("%I64d", &n);
    printf("%d\n", lower_bound(f, f + maxn, n) - f);
}

return 0;

}

{% endfold %}