Changle training Day7

T1 delete

topic

Description [title]

Now, I do have n digits, namely, a1, a2, a3, ..., an. I now need to delete k numbers of them. Of course, I do not want to casually deleted, I hope that after deleting k numbers, the number of remaining n-k in the largest number of different numbers.

[Input Format]

The first line of two positive integers n and k, the meaning as described in the title. The next line, there is a non-negative integer n, respectively, a1 to an.

[Output format]

The number of the maximum number of different post altogether row, an integer ans, indicate deleted k digits.

[Data] scale

For 30% of the data, n≤10, ai ≤10.

For 60% of the data, n≤100, ai ≤100.

For 80% of data, n≤10 ^ 5, ai ≤10 ^ 5.

To 100% of the data, n≤10 ^ 5, ai ≤10 ^ 9.

Resolve

The first sort, duplicates removed,

Then, then there is no then the.

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 100005;
int n, m, k, i, j, a[MAXN];
inline int get()
{
    char c;
    while (((c = getchar()) < 48 || c > 57) && c != '-');
    if (c == '-')
    {
        int res = 0;
        while ((c = getchar()) >= 48 && c <= 57)
        res = res * 10 + c - '0';
        return -res;
    }
    else{
        int res = c - '0';
        while ((c = getchar()) >= 48 && c <= 57)
        res = res * 10 + c - '0';
        return res;
    }
}
int main()
{
    //freopen("del.in", "r", stdin);
    //freopen("del.out", "w", stdout);
    cin >> n >> k;
    for(i = 1; i <= n; i ++)
        a[i] = get();
    sort(a + 1, a + 1 + n);
    m = unique(a + 1, a + 1 + n) - 1 - a;
    k -= (n - m);
    if (k <= 0) cout << m;
    else cout << m - k;
    //fclose(stdin); 
        //fclose(stdout);
}
View Code

 

 

 

 

 

T2 ants move

topic

Description [title]

There are a ruler, the length L , in the above there are N ants, ants and no two same initial position. Each ant has an initial direction (left or right), and they will crawl speed per a unit of length is.

When they encounter another ant edge or ruler, they will immediately change direction (i.e., reverse).

 

A given length of the ruler, the number of ants, and all the ants in the initial position and orientation. To ask you first T position seconds of each ant.

[Input Format]

The first line of two integers L and T .

A second line integer N , represents the number of ants.

 

Each subsequent line consists of two parts. The first part is an integer representing initial position of the ants. The second part is a letter indicating that the initial direction: D indicates right, L denotes the left. Two intermediate portions of space.

[Output format]

 

N integers, represents the final position of each ant. No need to output according to the original number of ants, as long as the incremental (non-drop) in accordance with the final order of position coordinates to output coordinates.

[Data] scale

L<=200000,N<=70000N<L,1<=T<=1000000。

Resolve

Very interesting subject, when two ants meet, will turn around, in fact, because the answers are not necessarily to the original number output, we can not deal directly encounter case,

U-turn is all that is practically without any change, then at 0:00 and turn to L points.

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
int read()
{
    int num=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        num=(num<<1)+(num<<3)+ch-'0';
        ch=getchar();
    }
    return num*w;
}
int l,t,n,a,b[70100],c;
char s;
int main()
{
    //freopen("mravi.in","r",stdin);
    //freopen("mravi.out","w",stdout);
    l=read(),t=read(),n=read();
    for(int i=1;i<=n;i++)
    {
        c=0;
        a=read(),s=getchar();
        while(c!=t)
        {
            c++;
            if(s=='D')
            {
                if(a==l)
                {
                    s='L';
                    a--;
                }
                else a++;
            }
            else
            {
                if(a==0)
                {
                    s='D';
                    a++;
                }
                else a--;
            }
        }
        b[i]=a;
    }
    sort(b+1,b+n+1);
    for(int i=1;i<=n;i++) cout<<b[i]<<" ";
    return 0;
    //fclose(stdin);
    //fclose(stdout);
}
View Code

 

 

 

 

 

T3 weights

topic

Description [title]

It has a length n of the sequence of real numbers , index from 1 start, wherein the first k real positions of P · (SiN (A · k + B) + COS (C · k + D) + 2) ,

sin and cos use radians, where P , A , B , C , D are given integer. You need to choose from two locations in this sequence (which may be identical), the numbers on the front of the location minus the number on the back of the maximum position.

If two same location is selected, the difference is zero.

[Input Format]

Row of six integers P, A, B, C, D, n- .

[Output format]

A real number line represents the maximum difference, retained six decimal.

[Data] scale

For 30% of the data, . 1 <= P, A, B, C, D <= 1000,1 <= n-<= 1000 ;

For all the data, . 1 <= P, A, B, C, D <= 1000,1 <= n-<^ = 10. 6 .

Resolve

What sin and cos that? Trigonometric functions? What is that? I do not know, but it does not matter, direct call sin () and cos () on it <cmath> library.

How to deal with it the biggest difference? Let prefix again maximum, minimum and then again suffix, the final two phases can take a maximum value subtraction.

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
int read()
{
    int num=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        num=(num<<1)+(num<<3)+ch-'0';
        ch=getchar();
    }
    return num*w;
}
int p,a,b,c,d,n;
double maxn,ans[1000001],ans1[1000001],ans2[1000001];
int main()
{
    //freopen("weight.in","r",stdin);
    //freopen("weight.out","w",stdout);
    p=read(),a=read(),b=read(),c=read(),d=read(),n=read();
    for(int i=1;i<=n;i++)
    {
        ans[i]=(double)(p*(sin(a*i+b)+cos(c*i+d)+2));
        ans1[i]=max(ans1[i-1],ans[i]);
    }
    ans2[n+1]=0x7f7f7f7f;
    for(int i=n;i>=1;i--) ans2[i]=min(ans2[i+1],ans[i]);
    for(int i=1;i<=n;i++) maxn=max(maxn,ans1[i]-ans2[i]);
    printf("%.6f",maxn);
    return 0;
    //fclose(stdin);
    //fclose(stdout);
}
View Code

 

 

 

 

 

T4 dvd in reverse order

topic

Description [title]

You n, k seek 1 ~ n number are arranged exactly k inversions pairs. Reverse order: for i, j, satisfy I <J , and p [i]> p [j ] is the number of points

[Input Format]

Row of two integers n, k

[Output format]

Output an integer representing the answer to 1,000,000,007 result modulo

[Data] scale

For 10% of the data   n <= 10

For 30% of the data   k <= 50

For 100% of the data 1 <= n, k <= 1000 and k <= n * (n- 1) / 2

Resolve

Obviously this is a DP problem, we let f [i] [j] represents the number before i, in reverse order of the number of the total number of program j.

Boundary f [i] [0] = 1, the state transition equation: f [i] [j] = f [i] [j-1] + f [i-1] [j] -f [i-1] [ji] (j> = i) (if j <i is not reduced)

The specific reasons for example try to know.

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
int read()
{
    int num=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') w=-1;
        CH = getchar (); 
    } 
    the while (CH> = ' 0 ' && CH <= ' . 9 ' ) 
    { 
        NUM = (NUM << . 1 ) + (<< NUM . 3 ) CH-, + ' 0 ' ; 
        CH = getchar () ; 
    } 
    return NUM * W; 
} 
const  int MOD = 1,000,000,007 ;
 int n-, K;
 Long  Long F [ 1010 ] [ 1010 ]; // F [i] [j] denotes the front i j is the number of reverse logarithmic scheme number
 int main()
{
    //freopen("sequence.in","r",stdin);
    //freopen("sequence.out","w",stdout);
    n=read(),k=read();
    for(int i=0;i<=n;i++) f[i][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=k;j++)
            f[i][j]=((f[i][j-1]+f[i-1][j])%mod-f[i-1][max(j-i,-1)]+mod)%mod;//f[i-1][-1]=0
    cout<<f[n][k];
    return 0;
    //fclose(stdin);
    //fclose(stdout);
}
View Code

Ants Mobile

 

Guess you like

Origin www.cnblogs.com/I-Love-You-520/p/11260677.html