0923- simulation game

A

See examples guess practice

First look at the topic should be thinking for a few seconds and an array of related differential

Then take a difference sample array tried it, I guess a practice

And then himself constructed at the data, it seems that can lead the way

To beat for beat! Oh, I will not write excluded violence ah orz, but fortunately did wrong orzorzorz, but really a little nervous when evaluating

B

She did not see the problem surface, that is to take a face value of two other par value would be sufficient, thought of! EX_gcd, knocked 30 ~ 40min, too small a sample, the sample is too large too too too ... Well grip grass? ? ! The last point how's going on

Hey grip grass? ? ! ! ! ! It is to hold a number of the other three the number represented! ! !

My people stupid .JPEG

Finally, think of it, it is a backpack ah backpack, or the simplest kind of infinite backpack (knapsack problem 1 .......), f is an array of type bool and even the kind of backpack

C

emmm, lacks the idea of ​​a question

Method is too difficult to describe, to put the code in the final, in which both the upper and lower /////// expressed in writing in question did not notice the error (pretty much)

The boss was right, not right to take this question out, but due to the data segment is very clear, to mix the last 40, 50 points is easy, and I WA0 really should not (just knocked a tree It has a diameter of 20 minutes)

in conclusion

Score desirable: \ (100 + 100 + 0 = 200 \)

Actual Score: \ (100 + 100 + 0 = 200 \)

No big mistakes mentally retarded, but is not supposed to WA0

The last question put AC C Code

#include<stdio.h>
#include<bits/stdc++.h>
#define LL long long
#define maxn 50005
#define maxm 100005
#define rel(i,s,n) for(int i=(s);i<(n);i++)
#define rep(i,s,n) for(int i=(s);i<=(n);i++)
#define red(i,s,n) for(int i=(s);i>=(n);i--)
#define res(i,x) for(int i=Last[x];i;i=Next[i])
using namespace std;
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
    char ch=GC;T w=1,x=0;
    while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
    n=x*w;
}
int x,y,z;
int L,R,Mid;
int n,m,tot,Ans;
struct Phenning{int id;int val;bool MK;};
int End[maxm],Last[maxn],Next[maxm],Len[maxm],f[maxn],g[maxn];
vector<Phenning>Son[maxn];
bool cmp(Phenning a, Phenning b){
    return a.val < b.val;
}
void add(int x, int y, int z){
    tot ++;
    Next[tot] = Last[x];
    Last[x] = tot;
    End[tot] = y;
    Len[tot] = z;
}
void QwQ(int x, int fa){
    int son = 0;
    res(i,x)if(End[i]!=fa){
        son ++;
        QwQ(End[i], x);
        
        ///////////////!!!!!!!!!!!!!!!!!!!!!
        f[x]+=f[End[i]];
        ///////////////!!!!!!!!!!!!!!!!!!!!!
        
        Phenning tmp;
        tmp.MK = 0;
        tmp.id = End[i];
        tmp.val = Len[i] + g[End[i]];
        Son[x].push_back(tmp);
    }
    if(son == 0)return;
    son --;
    sort(Son[x].begin(), Son[x].end(), cmp);
    rep(i, 0, son)if(Son[x][i].val >= Mid){f[x] ++; Son[x][i].MK = 1; continue;}
    rep(i, 0, son){
        //////////////////////////
        if(Son[x][i].MK) continue;
        //////////////////////////
        Phenning tmp;
        tmp.val = Mid - Son[x][i].val;
        int pos = lower_bound(Son[x].begin()+i+1, Son[x].end(), tmp, cmp) - Son[x].begin();
        if(pos>son)continue;
        while(Son[x][pos].MK == 1 && pos < son)pos ++;
        
        ///////////////////////////
        if(Son[x][pos].MK == 1)continue;
        ///////////////////////////
        
        if(Son[x][pos].val >= tmp.val){f[x] ++; Son[x][i].MK = Son[x][pos].MK = 1;}
    }
    red(i, son, 0)if(!Son[x][i].MK){g[x] = Son[x][i].val;break;}
    
    ///////////////
    Son[x].clear();
    ///////////////
    
}
bool isok(){
    rep(i, 1, n)f[i] = g[i] = 0;
    QwQ(1, 0);
    if(f[1] >= m)return 1;
    //puts("hahhahaha");
    return 0;
}
int main(){
    read(n);read(m);
    rel(i, 1, n){
        read(x);read(y);read(z);
        R += z;
        add(x, y, z);
        add(y, x, z);
    }
    while(L <= R){
        Mid = (L + R) >> 1;
        if(isok())Ans = Mid, L = Mid + 1;
        else R = Mid - 1;
    }
    printf("%d", Ans);
    return 0;
}
//长度最小的赛道长度最大:二分 

Guess you like

Origin www.cnblogs.com/qwqq/p/11621089.html