Educational Codeforces Round 7

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

Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).

Find the number on the n-th position of the sequence.

Input

The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find.

Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Output

Print the element in the n-th position of the sequence (the elements are numerated from one).

Sample test(s)
input
3
output
2
input
5
output
2
input
10
output
4
input
55
output
10
input
56
output

1

题意:给一串数字,找出规律,求第n个数是多少

解:找规律

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define LL __int64
int main()
{
    LL n;
    while(scanf("%I64d",&n)!=EOF)
    {
        LL m=floor((-1+sqrt(8*n-7))/2);
        LL x=n-m*(m+1)/2;
        printf("%I64d\n",x);
    }
    return 0;
}</span>

B. The Time
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.

Note that you should find only the time after a minutes, see the examples to clarify the problem statement.

You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock.

Input

The first line contains the current time in the format hh:mm (0 ≤ hh < 24, 0 ≤ mm < 60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).

The second line contains integer a (0 ≤ a ≤ 104) — the number of the minutes passed.

Output

The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).

See the examples to check the input/output format.

Sample test(s)
input
23:59
10
output
00:09
input
20:20
121
output
22:21
input
10:10
0
output
10:10

题意:给你当时的时间,叫你求出第a分钟后的时间是多少

水过吧

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int h,m,a;
    while(scanf("%d:%d",&h,&m)!=EOF)
    {
        scanf("%d",&a);
        int M=(a+m)%60;
        int x=(a+m)/60;
        int H=(h+x)%24;
        printf("%02d:%02d\n",H,M);
    }
    return 0;
}</span>

C. Not Equal on a Segment
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.

For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.

The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.

Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.

Output

Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value  - 1 if there is no such number.

Sample test(s)
input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
output
2
6
-1
4

题意:在给你n,m.表示有n个元素的数组,查找m个,每行有l,r,x.叫你找出区间【l,r]中,元素值不等于x的下标。

解:可以这样做,如果上一个元素和当前元素相同,表示成pre[i]=pre[i-1],不同就pre[i]=i-1;最后如果a[r]!=x输出r,否则的话就pre[r]>=l的话,就输出pre[r];如果不满足上诉情况,直接输出-1;

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=2e5+10;
int a[maxm];
int pre[maxm];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(pre,0,sizeof(pre));
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]!=a[i-1])
            {
                pre[i]=i-1;
            }
            else
            {
                pre[i]=pre[i-1];
            }
        }
        int l,r,x;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&l,&r,&x);
            int id=-1;
            if(a[r]!=x)
            {
                id=r;
            }
            else if(pre[r]>=l)
            {
                id=pre[r];
            }
            printf("%d\n",id);
        }
    }
    return 0;
}
</span>

D. Optimal Number Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.

Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum .

Input

The only line contains integer n (1 ≤ n ≤ 5·105).

Output

Print 2n integers — the permuted array a that minimizes the value of the sum s.

Sample test(s)
input
2
output
1 1 2 2
input
1
output
1 1
题意很简单。不用多说,暴力找规律就行
<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=2e5+10;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i;
        for(i=1;i<=n;i+=2)
            printf("%d ",i);
        i-=2;
        if(i==n)
            i-=2;
        for(;i>=1;i-=2)
            printf("%d ",i);
        for(i=2;i<=n;i+=2)
            printf("%d ",i);
        i-=2;
        if(i==n)
            i-=2;
        for(;i>=1;i-=2)
            printf("%d ",i);
        printf("%d\n",n);
    }
    return 0;
}</span>


你可能感兴趣的:(Educational Codeforces Round 7)