XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg.相关的知识,希望对你有一定的参考价值。

贼惨 130/186

B Black Widow

简单题

技术分享
#include <bits/stdc++.h>
const long long mod = 1e9+7;
const double ex = 1e-10;
#define inf 0x3f3f3f3f
using namespace std;
map <int,int> M;
int a[1010];
int b[100010];
int main()
{
    int N;
    scanf("%d",&N);
    int t = 0;
    for (int i = 1; i<=N;i++){
        scanf("%d",&a[i]);
        t = max(t,a[i]);
        for (int j = 1; j*j<=a[i];j++)
            if (a[i]%j==0) {
                    b[j] = 1;
                if (a[i]/j > 100000)M[a[i]/j]++;
                else b[a[i]/j] = 1;
            }
    }
    for (int i = 2 ;i<=1000000001 ;i++)
        if ((i<=100000&&b[i]==0)||(i>100000&&M[i]==0))
        {
            printf("%d\n",i);
            return 0;
        }
    return 0;
}
View Code

C Chitauri

海盗分金,按照海盗分金的贪心策略递推的求。

技术分享
#include <bits/stdc++.h>
using namespace std;
int n,k;
int vis[3005],money[3005],last;
int main()
{
    scanf("%d%d",&n,&k);
    money[1] = k;
    last = 1;
    for (int i=2;i<=n;++i) {
            int cnt = 0;
            int gg = 0;
            for (int j = 1;j<=i-1;j++){
                if (money[j] == 0)
                    cnt++;
                if (money[j] == -1)
                    gg++;
            }
            if (2*(min(cnt,k)+gg+1) < i ) {
                money[i] = -1;
                continue;
            }
            last = i;
            int tk=k;
            if (k-((i+1)/2 - gg -1) > 0) money[i] =k-((i+1)/2 - gg -1),tk-=money[i];
            for (int j=i-1;j>=1;--j) {
                if (money[j]==-1)
                    money[j]=0;
                else if (money[j]==0) {
                    if (tk>0) {
                        money[j]=1;
                        --tk;
                    }
                } else
                    money[j]=0;
            }

        }
            for (int z=n;z>=1;--z)
            printf("%d%c",money[z],z==1?\n: );
    return 0;
}
View Code

 D Dr. Banner

简单DP

技术分享
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n;
long long dp[21][100005];
int main()
{
    scanf("%d",&n);
    dp[0][n]=1;
    for (int i=1;i<=20;++i) {
        for (int j=1;j<=n;++j)
            dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
        for (int j=1;j*2<=n;++j)
            dp[i][j]=(dp[i-1][n]-dp[i-1][2*j-1]+mod)%mod;
    }
    long long res=0;
    for (int i=0;i<=20;++i)
        res=(res+dp[i][n])%mod;
    cout<<res<<endl;
    return 0;
}
View Code

 F Fury

缩点 ,然后DAG上贪心

技术分享
#include <bits/stdc++.h>
const long long mod = 1e9+7;
const double ex = 1e-10;
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
#define inf 0x3f3f3f3f
#define maxn 310
using namespace std;
int n,m,pre[maxn],low[maxn],sccno[maxn],dfs_clock,scc_cnt;
vector<int>e[maxn];
stack<int>S;
void dfs(int st) {
    pre[st]=low[st]=(++dfs_clock);
    S.push(st);
    REP(i,0,e[st].size()) {
        int nxt=e[st][i];
        if(!pre[nxt]) {
            dfs(nxt);
            low[st]=min(low[st],low[nxt]);
        }
        else if(!sccno[nxt]) {
            low[st]=min(low[st],pre[nxt]);
        }
    }
    if(low[st]==pre[st]) {
        scc_cnt++;
        while(1) {
            int now=S.top();S.pop();
            sccno[now]=scc_cnt;
            if(now==st) break;

        }
    }
}
void Tarjan() {
    dfs_clock=scc_cnt=0;
    memset(sccno,0,sizeof(sccno));
    memset(pre,0,sizeof(pre));
    for(int i=1;i<=n;i++) if(!pre[i]) dfs(i);
}
struct edge{
    int v,f,u,vv;
    edge(){}
    edge(int _v,int _f,int u,int v):v(_v),f(_f),u(u),vv(v){}
};
vector<edge>DAG[maxn];
int col[maxn],DAG_cnt;
void gao() {
    REP(i,1,n+1) {
        int u=sccno[i];
        REP(j,0,e[i].size()) {
            int v=sccno[e[i][j]];
            if(v==u) continue;
            DAG_cnt++;
            DAG[u].push_back(edge(v,0,i,e[i][j]));
        }
    }
}
int num[maxn];
int dfs2(int rt) {
    num[rt]++;
    for(int i=0;i<DAG[rt].size();i++) {
        int nxt=DAG[rt][i].v;
        if(DAG[rt][i].f==1) continue;
        if(num[nxt]>=1) {num[nxt]++;continue;}
        dfs2(nxt);
    }
}
vector<int>SCC[maxn];
typedef pair<int,int> pii;
vector<pii>Ans;
int main()
{
    scanf("%d %d",&n,&m);
    REP(i,1,m+1) {
        int u,v;scanf("%d %d",&u,&v);
        e[u].push_back(v);
    }
    Tarjan();
    int ans=0;
    for(int i=1;i<=n;i++)
        SCC[sccno[i]].push_back(i);
    for(int i=1;i<=scc_cnt;i++){
        if(SCC[i].size()==1) continue;
        for(int j=0;j<SCC[i].size();j++){
            Ans.push_back(make_pair(SCC[i][j],SCC[i][(j+1)%SCC[i].size()]));
        }
    }
   // REP(i,0,Ans.size()) cout<<Ans[i].first<<" "<<Ans[i].second<<endl;
    for(int i=1;i<=n;i++) col[sccno[i]]++;
    for(int i=1;i<=scc_cnt;i++) if(col[i]>1) ans+=col[i];
    gao();
    for(int i=1;i<=scc_cnt;i++) {
        for(int i=1;i<=scc_cnt;i++) num[i]=0;
        dfs2(i);
        for(int j=0;j<DAG[i].size();j++) {
            if(num[DAG[i][j].v]<=1) continue;
            DAG_cnt--;
            num[DAG[i][j].v]--;
            DAG[i][j].f=1;
        }
        for(int j=0;j<DAG[i].size();j++) {
            if(DAG[i][j].f==1) continue;
            Ans.push_back(make_pair(DAG[i][j].u,DAG[i][j].vv));
        }
    }
   /* for(int i=1;i<=scc_cnt;i++) {
        printf("%d: %d\n",i,DAG[i].size());
        for(int j=0;j<DAG[i].size();j++) {
            printf("%d ",DAG[i][j].v);
        }
        puts("");
    }*/

    printf("%d %d\n",n,DAG_cnt+ans);
    REP(i,0,Ans.size()) {
        printf("%d %d\n",Ans[i].first,Ans[i].second);
    }
    return 0;
}
View Code

G Groot

签到

技术分享
#include <bits/stdc++.h>
const long long mod = 1e9+7;
const double ex = 1e-10;
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    string  s;
    cin >> s ;
    cin >> s ;
    cin >> s ;
    if (s.length() == 5) puts("Pfff");
        else
    {
        cout <<W;
        for (int i = 1; i<=s.length()-5;i++) cout <<o;
        puts("w");
    }
    return 0;
}
View Code

J 待补

以上是关于XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg.的主要内容,如果未能解决你的问题,请参考以下文章

Petrozavodsk Summer-2016. Warsaw U Contest, XVI Open Cup Onsite.

XVIII Open Cup named after E.V. Pankratiev. GP of SPb

XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship

XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Peterhof.

XV Open Cup named after E.V. Pankratiev. GP of Siberia-Swimming

XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem F. Buddy Numbers 贪心数论构造