The first summary of the preliminary competition of 2019 UnionPay University geek challenge

Keywords: PHP

2 questions, 98, T-shirt in hand
 
Is the real name certification late, I don't know if it will affect.
 
Upper solution
 
The king's way of yard team's girlfriend
 
Simple simulation is enough. Pay attention to the net game. It is possible to pay attention to long long in the course of the season.
 
#include<bits/stdc++.h>
#define MAX 105
using namespace std;
typedef long long ll;

string s;

int main()
{
    int t,n,m,i,j,k;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d",&n,&k,&m);
        scanf(" ");
        cin>>s;
        ll c=0,cc=0,ans=0;
        for(i=0;i<n;i++){
            if(s[i]=='1') c++;
            else{
                if(k>0) k--;
                else c--;
            }
            cc=max(cc,c);
        }
        if(c<0) printf("%lld\n",max(0ll,cc));
        else printf("%lld\n",max(0ll,c*(m-1)+cc));
    }
    return 0;
}
The king's way of yard team's girlfriend
 
Brother of the code team who taught himself graph theory
 
First find the odd number ring with dfs, then find the value of the elements in the ring by dichotomy, and finally find the value of the elements outside the ring by bfs.
 
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
typedef long long ll;

vector<int> v[MAX],vv,vvv;
map<int,map<int,int> > mp;
queue<int> q;
int a[MAX],b[MAX],bb[MAX];
int f;
void dfs(int pre,int x){
    if(f==1) return;
    for(int i=0;i<v[x].size();i++){
        int to=v[x][i];
        if(to==pre) continue;
        if(b[to]){
            vv.push_back(to);
            f=1;
            return;
        }
        b[to]=1;
        vv.push_back(to);
        dfs(x,to);
        if(f==1) return;
        vv.pop_back();
    }
}
int main()
{
    int t,n,x,y,z,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d%d",&x,&y,&z);
        v[x].push_back(y);
        v[y].push_back(x);
        mp[x][y]=z;
        mp[y][x]=z;
    }
    if(n==1){
        printf("%d\n",z);
        return 0;
    }
    f=0;
    b[1]=1;
    vv.push_back(1);
    dfs(-1,1);
    for(i=0;i<vv.size();i++){
        if(vv[i]==vv[vv.size()-1]){
            for(j=i;j<vv.size();j++){
                vvv.push_back(vv[j]);
            }
            break;
        }
    }
//    for(i=0;i<vvv.size();i++){
//        printf("%d ",vvv[i]);
//    }printf("\n");
    int l=-32768,r=32768,m;
    while(l<=r){
        m=(l+r)/2;
        int ff=0;
        a[vvv[0]]=m;
        for(i=1;i<vvv.size()-1;i++){
            a[vvv[i]]=mp[vvv[i-1]][vvv[i]]-a[vvv[i-1]];
            if(a[vvv[i]]<-32768&&(i&1)){
                ff=1;
                break;
            }
            else if(a[vvv[i]]<-32768&&(i%2==0)){
                ff=2;
                break;
            }
            else if(a[vvv[i]]>32768&&(i&1)){
                ff=2;
                break;
            }
            else if(a[vvv[i]]>32768&&(i%2==0)){
                ff=1;
                break;
            }
        }
        if(ff==1){
            r=m-1;
        }
        else if(ff==2){
            l=m+1;
        }
        else{
            int z=mp[vvv[vvv.size()-2]][vvv[vvv.size()-1]]-a[vvv[vvv.size()-2]];
            if(z<-32768){
                r=m-1;
            }
            else if(z>32768){
                l=m+1;
            }
            else if(a[vvv[0]]==z){
                break;
            }
            else if(a[vvv[0]]<z){
                l=m+1; 
            }
            else{
                r=m-1;
            }
        }
    }
    for(i=0;i<vvv.size()-1;i++){
        q.push(vvv[i]);
        bb[vvv[i]]=1;
    }
    while(q.size()){
        int p=q.front();
        for(i=0;i<v[p].size();i++){
            int to=v[p][i];
            if(bb[to]) continue;
            bb[to]=1;
            a[to]=mp[p][to]-a[p];
            q.push(to);
        }
        q.pop();
    }
    for(i=1;i<=n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}
/*
8
1 2 11
2 3 7
2 4 9
4 5 2
4 6 8
5 7 13
6 8 -1
7 8 -2
*/
Brother of the code team who taught himself graph theory

 

Folding fan dyeing (non positive solution)
 
Guess the conclusion, can only pass the example.. Positive solution seems to use state transition
 
#include<bits/stdc++.h>
#define MAX 500005
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll a[MAX];

int main()
{
    int t,i,j,k;
    a[1]=1;
    for(i=2;i<=500002;i++){
        a[i]=a[i-1]*i%MOD;
    }
    scanf("%d",&t);
    while(t--){
        ll n,m;
        scanf("%lld%lld",&n,&m);
        if(m==4) printf("%lld\n",a[m]*n%MOD);
        else if(m>4) printf("%lld\n",a[m+1]*(n-1)%MOD);
        else printf("%lld\n",a[m-1]*(n+1)%MOD);
    }
    return 0;
}
Folding fan dyeing (non positive solution)

Posted by bigfunkychief on Sun, 20 Oct 2019 15:20:34 -0700