• Codeforces Round #234 (Div. 2)


    A. Inna and Choose Options
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output


    There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:

    There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b (a·b = 12), after that he makes a table of size a × b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.

    Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win.

    Input

    The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.

    The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start.

    Output

    For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.

    Sample test(s)
    input
    4
    OXXXOXOOXOOX
    OXOXOXOXOXOX
    XXXXXXXXXXXX
    OOOOOOOOOOOO
    output
    3 1x12 2x6 4x3
    4 1x12 2x6 3x4 6x2
    6 1x12 2x6 3x4 4x3 6x2 12x1
    0

     题意:略

     sl:简单模拟

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 const int MAX = 1e6;
     6 char str[10];
     7 int a[10],b[10];
     8 int map[13][13];
     9 int main()
    10 {
    11     int cas,num,ans;
    12     scanf("%d",&cas);
    13     while(cas--)
    14     {
    15         num=ans=0int flag=0;
    16         scanf("%s",str);
    17         int n=strlen(str);
    18         for(int i=0;i<n;i++) if(str[i]=='X') num++;
    19         if(num>=1)
    20         {
    21             a[ans]=1;
    22             b[ans++]=12;
    23         }
    24         for(int i=0;i<6;i++)
    25         {
    26             if(str[i]==str[i+6]&&str[i]=='X')
    27             flag=1;
    28         }
    29         if(flag) a[ans]=2,b[ans++]=6;
    30         flag=0;
    31         for(int i=0;i<4;i++)
    32         {
    33             if(str[i]==str[i+4]&&str[i]==str[i+8]&&str[i]=='X')
    34             flag=1;
    35         }
    36         if(flag) a[ans]=3,b[ans++]=4;
    37         flag=0;
    38         for(int i=0;i<3;i++)
    39         {
    40             if(str[i]==str[i+3]&&str[i]==str[i+6]&&str[i]==str[i+9]&&str[i]=='X')
    41                 flag=1;
    42         }
    43         if(flag) a[ans]=4,b[ans++]=3;
    44         flag=0;
    45         for(int i=0;i<2;i++)
    46         {
    47             if(str[i]==str[i+2]&&str[i]==str[i+4]&&str[i]==str[i+6]&&str[i]==str[i+8]&&str[i]==str[i+10]&&str[i]=='X')
    48                 flag=1;
    49         }
    50         if(flag) a[ans]=6,b[ans++]=2;
    51         flag=0;
    52         if(num==12) a[ans]=12,b[ans++]=1;
    53         if(ans)
    54         {
    55             printf("%d",ans);
    56             for(int i=0;i<ans;i++)
    57             {
    58                 printf(" %dx%d",a[i],b[i]);
    59             }
    60             printf(" ");
    61         }
    62         else printf("0 ");
    63     }
    64     return 0;
    65 }

    B. Inna and New Matrix of Candies
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".

    The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player can choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:

    • some dwarf in one of the chosen lines is located in the rightmost cell of his row;
    • some dwarf in the chosen lines is located in the cell with the candy.

    The point of the game is to transport all the dwarves to the candy cells.

    Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.

    Input

    The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000).

    Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".

    Output

    In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.

    Sample test(s)
    input
    3 4
    *G*S
    G**S
    *G*S
    output
    2
    input
    1 3
    S*G
    output
    -1

    题意:比赛时猜的题意一发wa然后又猜一发ac,就是要把所有人放到糖里,人只能向右移动,当碰到墙或者碰到糖算是一次移动结束。求移动次数

    sl: 直接求一下每行人到糖的最小距离排个序统计一下即可

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 const int MAX = 1e3+10;
     6 char map[MAX][MAX];
     7 int ans[MAX],a[MAX],b[MAX];
     8 int main()
     9 {
    10     int n,m;
    11     while(scanf("%d %d",&n,&m)==2)
    12     {
    13         int t=0;
    14         memset(ans,0,sizeof(ans));
    15         memset(b,0,sizeof(b));
    16         int flag=1,len=0,cur;
    17         for(int i=0;i<n;i++)
    18         {
    19             getchar(); int check=1; cur=0;
    20             for(int j=0;j<m;j++)
    21             {
    22                 scanf("%c",&map[i][j]);
    23                 if(j==m-1&&map[i][j]=='G') flag=0;
    24                 if(map[i][j]=='G'&&check)
    25                 {
    26                     a[cur++]=j; check=0;
    27                 }
    28                 else if(map[i][j]=='S'&&cur>0)
    29                 {
    30                     t=j-a[cur-1]-1;
    31                     ans[i]=max(ans[i],t);
    32                     check=1;
    33                   //  printf("%d %d #%d ",j,a[cur-1],t);
    34                 }
    35             }
    36             if(!check) flag=0;
    37         }
    38         int ret=1;
    39         if(!flag) printf("-1 ");
    40         else
    41         {
    42             sort(ans,ans+n);
    43             for(int i=1;i<n;i++)
    44             {
    45                 if(ans[i]!=ans[i-1]) ret++;
    46             }
    47             printf("%d ",ret);//,printf("%d ",ans[i]);
    48         }
    49 
    50     }
    51     return 0;

    52 } 

    C. Inna and Huge Candy Matrix
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).

    The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.

    Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

    Input

    The first line of the input contains fix integers nmxyzp (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).

    Each of the following p lines contains two integers xkyk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.

    Output

    For each of the p candies, print on a single line its space-separated new coordinates.

    Sample test(s)
    input
    3 3 3 1 1 9
    1 1
    1 2
    1 3
    2 1
    2 2
    2 3
    3 1
    3 2
    3 3
    output
    1 3
    1 2
    1 1
    2 3
    2 2
    2 1
    3 3
    3 2
    3 1

     题意:给出三种对矩阵的操作:1,顺时针旋转90度,2,翻转,3,逆时针旋转90度,再给出一些点的坐标,问操作之后的点的坐标

    sl:简单矩阵旋转操作。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 const int MAX = 1e6;
     6 int a[MAX],b[MAX];
     7 int n,m,x,y,z,p;
     8 void get1()
     9 {
    10     int t;
    11     for(int i=0;i<p;i++)
    12     {
    13         t=a[i];
    14         a[i]=b[i];
    15         b[i]=n-t+1;
    16     }
    17     swap(n,m);
    18 }
    19 void get2()
    20 {
    21     int t;
    22     for(int i=0;i<p;i++)
    23     {
    24         t=b[i];
    25         b[i]=a[i];
    26         a[i]=m-t+1;
    27     }
    28     swap(n,m);
    29 }
    30 void get3()
    31 {
    32     int t;
    33     for(int i=0;i<p;i++)
    34     {
    35         b[i]=m-b[i]+1;
    36     }
    37 }
    38 int main()
    39 {
    40     int xx,yy,zz;
    41     while(scanf("%d %d %d %d %d %d",&n,&m,&x,&y,&z,&p)==6)
    42     {
    43         for(int i=0;i<p;i++)
    44         {
    45             scanf("%d %d",&a[i],&b[i]);
    46         }
    47         xx=x%4;
    48         for(int i=0;i<xx;i++)
    49         get1();
    50         yy=y%2;
    51         for(int i=0;i<yy;i++) get3();
    52         zz=z%4;
    53         for(int i=0;i<zz;i++) get2();
    54         for(int i=0;i<p;i++)
    55         {
    56             printf("%d %d ",a[i],b[i]);
    57         }
    58 
    59     }
    60     return 0;

    61 }

    D. Dima and Bacteria
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are numbered from  to .

    With the help of special equipment Dima can move energy from some bacteria into some other one. Of course, the use of such equipment is not free. Dima knows m ways to move energy from some bacteria to another one. The way with number i can be described with integers uivi and ximean that this way allows moving energy from bacteria with number ui to bacteria with number vi or vice versa for xi dollars.

    Dima's Chef (Inna) calls the type-distribution correct if there is a way (may be non-direct) to move energy from any bacteria of the particular type to any other bacteria of the same type (between any two bacteria of the same type) for zero cost.

    As for correct type-distribution the cost of moving the energy depends only on the types of bacteria help Inna to determine is the type-distribution correct? If it is, print the matrix d with size k × k. Cell d[i][j] of this matrix must be equal to the minimal possible cost of energy-moving from bacteria with type i to bacteria with type j.

    Input

    The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers c1, c2, ..., ck (1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that .

    Output

    If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».

    Sample test(s)
    input
    4 4 2
    1 3
    2 3 0
    3 4 0
    2 4 1
    2 1 2
    output
    Yes
    0 2
    2 0
    input
    3 1 2
    2 1
    1 2 0
    output
    Yes
    0 -1
    -1 0
    input
    3 2 2
    2 1
    1 2 0
    2 3 1
    output
    Yes
    0 1
    1 0
    input
    3 0 2
    1 2
    output
    No

     题意:给出一些集合,然后给出集合中元素之间的距离,判断单个集合中是不是满足任意两点都有长度为0的路径。并输出集合到集合的最短路。

    sl:可以用并查集判断是不是存在长度为0的路径,求最短路可以使用弗洛伊德算法,因为k只有500.

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 const int MAX = 1e5+10;
     6 const int inf = 0x3f3f3f3f;
     7 int dist[510][510],fa[MAX],check[MAX];
     8 int c[MAX],sum[MAX];
     9 void make(int n)
    10 {
    11     for(int i=1;i<=n;i++) fa[i]=i;
    12 }
    13 int find(int x)
    14 {
    15     if(fa[x]!=x)
    16     fa[x]=find(fa[x]);
    17     return fa[x];
    18 }
    19 void Union(int a,int b)
    20 {
    21     int x=find(a),y=find(b);
    22     if(x!=y) fa[x]=y;
    23 }
    24 int main()
    25 {
    26     int n,m,k,flag;
    27     int u,v,x;
    28     while(scanf("%d %d %d",&n,&m,&k)==3)
    29     {
    30         memset(sum,0,sizeof(sum));
    31         memset(check,0,sizeof(check));
    32         make(n);
    33         for(int i=0;i<=k;i++) for(int j=0;j<=k;j++)
    34         dist[i][j]=inf;
    35         for(int i=1;i<=k;i++) scanf("%d",&c[i]);
    36         for(int i=1;i<=k;i++) sum[i]=sum[i-1]+c[i];
    37         for(int i=0;i<m;i++)
    38         {
    39             scanf("%d %d %d",&u,&v,&x);
    40             int uu=lower_bound(sum+1,sum+k+1,u)-sum; //二分枚举所在的集合
    41             int vv=lower_bound(sum+1,sum+k+1,v)-sum;
    42             dist[uu][vv]=dist[vv][uu]=min(dist[uu][vv],x);
    43             if(x==0) Union(u,v);
    44         }
    45         flag=1;
    46         for(int i=1;i<=n;i++)
    47         {
    48             int pos=lower_bound(sum+1,sum+k+1,i)-sum;
    49             int u=find(i);
    50             if(check[pos]&&u!=check[pos]) //判断相应的集合元素是不是距离为0
    51             {
    52                 flag=0;
    53                 break;
    54             }
    55             else check[pos]=u;
    56         }
    57         if(flag)
    58         {
    59             for(int i=1;i<=k;i++) dist[i][i]=0;
    60             for(int m=1;m<=k;m++)
    61             for(int i=1;i<=k;i++)
    62             for(int j=1;j<=k;j++)
    63             dist[i][j]=min(dist[i][m]+dist[m][j],dist[i][j]);
    64             printf("Yes ");
    65             for(int i=1;i<=k;i++)
    66             {
    67                 for(int j=1;j<=k;j++)
    68                 {
    69                     if(dist[i][j]==inf) dist[i][j]=-1;
    70                     if(j==1) printf("%d",dist[i][j]);
    71                     else printf(" %d",dist[i][j]);
    72                 }
    73                 printf(" ");
    74             }
    75         }
    76         else printf("No ");
    77     }
    78     return 0;

    79 } 

  • 相关阅读:
    解决端口被占用
    Oracle查询所有表的字段明细
    Spring cron表达式
    Java爬取12306余票
    Activiti工作流框架——快速上手
    ERROR 1045 (28000): Access denied for user 'xxx'@'localhost' (using password: YES)【奇葩的bug】
    一分钟学会JavaMail(假)__手动滑稽
    通过Servlet实现汉字验证码
    使用ServletContext对象读取资源文件
    编写一个简单的java服务器程序
  • 原文地址:https://www.cnblogs.com/acvc/p/3585171.html
Copyright © 2020-2023  润新知