就像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.

Input

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

Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.

Examples
input
6 7
.......
..***..
..*....
..***..
..*....
..***..
output
***
*..
***
*..
***
input
3 3
***
*.*
***
output
***
*.*
***
 #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

Input will consist of a single integer N (1 ≤ N ≤ 106), the number of city blocks that must be enclosed by the route.

Output

Print the minimum perimeter that can be achieved.

Examples
input
4
output
8
input
11
output
14
input
22
output
20
Note

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 - [周赛水题]的更多相关文章

  1. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  2. 【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 ...

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

  4. Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题

    题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...

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

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

  7. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

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

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

随机推荐

  1. Java使用泛型实现栈结构

    泛型是Java SE5.0的重要特性,使用泛型编程可以使代码获得最大的重用.由于在使用泛型时要指明泛型的具体类型,这样就避免了类型转换.本实例将使用泛型来实现一个栈结构,并对其进行测试. 思路分析:既 ...

  2. Java单例模式的应用

    单例模式用于保证在程序的运行期间某个类有且仅有一个实例.其优势在于尽可能解决系统资源.通过修改构造方法的访问权限就可以实现单例模式. 代码如下: public class Emperor { priv ...

  3. PostgreSQL逻辑复制之slony篇

    Slony是PostgreSQL领域中最广泛的复制解决方案之一.它不仅是最古老的复制实现之一,它也是一个拥有最广泛的外部工具支持的工具,比如pgAdmin3.多年来,Slony是在PostgreSQL ...

  4. mongo数据库查询结果不包括_id字段方法

    db.GPRS_PRODUCT_HIS_FEE.find({"条件字段" : "412171211145135"},{_id:0}) db.GPRS_PRODU ...

  5. WebForm的初步认识

    嘿嘿,这里就简单的总结一下初步学习webform以及对他的认识,其实大家都认为webform很讨厌,因为好多都是给我们封装好的,而且现在好多的公司已经慢慢的从中逃离出来选择使用mvc架构,甚至好多的项 ...

  6. STL概论

    一.STL简介 1.STL(Standard Template Library,标准模板库)是C++标准库最主要和最重要的组成部分.其重要作用在于: (1)它可以用来创建动态增长和减小的数据结构: ( ...

  7. (原创)Windows下使用android ADT工具dmtracedump.exe绘图

    在windows下使用dmtracedump绘图时,出现如下错误: 'dot' 不是内部或外部命令,也不是可运行的程序 或批处理文件. 应该是没有dot这个执行程序,安装:Graphviz程序,然后将 ...

  8. SqlServer 连接远程服务器数据库 实现跨服务器联合查询

    第一种: exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' exec sp_addlinkedsrvlogin 'IT ...

  9. springaop---->springaop的使用(一)

    与大多数技术一样, AOP 已经形成了自己的术语.描述切面的常用术语有通知(advice).切点(pointcut)和连接点(join point).从今天开始,我们对spring的切面编程做一个总结 ...

  10. springbatch---->springbatch的使用(六)

    前面的例子step都是线性的流程,这里我们提供一个非线性的流程,也就是根据不同的状态做不同的流程step处理.万一有天悔恨变得太现实太世故太麻木,说不定能从回忆中重拾随兴飞翔. step非线性的流程 ...