ICPC Greater New York Region 2019 题解

A

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

string s;
int main(){
    // debug;
    ios;
    cin>>s;
    if(s.substr(0,3) == "555") cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

B

C

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;
const double eps = 1e-7;

int N,P;
double dp[25],rate[25],nx_rate[25];
int sz[25];
bool G[25][25];


void sovle(int s,int e){
    for(int i = 1;i<=N;i++) dp[i] = 0,rate[i] = 0,nx_rate[i] = 0;
    double all = 0;
    rate[s] = 1;
    do{
        for(int i = 1;i<=N;i++) {
            dp[i] += 1.0/(sz[i]+1) * rate[i];
            all += 1.0/(sz[i]+1) * rate[i];
        }
        for(int i = 1;i<=N;i++) nx_rate[i] = 0;
        for(int i = 1;i<=N;i++){
            for(int j = 1;j<=N;j++){
                if(G[i][j] && i != j){
                    nx_rate[j] += rate[i] * 1.0/(sz[i] + 1);
                }
            }
        }
        swap(rate,nx_rate);
    }while(all < 1-eps);
    printf("%.5f\n",dp[e]);
}

int main(){
    // debug;
    while(cin>>N>>P){
        memset(G,false,sizeof G);
        for(int i = 1;i<=N;i++){
            int k,t;cin>>k;
            sz[i] = k;
            while(k--){
                cin>>t;
                G[i][t] = true;
                G[t][i] = true;
            }
        }
        for(int i = 1;i<=P;i++){
            int kase,s,e;cin>>kase>>s>>e;
            printf("%d ",kase);
            sovle(s,e);
        }

    }
    return 0;
}

D

E

F

G

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

ll n;
int main(){
    // debug;
    ios;
    cin>>n;
    int ans = 0;
    while(n>1){
        ans++;
        if(n&1) n = n+1;
        else n = n/2;
    }
    cout<<ans<<'\n';
    return 0;
}

H

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2e6+10;
using namespace std;

int M;
int P[maxn],tail;
bool vis[maxn];
vector<ll> res;
void initP(int N){
    for(int i = 2;i<=N;i++){
        if(!vis[i]) P[tail++] = i;
        for(int j = 0;P[j] <= N/i;j++){
            vis[P[j]*i] = true;
            if(i % P[j] == 0) break;
        }
    }
}
int main(){
    // debug;
    ios;
    initP(1<<17);
    cin>>M;
    for(int i = 1;i<=M;i++){
        ll cur;cin>>cur;
        for(int j = 0;j<tail && (ll)P[j]*P[j] <= cur;j++){
            if(cur%P[j] == 0){
                res.push_back(P[j]);
                res.push_back(cur/P[j]);
            }
        }
    }
    sort(res.begin(),res.end());
    res.erase(unique(res.begin(),res.end()),res.end());
    for(int i = 0;i<res.size();i++){
        cout<<res[i];
        if((i+1)%5 == 0) cout<<'\n';
        else if(i != res.size()-1) cout<<' ';
    }


    return 0;
}

I

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

ll p,q,n;
vector<int> ans;
map<int,char> mp;
void init(){
    for(int i = 0;i<=9;i++) mp[i] = '0'+i;
    for(int i = 0;i<26;i++) mp[i+10] = 'A'+i;
    for(int i = 0;i<26;i++) mp[i+26+10] = 'a'+i;
}
int main(){
    // debug;
    ios;
    init();
    cin>>p>>q>>n;
    while(n){
        ans.push_back(n%p);
        n /= p;
        n *= q;
    }
    reverse(ans.begin(),ans.end());
    for(auto v:ans) cout<<mp[v];


    return 0;
}

J

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int mod = 100007;
using namespace std;

int N;
int f[4040][3];
int solve(){
    f[1][0] = 1,f[1][1] = 1,f[1][2] = 1;
    for(int i = 2;i<=N-2;i++){
        f[i][0] = (f[i-1][0] + f[i-1][1]) % mod;
        f[i][1] = (f[i-1][0] + f[i-1][1] + f[i-1][2]) % mod;
        f[i][2] = (f[i-1][0] + f[i-1][1] + f[i-1][2]) % mod;
    }
    int res = 1;
    for(int i = 1;i<=N-2;i++) res = (res + f[i][0] + f[i][1] + f[i][2]) %mod;
    return (res+1)*N%mod;
}

int main(){
    // debug;
    ios;
    cin>>N;
    cout<<solve();

    return 0;
}

K

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;


int main(){
    // debug;
    ios;
    string s;getline(cin,s);
    int t = s.find('-');
    if(t == -1) {
        cout<<"NO\n";
        return 0;
    }
    string l = s.substr(0,t);
    string r = s.substr(t+1);
    if(l.size()>=2 && l.size()<=8 && r.size()>=1 && r.size()<=24) cout<<"YES"<<'\n';
    else cout<<"NO\n";

    return 0;
}
Ryuichi的算法分享 文章被收录于专栏

分享我的一些算法题解,致力于把题解做好,部分题解可能会采用视频的形式来讲解。

全部评论

相关推荐

想润的芹菜人狠话不多:把其中一个老总放中间都会得罪另一个
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务