• Codeforces Beat Round#57(Div.2)


    A. Table
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1)(n, 1)(1, m)(n, m).

    Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.

    Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (x1, y1), an arbitrary corner of the table (x2, y2) and color all cells of the table (p, q), which meet both inequations: min(x1, x2) ≤ p ≤ max(x1, x2)min(y1, y2) ≤ q ≤ max(y1, y2).

    Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.

    Input

    The first line contains exactly two integers nm (3 ≤ n, m ≤ 50).

    Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.

    Output

    Print a single number — the minimum number of operations Simon needs to carry out his idea.

    Sample test(s)
    input
    3 3
    0 0 0
    0 1 0
    0 0 0
    output
    4
    input
    4 3
    0 0 0
    0 0 1
    1 0 0
    0 0 0
    output
    2
    Note

    In the first sample, the sequence of operations can be like this:

    • For the first time you need to choose cell (2, 2) and corner (1, 1).
    • For the second time you need to choose cell (2, 2) and corner (3, 3).
    • For the third time you need to choose cell (2, 2) and corner (3, 1).
    • For the fourth time you need to choose cell (2, 2) and corner (1, 3).

    In the second sample the sequence of operations can be like this:

    • For the first time you need to choose cell (3, 1) and corner (4, 3).
    • For the second time you need to choose cell (2, 3) and corner (1, 1).
     1 /*************
     2 AC
     3 Time:2013-11-2
     4 ************/
     5 #include <iostream>
     6 #include<stdio.h>
     7 #include<string.h>
     8 #include<math.h>
     9 
    10 using namespace std;
    11 int num[52][52];
    12 int main()
    13 {
    14     int n,m;
    15     while(scanf("%d %d",&n,&m)!=EOF)
    16     {
    17         for(int i=1;i<=n;i++)
    18         {
    19             for(int j=1;j<=m;j++)
    20             {
    21                 scanf("%d",&num[i][j]);
    22             }
    23         }
    24         int judge=0;
    25         for(int i=1;i<=m;i++)
    26         {
    27             if(num[1][i]==1)
    28             judge=1;
    29         }
    30         for(int i=1;i<=m;i++)
    31         {
    32             if(num[n][i]==1)
    33             judge=1;
    34         }
    35         for(int i=1;i<=n;i++)
    36         {
    37             if(num[i][1]==1)
    38             judge=1;
    39         }
    40         for(int i=1;i<=n;i++)
    41         {
    42             if(num[i][m]==1)
    43             judge=1;
    44         }
    45         if(judge==1)printf("2
    ");
    46         else printf("4
    ");
    47     }
    48 
    49     return 0;
    50 }
    View Code
     
     
    B. Permutation
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.

    Simon has a positive integer n and a non-negative integer k, such that 2k ≤ n. Help him find permutation a of length 2n, such that it meets this equation: .

    Input

    The first line contains two integers n and k (1 ≤ n ≤ 500000 ≤ 2k ≤ n).

    Output

    Print 2n integers a1, a2, ..., a2n — the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.

    Sample test(s)
    input
    1 0
    output
    1 2
    input
    2 1
    output
    3 2 1 4
    input
    4 0
    output
    2 7 4 6 1 3 5 8
    Note

    Record |x| represents the absolute value of number x.

    In the first sample |1 - 2| - |1 - 2| = 0.

    In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.

    In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.

     1 /************
     2 AC
     3 Time:2013-11-2
     4 *************/
     5 #include <iostream>
     6 #include<stdio.h>
     7 #include<string.h>
     8 int num[100100];
     9 
    10 using namespace std;
    11 
    12 int main()
    13 {
    14     int n,k;
    15     while(scanf("%d%d",&n,&k)!=EOF)
    16     {
    17         for(int i=1;i<=2*n;i++)
    18         {
    19             num[i]=2*n-i+1;
    20         }
    21         for(int j=1;j<=k;j++)
    22         {
    23             int t=num[j*2];
    24             num[j*2]=num[j*2-1];
    25             num[j*2-1]=t;
    26         }
    27         for(int i=1;i<=2*n;i++)
    28         {
    29             if(i!=1)printf(" %d",num[i]);
    30             else printf("%d",num[i]);
    31         }
    32         printf("
    ");
    33     }
    34     return 0;
    35 }
    Problem B code
     
    D. Pair of Numbers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold:

    1. there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj;
    2. value r - l takes the maximum value among all pairs for which condition 1 is true;

    Help Simon, find the required pair of numbers (l, r). If there are multiple required pairs find all of them.

    Input

    The first line contains integer n (1 ≤ n ≤ 3·105).

    The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).

    Output

    Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.

    Sample test(s)
    input
    5
    4 6 9 3 6
    output
    1 3
    2
    input
    5
    1 3 5 7 9
    output
    1 4
    1
    input
    5
    2 3 5 7 11
    output
    5 0
    1 2 3 4 5
    Note

    In the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.

    In the second sample all numbers are divisible by number 1.

    In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1)(2, 2)(3, 3)(4, 4)(5, 5).

    ps:开始脑残的写错了,没过。

     1 /***************
     2 AC
     3 Time:2013-11-3
     4 **********************/
     5 #include <iostream>
     6 #include<stdio.h>
     7 #include<string.h>
     8 #include<math.h>
     9 int pre[300050];
    10 int csn[300050];
    11 
    12 using namespace std;
    13 
    14 int main()
    15 {
    16     int n;
    17     while(scanf("%d",&n)!=EOF)
    18     {
    19         int l,r;
    20         int tmp=0;
    21         int cnt=0;
    22         for(int i=1;i<=n;i++)
    23         scanf("%d",&pre[i]);
    24         for(int i=1;i<=n;i++)
    25         {
    26             l=r=i;
    27             while(l&&pre[l]%pre[i]==0)l--;
    28             while(r<=n&&pre[r]%pre[i]==0)r++;
    29             i=r;
    30             r=r-l-2;
    31             if(r>tmp)
    32             {
    33                 tmp=r;
    34                 cnt=0;
    35                // csn[cnt++]=l+1;
    36             }
    37             if(r==tmp)
    38             {
    39                 csn[cnt++]=l+1;
    40                 //printf("!!!
    ");
    41             }
    42 
    43         }
    44         printf("%d %d
    ",cnt,tmp);
    45         for(int i=0;i<cnt;i++)
    46         {
    47             if(i!=0)printf(" %d",csn[i]);
    48             else printf("%d",csn[i]);
    49         }
    50         printf("
    ");
    51     }
    52     return 0;
    53 }
    problem D code
  • 相关阅读:
    SecureCRT 连接 虚拟机Linux 命令
    如何使用secureCRT连接vmware中的虚拟主机?
    SecureCRT8.1+SecureCRT_keygen完成注册
    常用python机器学习库总结
    Torch7在Ubuntu下的安装与配置
    朴素贝叶斯算法 & 应用实例
    编写MR代码中,JAVA注意事项
    march.
    Docker CentOS 7.2镜像systemd问题解决办法
    Docker 基础命令 简要入门
  • 原文地址:https://www.cnblogs.com/ACshasow/p/3416142.html
Copyright © 2020-2023  润新知