首页 > 其他 > 详细

Codeforces Round #240 (Div. 2) 题解

时间:2014-04-07 22:39:04      阅读:599      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
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;
}
bubuko.com,布布扣

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

bubuko.com,布布扣
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;
}
bubuko.com,布布扣

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

bubuko.com,布布扣
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;
}
bubuko.com,布布扣

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

bubuko.com,布布扣
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;
}
bubuko.com,布布扣

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

 

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

Codeforces Round #240 (Div. 2) 题解,布布扣,bubuko.com

Codeforces Round #240 (Div. 2) 题解

原文:http://www.cnblogs.com/Felix-F/p/3650017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!