NOIP Chicken King Competition

NOIP Chicken King Competition

Competition Time: August 23, 2018
By - Pharaoh
final test are open O2 optimization



bag vest helmet
bag.in vest.in helmet.in
bag,out vest.out helmet.out
2s 2s 2s
512MB 512MB 512MB
Ignore spaces and end of line
carriage return
Ignore spaces and end of line
carriage return
Ignore spaces and end of line
carriage return
Tradition Tradition Tradition




Problem A: three packets (bag.c / cpp / pas)

Input file: bag.in
Output file: bag.out
Time limit: 2 seconds
Memory limit: 512 megabytes


Pharaoh was the students got me to eat chicken, a landing to pick up a three-tier package, but on the ground there are many other Pharaoh
what they want to take away, M416, 5.56 bullets, vertical grip, 8-fold mirror, and so on, but apparently Pharaoh is not
to take away everything. Pharaoh rather peculiar three packages, not only the weight limit, but the number of items have
limitations. The number of each of the equipment on the ground are recorded as 1 and has its own weight, without exceeding the limit Pharaoh wanted to
take away as much as possible in the case of heavy things, in order to help the Pharaoh chicken, invite you to complete this problem .
Input
a first row of two positive numbers n, m respectively represent the number of packets three constraints and capacity constraints
second row k represents an integer number of equipment on the ground
next line k integer, the integer i

Output
Output line a total of integer representing the Pharaoh can take away the maximum weight

Example

the Sample Input1

5 100
8
8 64 17 23 91 32 17 12

Sample Output1

99

Sample Input2

5 10
3
99 99 99

Sample Output2

0

 

Notes
have a 30% data satisfies K ≤ 15 .
Another 20% of the data, meet k ≤ 20 .
Another 20% of the data, to meet the n-≤. 6 .
For 100% of the data, K ≤ 40 , n-≤ 35 , the data are not mentioned . 1 to 10 ^ 9 integer.

Decomposition 30: 2  ^ n- blast searches to
50 decomposition: 30 min pruning optimization approach just about
70 decomposition: Since n-≤. 6 , from 1 ~ n enumerate the number of selected items, and then
burst search, C [ k] [6] did not much, so there is no pressure ran (+50 cents practice)

Decomposition 100:
first half of the article prior to pretreatment, part of this article enumerate all selected set, and
kept down by set S [i] is stored inside the selected items does not exceed the number i ownership value
set. Similarly, the set half enumerate all of the selected items, and to a corresponding
set which meet the requirements of the binary search can be maximum priority value, the time complexity of
O (tlogt)

Thank Huang seniors (God Ben) source code

//
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int w[50],n,m,k;
int cnt1[1<<21],cnt2[1<<21];
ll sum1[1<<21],sum2[1<<21],ans;
vector<ll> v[50];
int lowbit(int x)
{
    return x&-x;
}
int main ()
{
     cin>>n>>m>>k; 
    for(int i=1;i<=k;i++)cin>>w[i];
    if(k==1)
    {
        if(w[1]<=m)cout<<w[1];
        else cout<<0;
        return 0;
    }
    int mid=k/2;
    int tot=(1<<mid)-1;
    for(int i=1;i<=mid;i++)sum1[1<<i-1]=w[i];//压缩1集合 
    for(int s=1;s<=tot;s++)
    {
        SUM1 [S] = sum1 [s ^ lowbit (s) ] + SUM1 [lowbit (s)]; // set (s removed lowbits bit) set to S sum1 [s ^ lowbit (s) ] bit case plus lowbit a case (lowbits bit is a) 
        CNT1 [S] = CNT1 [lowbit ^ S (S)] + . 1 ; // number-limited 
        IF (SUM1 [S] <= m && CNT1 [S] <= n-) // satisfy the condition 
        {
            years = max (years sum1 [s]);
            ;. V [cnt1 [S]] push_back (SUM1 [S]) // a consideration in the case where a selected article cnt1 
        }
    }
    for(int i=1;i<=mid;i++)sort(v[i].begin(),v[i].end());
    for(int i=1;i+mid<=k;i++)sum2[1<<i-1]=w[i+mid];//压缩2集合 
    mid=k-mid;
    tot=(1<<mid)-1;
    vector<ll>::iterator it;
    for(int s=1;s<=tot;s++)
    {
        sum2[s]=sum2[s^lowbit(s)]+sum2[lowbit(s)];
        cnt2[s]=cnt2[s^lowbit(s)]+1;
        if(cnt2[s]<=n&&sum2[s]<=m)
        {
            ANS = max (ANS, SUM2 [S]);
             for ( int J = . 1 ; J <-n-CNT2 = [S]; J ++) // and a matching set of 
            IF (! V [J] .empty ())
            {
                IT = upper_bound, (V [J] .begin (), V [J] .end (), m-SUM2 [S]); // binary search meet maximum weight value 
                IF (IT =! V [J]. begin ())
                {
                    it--;
                    ans=max(ans,(*it)+sum2[s]);
                }
            }
        }
    }
    cout << years;
    return  0 ;
}

 

Problem B: A three (vest.c / cpp / pas)

Input file: vest.in
Output file: vest.out
Time limit: 2 seconds
Memory limit: 512 megabytes

In Picado picked up a three armor of Pharaoh very excited and want to immediately test the three A's performance,
so Wang went to the open space next to the gas station Russia hop dance, who will soon be playing a row bullet,
Pharaoh hiding off after three a, the discharge was found bullet holes of varying depth, a smart amount Pharaoh thought
method of computing performance, given a K (K ≤ n-) , is calculated for all bullet hole length section k of the depth
minimum value and, of course, different k values, the performance values obtained are different, it will take a different k Pharaoh into
line calculation, in order to help Wang chicken, this problem post for you to solve.
Input
a first row of two positive numbers n, m each represents the number of bullet holes and the interrogation frequency and
a second row Total n integers, the row represents the depth of each bullet hole

Output
The output common-m rows, each row corresponding to the output of an answer to the inquiry integer

Example

Sample Input1

2 2
1 1
1

2

Sample Output1

2

1

Sample Input2

5 3
10 3 20 30 11

2

4

5

Sample Output2

37

6

3

Sample Input3

9 5
11 33 78 55 26 100 200 89 98
2

3

4

5

6

Sample Output3

429

300

204

115

89

30 decomposition: just how do
50 decomposition: the contribution of each element analysis of different interrogation interval length,
L for it to the left than to the first element of his small, r is it to the right of the first
small element than him distance, it can be found that, as a contribution to this trend, "
then each element can be pretreated l, r, O (1) can be obtained for each element of
the contribution of the interrogation interval length, then O (n ^ 2)

60 decomposition: 50 min + 10 min sent
100 decomposition: note, such as the figure above is interrogated plurality of trapezoidal, in a certain
weight and a at x, and said apparent trapezoidal and can be divided into three sections, two public
difference arithmetic sequence and a period of a constant number of columns, so the three separate sections prefixes and suffixes
like O (n) pre-treatment at each interrogation O (1) , then the final complexity of
O (n)

//
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
inline char nc()
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd()
{
    char ch=nc();
    int sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}
typedef long long ll;
ll ans1[1000005],ans2[1000005];
int n,m;
int a[1000005],l[1000005],r[1000005];
stack<int> s;
int main()
{
    n=rd(),m=rd(); 
    for(int i=1; i<=n; i++)
    {
        a [i] = rd ();
    }
    s.push(0);
    for(int i=1; i<=n; i++)
    {
        the while (! s.empty () && A [s.top ()]> a [i]) // If a [i] is smaller than the top element 
        {
            R & lt [s.top ()] = I- . 1 ; // stack rightmost not exceed A [I] 
            s.pop ();
        }
        IF (! s.empty () && A [s.top ()] == A [I]) // Laid equal judgment 
        {
            L [I] = L [s.top ()]; // left take less 
            R & lt [s.top ()] = I- . 1 ; // the right does not take 
            s.pop ();
        }
        the else L [i] = s.top () + . 1 ; // top of the stack is less than a [i], a [i ] does not exceed the top leftmost element 
        s.push (i); // number stack i 
    }
     the while (! s.empty ()) R & lt [s.top ()] = n-, s.pop (); // the stack also indicates that no elements a [i] is less than equal to the top element, the top element is minimum rightmost affect the number n- 
    int L, R & lt;
     for ( int i = . 1 ; i <= n-; i ++) // discuss the contribution of number i points 
    {
        L = IL [I] + . 1 ; // L to R interval with different situations 
        R = R & lt [I] -i + . 1 ;
         IF (L <= R)
             // IF (K <= L) = K * A + ANS [ i]; left trapezoidal
             // IF (L <K <R & lt) ANS + = L * A [i]; trapezoid is
             // IF (R & lt <= K <= R & lt + L) ANS + = (R & lt + of Lk) * A [ i]; the right trapezoidal
             // partial differential absence k 
        {
             IF (L> . 1 )
            {
                ans2[1]+=a[i];//差分ans2:a[i] 
                ans2[L]-=a[i];
            }
            ans1[L]+=1ll*L*a[i];
            ans1[R+1]-=1ll*L*a[i];
            if(R+1<=L+R-1)
            {
                ans1[R+1]+=1ll*(R+L)*a[i];
                ans1[L+R]-=1ll*(R+L)*a[i];
                ans2[R+1]-=a[i];
                ans2[L+R]+=a[i];
            }
        }
        else
        {
            if(R>1)
            {
                ans2[1]+=a[i];
                ans2[R]-=a[i];
            }
            ans1[R]+=1ll*R*a[i];
            ans1[L+1]-=1ll*R*a[i];
            if(L+1<=L+R-1)
            {
                ans1[L+1]+=1ll*(L+R)*a[i];
                ans1[L+R]-=1ll*(L+R)*a[i];
                ans2[L+1]-=a[i];
                ans2[L+R]+=a[i];
            }
        }
    }
    int x;
    for(int i=1; i<=n; i++)ans1[i]+=ans1[i-1],ans2[i]+=ans2[i-1];
    for(int i=1; i<=n; i++)ans1[i]+=ans2[i]*i;//补回 k*a[i]
    while(m--)
    {
        x = rd ();
        printf("%lld\n",ans1[x]);
    }
}

 

 

 

 



Guess you like

Origin www.cnblogs.com/CXYscxy/p/11758046.html