2019-2020 ACM-ICPC Brazil Subregional Programming Contest (7/13)

\(2019-2020\ ACM-ICPC\ Brazil\ Subregional\ Programming\ Contest\)

\(A.Artwork\)

Disjoint-set, the detecting area detector can be together in a disjoint-set, and then determines whether there is a set of left and top edges can be sealed in a well where one of the right and below can

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1111;
const int INF = 0x3f3f3f3f;
int n,m,k,root[MAXN],tot;
pair<pair<int,int>,int> sensor[MAXN];
vector<int> SET[MAXN];
map<int,int> mp;
int findx(int x){
    if(x!=root[x]) root[x] = findx(root[x]);
    return root[x];
}
int dist(const pair<int,int> &A, const pair<int,int> &B){
    return (A.first-B.first)*(A.first-B.first)+(A.second-B.second)*(A.second-B.second);
}
int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i = 1; i <= k; i++) scanf("%d %d %d",&sensor[i].first.first,&sensor[i].first.second,&sensor[i].second);
    for(int i = 1; i <= k; i++) root[i] = i;
    for(int i = 1; i <= k; i++) for(int j = i+1; j <= k; j++){
        int fa = findx(i);
        int fb = findx(j);
        if(fa==fb) continue;
        if((sensor[i].second+sensor[j].second)*(sensor[i].second+sensor[j].second)>=dist(sensor[i].first,sensor[j].first)){
            root[fa] = fb;
        }
    }
    for(int i = 1; i <= k; i++){
        if(!mp.count(findx(i))) mp.insert(make_pair(findx(i),++tot));
        SET[mp.at(findx(i))].emplace_back(i);
    }
    bool ok = true;
    for(int i = 1; i <= tot; i++){
        int u = -INF, d = INF, l = INF, r = -INF;
        for(auto p : SET[i]){
            u = max(u,sensor[p].first.second+sensor[p].second);
            d = min(d,sensor[p].first.second-sensor[p].second);
            l = min(l,sensor[p].first.first-sensor[p].second);
            r = max(r,sensor[p].first.first+sensor[p].second);
        }
        if((u>=m||l<=0)&&(d<=0||r>=n)){
            ok = false;
            break;
        }
    }
    puts(ok?"S":"N");
    return 0;
}

\(B.Buffoon\)

Attendance

\(C.Crossings\ With\ Danger\)

\(D.Denouncing Mafia\)

DP + tree for each node in the priority queue record its deepest position of the nodes, the chain length of the keyword throw priority queue, each time looking for the longest chain has not been traversed

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
int n,m,par[MAXN],depth[MAXN],vis[MAXN];
vector<int> G[MAXN];
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,less<pair<int,pair<int,int>>>> que;
int dfs(int u){
    depth[u] = depth[par[u]]+1;
    int maxdep = u;
    for(int v : G[u]){
        int p = dfs(v);
        maxdep = depth[maxdep]<depth[p]?p:maxdep;
    }
    que.push(make_pair(depth[maxdep]-depth[u]+1,make_pair(maxdep,u)));
    return maxdep;
}
int main(){
    scanf("%d %d",&n,&m);
    for(int i = 2; i <= n; i++){
        scanf("%d",&par[i]);
        G[par[i]].emplace_back(i);
    }
    dfs(1);
    int ans = 0;
    while(!que.empty()&&m){
        auto p = que.top();
        que.pop();
        if(vis[p.second.second]) continue;
        m--;
        ans += p.first;
        while(p.second.first!=par[p.second.second]){
            vis[p.second.first] = 1;
            p.second.first = par[p.second.first];
        }
    }
    printf("%d\n",ans);
    return 0;
}

\(E.Exhibition\ of\ Clownfish\)

\(F.Forests\ in\ Danger\)

\(G.Getting\ Confidence\)

The multiplication becomes addition to the number of KM is then matched the template

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 111;
const int INF = 0x3f3f3f3f;
int n,LX[MAXN],LY[MAXN],visx[MAXN],visy[MAXN],match[MAXN],slack[MAXN],G[MAXN][MAXN];
bool dfs(int x){
    visx[x] = 1;
    for(int y = 1; y <= n; y++){
        if(visy[y]) continue;
        int gap = LX[x] + LY[y] - G[x][y];
        if(!gap){
            visy[y] = 1;
            if(match[y]==-1||(!visx[match[y]]&&dfs(match[y]))){
                match[y] = x;
                return true;
            }
        }
        else slack[y] = min(slack[y],gap);
    }
    return false;
}
void KM_match(){
    memset(match,255,sizeof(match));
    for(int i = 1; i <= n; i++) LX[i] = *max_element(G[i]+1,G[i]+1+n);
    memset(LY,0,sizeof(LY));
    for(int i = 1; i <= n; i++){
        memset(slack,INF,sizeof(slack));
        while(true){
            memset(visx,0,sizeof(visx));
            memset(visy,0,sizeof(visy));
            if(dfs(i)) break;
            int d = INF;
            for(int j = 1; j <= n; j++) if(!visy[j]) d = min(d,slack[j]);
            for(int j = 1; j <= n; j++) if(visx[j]) LX[j]-=d;
            for(int j = 1; j <= n ;j++) if(visy[j]) LY[j]+=d;
            else slack[j]-=d;
        }
    }
    for(int i = 1; i <= n; i++) printf("%d ",match[i]);
}
int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
        scanf("%d",&G[i][j]);
        G[i][j] = log(G[i][j])*1000000;
    }
    KM_match();
    puts("");
    return 0;
}

\(H.Hour\ for\ a\ Run\)

Attendance

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int n,m;
int main(){
    ____();
    cin >> n >> m;
    for(int i = 1; i < 10; i++) cout << int(ceil((n*m*i)/10.0)) << ' '; cout << endl;
    return 0;
}

\(I.Interplanetary\)

\(J.Jar\ of\ Water\ Game\)

\(K.Keep\ Calm\ and\ Sell\ Balloons\)

\(L.Less\ Coin\ Tosses\)

The answer is \ (C (n, 0)
% 2 + C (n, 1)% 2 + ... + C (n, n-1)% 2 + C (n, n-1)% 2 \) The Lucas theorem, the answer is 2 \ (N \) bit in one of several power 1

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int_fast64_t n;
#define lowbit(x) ((x)&(-x))
int main(){
    scanf("%I64d",&n);
    int_fast64_t res = 1;
    while(n) res <<= 1,n-=lowbit(n);
    printf("%I64d\n",res);
    return 0;
}

\ (M.Maratona \ Brazilian \ a \ Popcorn \)

Half determined that the answer to

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
using LL = int_fast64_t;
int n,c,t,A[MAXN];
bool check(int mid){
    int cur = 0, tot = 1;
    for(int i = 1; i <= n; i++){
        if(mid*1ll*t<A[i]) return false;
        if(mid*1ll*t>=cur+A[i]) cur+=A[i];
        else{
            tot++;
            cur = A[i];
        }
    }
    return tot<=c;
}
int solve(){
    int l = 1, r = 1e9+7;
    while(l<=r){
        int mid = (l+r) >> 1;
        if(check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    return l;
}
int main(){
    scanf("%d %d %d",&n,&c,&t);
    for(int i = 1; i <= n; i++) scanf("%d",&A[i]);
    printf("%d\n",solve());
    return 0;
}

Guess you like

Origin www.cnblogs.com/kikokiko/p/12236510.html