Changle weak chicken children burst zero tour Day3

T1 cow Clothesline

【Problem Description】

    Under the wise leadership of Mother Bear, hour and his companions gave birth to many baby cow. Bear aunt decided to give every baby wear cute baby clothes. Then, wash drying of clothes for the baby cow became very uncomfortable thing.

    Sage king take this important task. After washing the clothes, you have to dry the clothes. Clothes Under natural conditions can be dried by the time point A 1 humidity. Stingy bear aunt bought a table dryer. Use dryer allows you to use the time to make a garment 1 Aside from the natural humidity dried at point A, point B, drying may humidity, but only for a time within a garment.

    N pieces of clothes for various reasons and not as wet, and now tell you the humidity of each garment, you want to find all the clothes are dry minimum time (humidity of 0 to dry).

[Input Format]

    The first row N, A, B, the next N rows, each row a number representing the humidity of clothes (1 <= humidity, A, B <= 500000,1 <= N <= 500000).

[Output format]

    Line, the minimum time.

[Sample input] Dry.in

    3 2 1

    1

    2

    3

[Output] Sample Dry.out

    1

[ Sample resolved]

    The first time, the third garment processing machines, in addition, all the clothes dried NATURAL 2. 1 Time spent all dry.

Priority Queue practice

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
priority_queue<int>q;
inline int read()
{
    int f=0;
    char ch=getchar();
    while(ch>'9' || ch<'0')
        ch=getchar();
    while(ch>='0' && ch<='9'){
        f=f*10+ch-'0';
        ch=getchar();
    }
    return f;
}
int n,a,b;
int main()
{
    freopen("Dry.in","r",stdin);
    freopen("Dry.out","w",stdout);
    n=read();a=read();b=read();
    for(int i=1;i<=n;i++){
        int x=read();
        q.push(x);
    }
    int i;
    for(i=0;;++i){
        int x=q.top();q.pop();
        if(x-a*i<=0) break;
        else if(x-b>0)q.push(x-b);
    }
    printf("%d",i);
    return 0;
}

O (n) algorithm

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read()
{
    int f=0;
    char ch=getchar();
    while(ch>'9' || ch<'0')
        ch=getchar();
    while(ch>='0' && ch<='9'){
        f=f*10+ch-'0';
        ch=getchar();
    }
    return f;
}
int n,a,b;
int cnt[500010];
int main()
{
    int mx=-1;
    n=read();a=read();b=read();
    for(int i=1;i<=n;i++){
        int x=read();
        cnt[x]++;
        mx=max(mx,x);
    }
    int t=0;
    while(t*a<mx){
        t++;
        if(mx-b>0)cnt[mx-b]++;
        cnt[mx]--;
        while(!cnt[mx])mx--;
    }
    printf("%d",t);
    return 0;
}

 

T2 decrypted text

【Problem Description】

    26 letters in English known probability of occurrence P [0], P [1] ......, P [25] (and their 1), respectively, 'a', 'b', 'c' ...... appears the probability (uppercase and lowercase letters are considered the same).

    There is now a encrypted file, encryption is the original file for each letter of the same transformation, other characters the same, methods of transformation are as follows:

    If a to z are numbered 0-25, the letter i is replaced with (i + K) MOD 26,0 <= K <26 is . The original uppercase letters, still capitalized, lowercase letters still turned out to be lowercase.

    But you do not know the value of k, so I had to enumerate. Knowing the frequency of occurrence of letters 26, so you can try to select a good k, such that the frequency of the variance and the minimum variance and is defined as follows:

    Suppose you enumerated k probability restore the original file out of the 26 letters appears as the X-[0], the X-[1], ......, the X-[25] , and then the variance is: (the p-[0] -x [0]) ^ 2 + (P [. 1] the -X-[. 1]) ^ 2 + ...... + (P [25] the -X-[25]) ^ 2 .

    If there are as good as two identical k, then choose smaller k .

    Finally, the output decrypted original file.

[Input Format]

    The first 26 rows are the probability of occurrence of 26 letters.

    Next is a case contains only 26 letters and spaces, line breaks , punctuation, digits and other text.

[Output format]

    Decrypted text.

[Sample input]

0.109375

0.000000

0.062500

0.015625

0.109375

0.015625

0.015625

0.000000

0.062500

0.015625

0.000000

0.078125

0.062500

0.062500

0.093750

0.015625

0.015625

0.031250

0.046875

0.046875

0.046875

0.000000

0.000000

0.000000

0.093750

0.000000

L DP Ol Bxtldq, ru brx fdq fdoo ph VsdfhIobhu.

L dp jodg wr vhh brx.

Hqmrb pb frqwhvw.

[Sample Output]

I am Li Yuqian, or you can call me SpaceFlyer.

I am glad to see you.

Enjoy my contest.

Analysis: The enumeration data processing bin

xjh: T2 it is not very simple

TvTvTvTvT

#include <the iostream> 
#include <cstdio> 
#include <CString> 
#include < String >
 the using  namespace STD;
 const  int MOD = 26 is ;
 String S [ 1005 ];
 Double X [ 30 ];
 Double OC [ 30 ], SUM1;
 // OC record occurrences letter string 
int TOT;
 struct Rex {
     Double P; 
} P [ 26 is ];
 struct REC {
     string S;
     int len;
    int bo[10000];//小写0 大写1 符号2 
}qaq[1005];
double sq()
{
    double w=0;
    for(int i=0;i<26;i++)
        w+=(p[i].p-x[i])*(p[i].p-x[i]);
    return w;
}
int main()
{
    //freopen("decode.in","r",stdin);
    //freopen("decode.out","w",stdout);
    for(int i=0;i<26;i++) { 
        Scanf ( " % LF \ n- " , & P [I] .p); // (-_- |||) are not
         // (-_- |||) write
         // (-_- ||| ) change
         // (-_- |||) row
         // (-_- |||) will
         // (-_- |||) burst
         // (-_- |||) zero 
    }
     the while (getline (CIN, S [++ TOT])) { 
        QAQ [TOT] .s = S [TOT];
         int len = QAQ [TOT] .LEN = S [TOT] .length ();
         for ( int I = 0 ; I <len; I ++ ) {
             IF (S [TOT] [I]> =' A ' && s [All] [i] <= ' z ' ) { 
                c [s [all] [i] - ' a ' ] ++ ; 
                qaq [all] .bo [i] = 0 ; 
            } 
            Else  if (s [all] [i]> = ' A ' && s [All] [i] <= ' Z ' ) { 
                c [s [all] [i] - ' A ' ] ++ ; 
                qaq [all] .bo [i] = 1 ; 
            } 
            Else qaq [all].;
        }    
    }
    for(int i=0;i<26;i++)
        sum1+=oc[i];
    int ak=0;
    double sq1=999999999999;
    for(int k=0;k<26;k++){
        for(int i=0;i<26;i++)
            x[i]=oc[(i+k)%26]/sum1;
        if(sq1>sq()){
            sq1=sq();
            ak=k;
        }
    }
    for(int i=1;i<tot;i++){
        int len=qaq[i].len;
        for(int j=0;j<len;j++){
            char ch=qaq[i].s[j];
            if(qaq[i].bo[j]==2) cout<<ch;
            else if(qaq[i].bo[j]==0){
                cout<<(char)((ch-'a'-ak+52)%26+'a');
            }
            else if(qaq[i].bo[j]==1){
                cout<<(char)((ch-'A'-ak+52)%26+'A');
            }
        }
        cout<<endl;
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/WJill/p/11240760.html