zoukankan      html  css  js  c++  java
  • Codeforces 14A

    就像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
    ***
    *.*
    ***
     1 #include<cstdio>
     2 int n,m;
     3 int up,down,left,right;
     4 char sheet[53][53];
     5 int main()
     6 {
     7     scanf("%d%d",&n,&m);
     8     left=m+1, right=0, up=n+1, down=0;
     9     for(int i=1;i<=n;i++)
    10     {
    11         scanf("%s",sheet[i]+1);
    12         for(int j=1;j<=m;j++)
    13         {
    14             if(sheet[i][j]=='*')
    15             {
    16                 if(j<left) left=j;
    17                 if(j>right) right=j;
    18                 if(i<up) up=i;
    19                 if(i>down) down=i;
    20             }
    21         }
    22     }
    23     for(int i=up;i<=down;i++)
    24     {
    25         for(int j=left;j<=right;j++) printf("%c",sheet[i][j]);
    26         printf("
    ");
    27     }
    28 }

                                                                                                                                                                                                         

    题目链接: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,那就必然有一条边上要垒上一些个方块,那么就会比原来多两条单位边(即一个小正方形的一条边);

    如果第一条边垒满了,要垒第二条边了,那就又再多两条单位边;

    而且,最多垒满两条边,不会再多;

     1 #include<cstdio>
     2 #include<cmath>
     3 int n,l,ans;
     4 int main()
     5 {
     6     scanf("%d",&n);
     7     double tmp=sqrt(n);
     8     l=(int)floor(tmp);
     9     ans=4*l;
    10     if(n-l*l>l) ans+=4;
    11     else if(0<n-l*l && n-l*l<=l) ans+=2;
    12     printf("%d
    ",ans);
    13 }
  • 相关阅读:
    WinForm换行
    aspx获取页面间传送的值
    Response.BinaryWrite()方法输出二进制图像
    Jquery删除table的行和列
    WinForm DataGridView控件隔行变色
    IE中table的innerHTML无法赋值
    C#为IE添加可信任站点
    静态代码检查
    第三方开源小工具
    查看sql server 服务器内存使用情况
  • 原文地址:https://www.cnblogs.com/dilthey/p/7542246.html
Copyright © 2011-2022 走看看