noip simulation [2016]

T1

[greedy]

Sort according to wait time, and then record the maximum dissatisfaction can be. -> correct complexity O (nlogn), the correctness of the unknown.

It can be considered with the full array pat violence. Data made good. Violence good writing.

5 minutes think O (n ^ 2) Methods -> no idea.

Again too small sample and large sample. Suddenly I do not want to shoot. Finished back to make another title. .

This problem is today rank1 player card ak ha ha ha. .

 【code】

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define File "transact"
inline void file(){
    freopen(File".in","r",stdin);
    freopen(File".out","w",stdout);
} 
inline int read(){
    int x = 0,f = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();}
    return x*f;
}
const int mxn = 1e5 + 5;
int n;
struct P{
    int t,d;
}p[mxn];

inline bool cmp(P t1,P t2){
    return t1.d < t2.d;
}

int main(){
    file();
    n = read();
    for(int i = 1;i <= n; ++i) p[i].t = read();
    for(int i = 1;i <= n; ++i) p[i].d = read();
    sort(p+1,p+n+1,cmp);
    ll s(0),mx(0);
    for(int i = 1;i <= n; ++i){
        s += (ll)p[i].t;
        if(s > (ll)p[i].d) mx = max(mx,s-(ll)p[i].d);
    }
    printf("%lld\n",mx);
    return 0;
}
View Code

 

 

T2

[Topology? ]

Since each person received the ball after ball to who would be fixed, and the passing distance is fixed.

Change the ball passes the relay to change the order of the longest distance, just change the first person to serve the order.

When the ball has to be passed to a person to get over the ball, the ball stopped.

O (n ^ 2) violent -> 50pts

It is contemplated that this figure is actually a tree (to have) a multi-edge, the diameter required of FIG.

But the complexity of the correctness of a fly did not practice. From each of the zero point.

A complexity unknown approach correctness correct. Build two-way side, special treatment, the diameter of the tree can run.

Then cool off after writing these two programs.

Then practice the correctness of the unknown really is garbage.

I thought actually to deal with a ring together with a number of branches.

Must enter and traverse from one zero-degree point.

The ring (a little edge) is traversed over again anyway.

Enumeration breakpoints, you can take max.

 【code】

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define File "pass"
inline void file(){
    freopen(File".in","r",stdin);
    freopen(File".out","w",stdout);
} 
inline int read(){
    int x = 0,f = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();}
    return x*f;
}
const int mxn = 5e5 + 5;
int n;
int in[mxn],cir[mxn];
ll a[mxn],d[mxn],b[mxn],f[mxn]; 

queue<int> q;
bool v[mxn];
ll tot(0),sum(0),ans(0);

int main(){
    file();
    n = read();
    for(int i = 1;i <= n; ++i){
        a[i] = read(),d[i] = read();
        in[a[i]]++;
    }
    for(int i = 1;i <= n; ++i) 
        if(!in[i]) q.push(i);
    
    while(!q.empty()){
        ll x = q.front(); q.pop();
        ll y = a[x];
        f[y] = max(f[y],f[x] + d[x]);
        if(!(--in[y]))    q.push(y);
    }
    
    for(int i = 1;i <= n; ++i){
        if(in[i] && !v[i]){
            ll k = a[i];
            
            cir[++tot] = i;
            b[a[i]] = d[i];
            sum = d[i];
            
            while(k != i){
                v[k] = 1;
                
                cir[++tot] = k;
                b[a[k]] = d[k]; 
                sum += d[k];
                
                k = a[k];                                         
            }//
            for(int j = 1;j <= tot; ++j)
                ans = max(ans,sum + f[cir[j]] - b[cir[j]]);
        }
    } 
    printf("%lld\n",years);
    return  0 ; 
} 
/ * 
5 
February 1 
March 2 
April 1st 
February 3 
March 3 
* /
View Code

 

 

T3

[dp]

Consider the most violent violence.

Selecting a grid on which to start the game O (n ^ 2)

How many go to which direction each O (4 * n)

Continue to walk after went to the current grid. .

Again O (4 * n) enumeration

A total enumeration T times.

The total complexity is O (n ^ 2 * 4 ^ T * n ^ T) -> 30pts

Such as Kazakhstan. This could there be a dp thing.

Then you can out of. .

 【code】

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define File "coin"
inline void file(){
    freopen(File".in","r",stdin);
    freopen(File".out","w",stdout);
} 
inline ll read(){
    ll x = 0,f = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();}
    return x*f;
}
const int mxn = 30;
const int mxT = 105;
const int mxW = 155;
int n,C,W,T;
int dx[5] = {-1,1,0,0,0},dy[5] = {0,0,-1,1,0}; 

inline ll min_(ll x,ll y){
    return x < y ? x : y;
}
inline ll max_(ll x,ll y){
    return x > y ? x : y;
}
inline bool ok(int x,int y){
    if(x > 0 && x <= n && y > 0 && y <= n) return true;
    return false;
}
inline int x_(int i,int x,int c){
    if(!c) return x+dx[i];
    return x+2*c*dx[i];
}
inline int y_(int i,int y,int c){
    if(!c) return y+dy[i];
    return y+2*c*dy[i];
}

ll f[mxT][mxn][mxn][mxW];
ll a[mxn][mxn];
ll ans(0);
int main(){
    file();
    n = read(),C = min_(n/2,read()),W = read(),T = read();
///*
    memset(f,0xcf,sizeof f);

    for(int i = 1;i <= n; ++i)
        for(int j = 1;j <= n; ++j)
            f[0][i][j][0] = 0;
    
    for(int t = 1;t <= T; ++t){
        for(int i = 1;i <= n; ++i)
            for(int j = 1;j <= n; ++j)
                a[i][j] = read();
        
        for(int x = 1;x <= n; ++x)
            for(int y = 1;y <= n; ++y)
                for(int s = 0;s <= W; ++s)
                    for(int i = 0;i < 5; ++i)
                        for(int c = 0;c <= min_(C,s) && ok(x_(i,x,c),y_(i,y,c)) && (i!=4||!c); ++c)
                            f[t][x][y][s] = max_(f[t][x][y][s],f[t-1][x_(i,x,c)][y_(i,y,c)][s-c] + a[x][y]);        
    }
    
    for(int i = 1;i <= n; ++i)
        for(int j = 1;j <= n; ++j)
            for(int k = 0;k <= W; ++k)    
                ans = max_(ans,f[T][i][j][k]);
    printf("%lld\n",ans);             

    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/ve-2021/p/11357083.html