codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
就像title说的,是昨天(2017/9/17)周赛的两道水题……
题目链接:http://codeforces.com/problemset/problem/14/A
time limit per test: 1 second memory limit per test: 64 megabytes
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
The first line of the input data contains numbers n and m (1 ≤ n, m ≤ 50), n — amount of lines, and m — amount of columns on Bob's sheet. The following n lines contain m characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
6 7
.......
..***..
..*....
..***..
..*....
..***..
***
*..
***
*..
***
3 3
***
*.*
***
***
*.*
***
#include<cstdio>
int n,m;
int up,down,left,right;
char sheet[][];
int main()
{
scanf("%d%d",&n,&m);
left=m+, right=, up=n+, down=;
for(int i=;i<=n;i++)
{
scanf("%s",sheet[i]+);
for(int j=;j<=m;j++)
{
if(sheet[i][j]=='*')
{
if(j<left) left=j;
if(j>right) right=j;
if(i<up) up=i;
if(i>down) down=i;
}
}
}
for(int i=up;i<=down;i++)
{
for(int j=left;j<=right;j++) printf("%c",sheet[i][j]);
printf("\n");
}
}
题目链接:http://codeforces.com/problemset/problem/859/B
time limit per test: 2 seconds memory limit per test: 256 megabytes
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.
Input will consist of a single integer N (1 ≤ N ≤ 106), the number of city blocks that must be enclosed by the route.
Print the minimum perimeter that can be achieved.
4
8
11
14
22
20
Here are some possible shapes for the examples:

肯定首先要尽量做成一个大正方形,所以我们取int l = floor(sqrt(n));
然后多出来的方块块怎么办嘞,肯定就是往大正方形的一条边上垒小方块,如果一条边垒满了, 就换条边垒(垒第二条边);
显然,只要n>l*l,那就必然有一条边上要垒上一些个方块,那么就会比原来多两条单位边(即一个小正方形的一条边);
如果第一条边垒满了,要垒第二条边了,那就又再多两条单位边;
而且,最多垒满两条边,不会再多;
#include<cstdio>
#include<cmath>
int n,l,ans;
int main()
{
scanf("%d",&n);
double tmp=sqrt(n);
l=(int)floor(tmp);
ans=*l;
if(n-l*l>l) ans+=;
else if(<n-l*l && n-l*l<=l) ans+=;
printf("%d\n",ans);
}
codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]的更多相关文章
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- 【CF MEMSQL 3.0 B. Lazy Security Guard】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题
题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
随机推荐
- SpringBoot------热部署(Springloaded)
为啥要热部署: 在修改代码的时候,不需要重新启动程序,程序会自动进行编译 注意: 控制器中新增加的方法是不能进行热部署的 方法: 1.在pom.xml文件里面添加下面代码 <project> ...
- Nexus5 破解电信关键步骤
5儿子终于摔坏了,送去保养之后,发现之前已破解的电信3G竟然无效了,心碎!!!!!!!!!!!!!!!!!! 尝试恢复efs --还好有备份,备份万岁!!! 不行!继续尝试恢复!还是不行!再试!... ...
- eclipse debug Liunx服务器上的svn项目
1.本地项目提交到svn上,以保证本地代码与服务器代码相同 2.开启服务器debug端口 3.使用root账号重新部署服务器项目并监听catalina.out sh /home/p/deploy/gt ...
- 品鉴同事发来的炸金花的PHP程序代码
今天同事发来了一个炸金花的PHP程序,这个代码实现了两个人通过各自的三张牌进行权重计算,得到分数进行比较得到谁的牌大,我觉得里面还有一些问题,代码如下: <?php /** 每张牌的分值为一个2 ...
- 【数据分析】Superset 之一 准备
https://segmentfault.com/a/1190000005083953 http://blog.csdn.net/bingoxubin/article/details/78583165 ...
- Linux应急响应(一):SSH暴力破解
0x00 前言 SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全.SSH口令长度太短或者复杂度不够,如仅包含数字,或仅包 ...
- 使用一条sql查询多个表中的记录数
方法一: select t1.num1,t2.num2,t3.num3 from (select count(*) num1 from table1) t1, (select count(*) num ...
- DOM的学习
今天学习了DOM,感觉学习起来真的没那么简单啦,这不是一个好现象啊,只有依靠自己大补课,嘿嘿,具体的总结了一下,今天学习的其实并不多,仅仅学习了不同的节点类型,但是知识还是蛮碎的,要一点一点的总结,昨 ...
- rabbitMQ常用的命令
rabbitMQ常用的命令 启动监控管理器:rabbitmq-plugins enable rabbitmq_management 关闭监控管理器:rabbitmq-plugins disable r ...
- 《转》windows下通过cmd切换python2和python3版本
当电脑中同时安装了python2和python3时,往往会由切换版本的需求.那么如何通过cmd命令行做到呢? 方法:修改python.exe的文件名 举个栗子: 我的电脑中同时安装了py2.7.10和 ...