Codeforces Round #364 (Div. 2) 解题报告

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

There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.

Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.

Input

The first line of the input contains integer n (2 ≤ n ≤ 100) — the number of cards in the deck. It is guaranteed that n is even.

The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.

Output

Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.

It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.

Examples
input
6
1 5 7 4 4 3
output
1 3
6 2
4 5
input
4
10 10 10 10
output
1 2
3 4
Note

In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.

In the second sample, all values ai are equal. Thus, any distribution is acceptable.

题意:将n个数分为两个一组,一共n/2组,每组的和都相同,因为数据范围小,可以直接暴力

AC代码:

<span style="font-size:14px;"><span style="font-size:14px;">#include<stdio.h>
#include<string.h>
int main()
{
    int n,a[110],visit[110],sum=0,i,j;
    memset(visit,0,sizeof(visit));
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sum=sum/(n/2);
    for(i=1;i<=n;i++)
    {
       if(visit[i]==0)
       {
         visit[i]=1;
         for(j=i+1;j<=n;j++)
         if(visit[j]==0&&a[i]+a[j]==sum)
         {
           printf("%d %d\n",i,j);
           visit[j]=1;
		   break;
         }
       }
    }
}
</span></span>
B. Cells Not Under Attack
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.

The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.

You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 0001 ≤ m ≤ min(100 000, n2)) — the size of the board and the number of rooks.

Each of the next m lines contains integers xi and yi (1 ≤ xi, yi ≤ n) — the number of the row and the number of the column where Vasya will put the i-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.

Output

Print m integer, the i-th of them should be equal to the number of cells that are not under attack after first i rooks are put.

Examples
input
3 3
1 1
3 1
2 2
output
4 2 0 
input
5 2
1 5
5 1
output
16 9 
input
100000 1
300 400
output
9999800001 
Note

On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.

题意:有一个n*n的方格,m个棋子依次放下,棋子放下,就代表所在的那一行和那一列被占领,求每个棋子放下后还剩余多少没有被占领的方格。思路见注释。
AC代码:
<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
int visit1[100001],visit2[100001];//分别标记行和列的访问情况
int main()
{
  long long n,m,i,j,x,y,ans,a,b;
  scanf("%lld%lld",&n,&m);
  memset(visit1,0,sizeof(visit1));
  memset(visit2,0,sizeof(visit2));
  ans=n*n;
  a=0,b=0;
  //a代表列已经被占领的方格数,b代表行已经被占领的方格数。若某一行被占领,显然所有列上的方格数被占领数都会加1,即a++;b同理
  while(m--)
  {
      scanf("%lld%lld",&x,&y);//如果x行没有被占领
      if(!visit1[x])//
      {
          ans-=(n-b);//行上新被占领的数是n-b
          a++;//列上被占领数加1
          visit1[x]=1;//标记x行被占领
      }
      if(!visit2[y])//与行同理
      {
          ans-=(n-a);
          b++;
          visit2[y]=1;
      }
      printf("%lld ",ans);
  }
}</span>
C. They Are Everywhere
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.

There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.

Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.

Input

The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house.

The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.

Output

Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.

Examples
input
3
AaA
output
2
input
7
bcAAcbc
output
3
input
6
aaBCCe
output
5
Note

In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.

In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.

In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.


题意:长度为n的字符串,包含大小写字母,求最短的连续子串的长度, 使得子串中包含所有在原字符串中出现过的字母。
思路:这里用到尺取法,它的基本思想是

  1.初始化左右端点

  2.不断扩大右端点,直到满足条件

 3.如果第二步中无法满足条件,则终止,否则更新结果

 4.将左端点扩大1,然后回到第二步

AC代码:

#include<stdio.h>
#include<string.h>
int main()
{
    int n,temp=0,i,ans;char s[100010];int a[200];
    memset(a,0,sizeof(a));
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++)
    {
      a[s[i]]=1;
    }
    for(i=65;i<=122;i++)
    if(a[i]) temp++;//先找出原来字符串一共包含多少个不同的字母
	memset(a,0,sizeof(a));
    int l=0,r=0,now=1;ans=n+1;
	a[s[l]]=1;
	while(1)//尺取法
	 {
		 while(r<n-1)
		 {  
		   if(now==temp) break;
		   r++;
		   if(!a[s[r]]) {now++;} 
		   a[s[r]]++;
		  
		 }
		 if(now<temp) break;
		 if(r-l+1<ans) ans=r-l+1;
		 if((--a[s[l]])==0) now--;
		 l++;
	 } 
    printf("%d\n",ans);	
}

D. As Fast As Possible
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, which has seats fork people (it means that it can't fit more than k people at the same time) and the speed equal to v2. In order to avoid seasick, each of the pupils want to get into the bus no more than once.

Determine the minimum time required for all n pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.

Input

The first line of the input contains five positive integers nlv1v2 and k (1 ≤ n ≤ 10 0001 ≤ l ≤ 1091 ≤ v1 < v2 ≤ 109,1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.

Output

Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10 - 6.

Examples
input
5 10 1 2 5
output
5.0000000000
input
3 6 1 2 1
output
4.7142857143
Note

In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.

题意:一段长为l的路,n个人要过去,人步行的速度是v1,车一次可以接k个人,车的速度是v2,求所有人通过的最短时间。

思路:这是一道数学题,试想一下,所有人最后无论是坐车还是步行,都是同时到达,那么时间一定是最短的,也就是最后一波坐车的到达时,其余正在步行的也刚好到达,所有人花费的时间都相同,省去了等待时间,那么每个人步行和坐车的时间也一定相同。设步行时间是t1,坐车时间是t2;

                                               

AC代码:

#include<stdio.h>
int main()
{
	int n,k,num;double v1,v2,l,t2,t;
	scanf("%d%lf%lf%lf%d",&n,&l,&v1,&v2,&k);
	num=n/k+(n%k==0?0:1);
	t2=l/(v2+(num-1)*v1*(1+(v2-v1)/(v2+v1)));
	t=(l-t2*v2)/v1+t2;
	printf("%lf\n",t);
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值