codeforces 238 div2 ab

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

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.

There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.

Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!

Input

The first line of input contains an integer n (1 ≤ n ≤ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 ≤ ai ≤ 100) denotes the number of cubes in the i-th column.

Output

Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.

Sample test(s)
Input
4
3 2 1 2
Output
1 2 2 3 
Input
3
2 3 8
Output
2 3 8 
Note

The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.

In the second example case the gravity switch does not change the heights of the columns.

题意十分简单:给出一数组,在问你重力向右之后的数组

Sort搞定

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,a[200],n;
    while (~scanf("%d",&n))
    {
        for (i=0; i<n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        for (i=0; i<n; i++)
        {
            if (i!=0)
              printf(" ");
            printf("%d",a[i]);
        }
        puts("");
    }
    return 0;
}

B. Domino Effect
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".

Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.

After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.

Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

Input

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to

  • "L", if the i-th domino has been pushed to the left;
  • "R", if the i-th domino has been pushed to the right;
  • ".", if the i-th domino has not been pushed.

It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

Sample test(s)
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note

The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.

In the second example case, all pieces fall down since the first piece topples all the other pieces.

In the last example case, a single piece has not been pushed in either direction.

题意:.L.R...LR..L..点表示主动倒,L表示主动向左倒,R表示主动向有倒,求最后又几个没倒的,

模拟题,分几种情况,考虑全面了就不会错了

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    int i,n;
    char str[5000];
    while (~scanf("%d",&n))
    {
        int flag1=0,flag2=0,ans1=0,sum=0,ans=0;
        scanf("%s",str+1);
        for (i=1; i<=n; i++)
        {
            if (str[i]=='R'&&flag2==0)
                 sum+=i-1;
            if (str[i]=='R'&&ans==1)
                 sum+=i-flag1-1;
            if (str[i]=='L'&&ans==-1&&(i-ans1)%2==0)
                 sum+=1;
            if (str[i]=='L')
                flag1=i,flag2++,ans=1;
            if (str[i]=='R')
                ans1=i,flag2++,ans=-1;
            if (i==n&&str[i]=='.'&&ans==1)
               sum+=i-flag1;
            if (i==n&&str[i]=='.'&&ans==0)
               sum+=i;
        }
        printf("%d\n",sum);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值