Codeforces 859B Lazy Security Guard
来源:互联网 发布:白衣服发黄 知乎 编辑:程序博客网 时间:2024/05/18 02:35
题目链接:CF-859B
同样也是很有意思的一道题,和今年某场多校有一些相似。
题意是这样的,在无限大的单位为1的正方形网格中,求一条曲线(其实都是直的)的最小周长,其中这条曲线是恰好围成N个小正方形的边界。
自己画几个图就可以知道,最优策略肯定是近似于正方形的曲线,如果N是完全平方数,那么直接围成正方形即可,如果不是完全平方数,只需要让长和宽尽可能相等就行(其实用到了基本不等式)。
找到第一个满足x*x>N的x,在x附近简单枚举就可以。
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <string.h>#include <string>#define ll long longusing namespace std;int main(){int N;scanf("%d", &N);int x;int ans = 1000000000;for (int i = 1;i <= 1000;++i){if (i*i >= N){x = i;break;}}if (x*x == N)printf("%d\n", 4 * x);else{for (int i = x - 1;i <= x + 1;++i){int rem = N / i;int mod = N%i;if (mod == 0)ans = min(ans, 2 * (i + rem));elseans = min(ans, 2 * (i + rem + 1));}printf("%d\n", ans);}//system("pause");return 0;}
阅读全文
0 0
- codeforces 859B B. Lazy Security Guard
- Codeforces 859B Lazy Security Guard
- Codeforces 859B Lazy Security Guard
- Codeforces 605B Lazy Student
- 605B. Lazy Student(codeforces Round 335)
- [CodeForces 605B]Lazy Student[贪心][构造]
- CodeForces 605 B.Lazy Student(构造)
- java.security.Guard翻译
- codeforces 859B
- Redis Essentials 读书笔记 - 第七章: Security Techniques (Guard Your Data)
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- guard
- Guard
- 【22.73%】【codeforces 606D】Lazy Student
- lazy
- SQL基本语法【SQl】
- 超新潮的智能机器人品牌旗舰店推荐_智能机器人分类_旗舰店推荐
- [python]leetcode(438). Find All Anagrams in a String
- DevExpress GridView 那些事儿
- SSH整合技术
- Codeforces 859B Lazy Security Guard
- fatal error LNK1201: 写入程序数据库“.pdb”时出错
- Python中显示图片
- 项目使用dubbo 、zookeeper服务报 Could not initialize class org.I0Itec.zkclient.ZkClient
- Java 位运算符:左移 << 右移 >> 无符号右移 >>>
- HashMap源码剖析
- Maven中的dependencyManagement和dependencies区别
- 体系化认识RPC
- React Native学习二