Codeforces Round #364 (Div. 2)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lv414333532/article/details/52032360
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 iseven) 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 thatn is even.

The second line contains the sequence of n positive integersa1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on thei-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 to8.

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



#include <iostream>
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int A[101];
int flag[101];
int main()
{
    int n;
     while(cin>>n)
     {
         int sum=0;
         memset(flag,0,sizeof(flag));
         for(int i=0;i<n;i++)
         {
             scanf("%d",&A[i]);
             sum+=A[i];
         }
         sum/=n/2;
         for(int i=0;i<n;i++)
         {
             if(flag[i])continue;
             printf("%d",i+1);
             flag[i]=1;
             int tmp=sum-A[i];
             for(int j=i+1;j<n;j++)
             {
                 if(A[j]==tmp&&!flag[j])
                 {
                     flag[j]=1;
                     printf(" %d\n",j+1);
                     break;
                 }
             }
         }
     }
    return 0;
}

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 andm 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 arenot under attack after Vasya puts it on the board.

Input

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

Each of the next m lines contains integersxi andyi (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 firsti 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.


#include <iostream>
#include <cstdio>
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e6+10;
int H[N],L[N];
LL r,c;
int main()
{
     int n,m;
     int x,y;
     while(cin>>n>>m)
     {
         memset(H,0,sizeof(H));
         memset(L,0,sizeof(L));
          r=c=0;
         LL sum=(LL)n*n;
         for(int i=0;i<m;i++)
         {
             scanf("%d%d",&x,&y);
             if(!H[x])
             {
                 H[x]=1;
                 r++;
             }
             if(!L[y])
             {
                 L[y]=1;
                 c++;
             }
             if(i!=0)
                printf(" ");
             printf("%lld",sum-(n*(c+r)-c*r));
         }
         printf("\n");
     }
    return 0;
}

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 ofn 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 number2 and the flat number n is only connected with the flat numbern - 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 lengthn, it consists of uppercase and lowercase letters of English alphabet, thei-th letter equals the type of Pokemon, which is in the flat numberi.

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.




include <iostream>
#include <cstring>
#include <cstdio>
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e6+10;
int A[128];
char s[N];
int main()
{
    int n;
    while(cin>>n)
    {
        scanf("%s",s);
        memset(A,0,sizeof(A));
        for(int i=0;i<n;i++)
        {
            A[s[i]]++;
        }
        int cnt=0;
        for(int i='A';i<='z';i++)
        {
            if(A[i])
                cnt++;
        }
        int i=0,j=0;
        memset(A,0,sizeof(A));
        int tmp=0;
        int ans=N;
        for(i=0;i<n;i++)
        {

            while(j<n&&tmp<cnt)
            {
                if(A[s[j]]==0)
                {
                tmp++;
                }
                A[s[j]]++;
                j++;
            }

            if(tmp==cnt)
            ans=min(ans,j-i);
            else
                break;
            A[s[i]]--;
            if(A[s[i]]==0)
            {
                tmp--;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}



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


若要时间最少,是每个人坐车的时间一致所有人同时到达终点,假设为t2,步行的时间位t1, 车每次返回的时间t3=(v2-v1)*(v1+v2)

则 p为车需要接人的次数,num=p-1为车返回的次数;,想想队后一组人  得  num*(t2+t3)=t1;    t1*v1+t2*t2=l;  联立方程求解; 

On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the lengthl meters. Each of the pupils will go with the speed equal tov1. 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 thank people at the same time) and the speed equal tov2. In order to avoid seasick, each of the pupils want to get into the busno 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 n, l, v1, v2 andk (1 ≤ n ≤ 10 000,1 ≤ l ≤ 109,1 ≤ 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 exceed10 - 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 equals2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.




#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
     double L,v1,v2;
     int n,k;
     while(cin>>n>>L>>v1>>v2>>k)
     {
         int p=(n/k)-((n%k==0)?1:0);
         if(v1>=v2)
         {
             printf("%.10f\n",L*1.0/v1);
         }
         else
         {
             if(k>=n)
                printf("%.10f\n",L*1.0/v2);
             else
             {
                 double t=(double)p*((v2-v1)/(v2+v1)+1);
                 double t2=L/((double)t*v1+v2);
                 printf("%.10f\n",(t+1)*t2);
             }
         }
     }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/lv414333532/article/details/52032360