zoukankan      html  css  js  c++  java
  • poj 2586

    所以,我还是太年轻,同一逻辑用Cpp写的,过了,用C写,Output Limit Exceeded。

    没过的C

    //
    //  main.c
    //  poj2586
    //
    //  Created by 韩雪滢 on 11/27/16.
    //  Copyright © 2016 韩雪滢. All rights reserved.
    //
    
    #include <stdio.h>
    
    int surplus=0;
    int deficit=0;
    int result = 0;
    
    int main() {
        
        while(scanf("%d%d",&surplus,&deficit)){
            
            int i=0;
            while(i*surplus-(5-i)*deficit < 0)
                i++;
            i--;
            
            result = 2*(i*surplus+(5-i)*deficit);
    
            if(i>=2)
                result += 2*surplus;
            else
                result = result + i*surplus - (2-i)*deficit;
            
            if(result>0)
                printf("%d
    ",result);
            else
                printf("Deficit
    ");
        }
        
        return 0;
    }

    过了的Cpp

    //
    //  main.cpp
    //  poj2586Cpp
    //
    //  Created by 韩雪滢 on 11/27/16.
    //  Copyright © 2016 韩雪滢. All rights reserved.
    //
    
    #include <iostream>
    using namespace std;
    
    int main(int argc, const char * argv[]) {
        int s,p;
        while(cin >> s >> p){
            int i=0;
            while(i*s - (5-i)*p <0)
                i++;
            i--;
            int ans = i*2*s - (5-i)*2*p;
            if(i>=2)
                ans += 2*s;
            else
                ans = ans + i*s - (2-i)*p;
            if(ans > 0)
                cout << ans <<endl;
            else
                cout << "Deficit" << endl;
        }
        return 0;
    }
  • 相关阅读:
    php-基于面向对象的MySQL类
    php-迭代创建级联目录
    php-删除非空目录
    php-递归创建级联目录
    linux 用户管理
    mysql 语法大全
    dos命令下修改mysql密码的方法
    对 linux init.d的理解
    linux 重启服务器命令
    校验软件包
  • 原文地址:https://www.cnblogs.com/HackHer/p/6107841.html
Copyright © 2011-2022 走看看