ACM:Aries's Trial(1)

During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.

Let’s describe the process more precisely. Let’s say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.

You’ve got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.

Input
The first line contains two integers n and t (1 ≤ n, t ≤ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren’s initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals “B”, otherwise the i-th character equals “G”.

Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal “B”, otherwise it must equal “G”.

Input

5 1
BGGBG

Output

AC:

#include<stdio.h>
int  main()
{
	int i = 0,j = 0,t = 0,n = 0;
	char buff[50] = {'0'};

	scanf("%d%d",&n,&t);//n为人数,t为规定时间
	scanf("%s",buff);

	for(i=0;i<t;i++)
	{
		for (j=0;j<n;)
		{
			if(buff[j]=='B')
			{
				if(buff[j+1]=='G')
				{
					buff[j]='G';
					buff[j+1]='B';
					j+=2;
				}
				else 
					j++;
			}
			else 
				j++;
		}
	}
	printf("%s\n",buff);
	return 0;
}

A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. “Piece of cake” — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.

Input
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).

Output
Print the word “YES” if the body is in equilibrium, or the word “NO” if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES

AC:

#include <stdio.h>
int main()
{
	int n = 0,x=0,y=0,z=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int xsum = 0,ysum = 0,zsum = 0;
		scanf("%d%d%d",&xsum,&ysum,&zsum);
		x+=xsum;y+=ysum;z+=zsum;
	} 
	if(x==0 && y==0 && z==0)
		printf("YES");
	else
		printf("NO");
	return 0;
}

It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.

Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.
Output
Print a single integer — the minimum year number that is strictly larger than y and all it’s digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014

AC:

#include<stdio.h>
int main()
{
	int n,i,n1,n2,n3,n4;
	
	scanf("%d",&n);
	for(i=n+1;;i++)
	{
		n1=i%10;
		n2=(i/10)%10;
		n3=(i/100)%10;
		n4=(i/1000)%10;
		if(n1!=n2 && n1!=n3 && n1!=n4 && n2!=n3 &&n2!=n4 && n3!=n4)
		{
				printf("%d\n",i);
				break;
		}
	}
	return 0;
}

The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).

The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.

Ms. Manana doesn’t want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.
Input
The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f1, f2, …, fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.
Output
Print a single integer — the least possible difference the teacher can obtain.
Examples
Input
4 6
10 12 10 7 5 22
Output
5
Note
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.

AC:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int c[55];

int main()
{
    int n = 0,m = 0,min_n=1005,i = 0;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++)
        scanf("%d",&c[i]);
    
	sort(c,c+m+1);

    for(i=n;i<=m;i++)
        if((c[i]-c[i-n+1])<min_n)
            min_n=c[i]-c[i-n+1];

    printf("%d",min_n);
    
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值