Codeforces Round #240 (Div. 2) 题解

A: 1分钟题,往后扫一遍

int a[MAXN];
int vis[MAXN];
int main(){
    int n,m;
    cin>>n>>m;
    MEM(vis,0);
    for(int i = 1 ; i <= m ; i++) {
        cin>>a[i];
        for(int j = a[i] ; j <= n ; j++){
            if(vis[j] == 0){
                vis[j] = a[i];
            }
        }
    }
    for(int i = 1 ; i <= n ; i++){
        cout<<vis[i]<<" ";
    }cout<<endl;
    return 0;
}

B: 给a,b,n...求x<=n 且floor(x*a/b)最大时的,x的最大值 3分钟题

int x[MAXN];
int main(){
    LL n,a,b;
    cin>>n>>a>>b;
    for(int i = 0 ; i < n ; i++){
        cin>>x[i];
        LL p = (x[i]*a)/b;
        if((p*b)%a == 0){
            cout<<x[i]-(p*b)/a<<" ";
        }else
            cout<<x[i]-(p*b)/a-1<<" ";
    }
    cout<<endl;

    return 0;
}

C: 各种特判...前两个保证是x和2x,剩下的自然gcd全是1就行了..那么显然相邻的gcd一定是1...wa了3次我太蠢了

int main(){
    int n,k;
    while(cin>>n>>k){
        int m = n/2;
        if(n == 1 && k == 0){
            cout<<"1"<<endl;
            continue;
        }
        if(m > k || n == 1 || k == 0){
            cout<<"-1"<<endl;
            continue;
        }
        int x = k-m+1;
        int y = x*2;
        cout<<x<<" "<<y<<" ";
        int cnt = 1;
        for(int i = 0 ; i < m-1 ; i++){
            while(cnt == x || cnt+1 == x || cnt == y || cnt+1 == y) cnt++;
            cout<<cnt<<" "<<cnt+1<<" ";
            cnt+=2;
        }
        while(cnt == x || cnt+1 == x || cnt == y || cnt+1 == y) cnt++;
        if(n%2 == 1) cout<<cnt<<endl;
        else cout<<endl;
    }
    return 0;
}

D: dp , dp[i][j] 表示 第i位为j的 方案数 那么类似素数筛搞一遍, 每个状态只能由i-1且为j的约数 转移过来...打一下就是O(n^2lnn) 

LL dp[2005][2005];
int main(){
    int n,k;
    while(cin>>n>>k){
        MEM(dp,0);
        for(int i = 1 ; i <= n ; i++){
            dp[1][i] = 1;
        }
        for(int i = 2 ; i <= k ; i++){
            for(int j = 1 ; j <= n ; j++){
                for(int x = j ; x <= n ; x+=j){
                    dp[i][x] = (dp[i][x] + dp[i-1][j]) % MOD;
                }
            }
        }
        LL res = 0;
        for(int i = 1 ; i <= n ; i++){
            res = (res + dp[k][i])% MOD;
        }
        cout<<res<<endl;
    }
    return 0;
}

E: 并归搞吧...还有直接暴力sort过的...CF机器真快...todo一下

 

+182...偶尔爆发一下...

posted @ 2014-04-07 13:06  Felix_F  阅读(195)  评论(0编辑  收藏  举报