XiaoHui.net 笑汇程序员论坛首页
工作并快乐着,职业并休闲着
寻梦的岁月从不言辛苦几许,
不问收获几多……
» 游客:  申请新用户 | 登录 | 会员 | 统计 | 帮助 » XiaoHui.Net 笑汇程序员论坛 | 纯文字版 | 全站索引 | XiaoHui.com


[算法讨论] ACM中的一个练习题 编程新手 谢谢

RSS 订阅当前论坛  

上一主题 下一主题
     

标题: [算法讨论] ACM中的一个练习题 编程新手 谢谢  
 
混口饭吃
小水手
Rank: 1



UID 30324
精华 0
积分 1
帖子 1
阅读权限 10
注册 2007-7-9
状态 离线
ACM中的一个练习题 编程新手 谢谢

原体如下:

招聘计划
Time Limit:5000MS  Memory Limit:65536K
Total Submit:10 Accepted:6
Description
A project manager wants to determine the number of the workers needed in every month. He does know the minimal number of the workers needed in each month. When he hires or fires a worker, there will be some extra cost. Once a worker is hired, he will get the salary even if he is not working. The manager knows the costs of hiring a worker, firing a worker, and the salary of a worker. Then the manager will confront such a problem: how many workers he will hire or fire each month in order to keep the lowest total cost of the project.一个工程部经理想确定每个月的员工的总人数。他知道每个月员工人数的最小值。当他雇用或解雇一个员工时,将有一笔额外的开销。一旦,雇用一个员工,即便他没有工作,他将得到这个月的薪水。经理知道解雇工人和雇用工人的开销,以及工人的薪水。因此,这个经理面临这样一个问题:他每个月将雇用或解雇多少员工才能使工程部的总开销最低。



Input
The input may contain several data sets. Each data set contains three lines. First line contains the months of the project planed to use which is no more than 12. The second line contains the cost of hiring a worker, the amount of the salary, the cost of firing a worker. The third line contains several numbers, which represent the minimal number of the workers needed each month. The input is terminated by line containing a single ‘0’。输入数据可以包含若干数据集。每个数据集包含3行。第一行输入这个工程计划的工期(以月为单位),不超过12个月。第二行包含雇用一个工人的开销,薪水数,和解雇一个工人的开销。第三行包括多个数据,表示每个月需要的最小的工人数。在最后一行输入0表示结束。
Output
The output contains one line. The minimal total cost of the project.结果只有一行,为这个项目的最小总开销。
Sample Input
3
4 5 6
10 9 11
0
Sample Output
199

第一次用ACM不知道注意些什么 也是刚刚接触编程 下面是我自己写的 一直不能AC
#include <iostream>
using namespace std;
int main()
{
    int n;//工程时间
    int i;
    cin>>n;
   
    if (n>12)
    {
   
    }
    else if(n<=0)
    {
   
    }
    else
    {

    int a[12];
    float kx;//最小开销
   
    float k;//当前开销
    float kx1;解雇开销
    float kx2;雇用开销
    int jgrs;//解雇用人数
    float nojg;
    float jgskx;//解雇用是开销
    int p;//工资
    cin>>kx2>>p>>kx1;

    int m;

        for(i=0;i<n;i++)
        {
        cin>>a;
        }
        cout<<"/n";
        cin>>m;
        kx=a[0]*(p+kx2);
        for(i=1;i<n;i++)
        {   
        jgrs=a-a[i-1];
        if (jgrs==0)
            k=a*p;
        if (jgrs<0)
        {
            jgskx=-jgrs*kx1+a*p;
            nojg=a[i-1]*p;
            if (nojg>jgskx)
            {
                k=jgskx;
            }
               
            else
            {
                k=nojg;
                a=a[i-1];
                    }
        }
        if (jgrs>0)
        {
            jgskx=jgrs*kx2+a*p;
            k=jgskx;
        }
        kx=kx+k;
        }
       cout<<kx<<endl;
   
   
    }
    return 0;
   
}

请高手指教下上面的程序错误在哪里,为什么不能AC呢 还有 编程方面的技巧还请赐教

[ 本帖最后由 混口饭吃 于 2007-7-10 09:54 编辑 ]
2007-7-9 14:50#1
查看资料  Blog  发短消息  顶部
 
luluwenwen
传说中的水手
Rank: 5Rank: 5



UID 176
精华 0
积分 683
帖子 683
阅读权限 1
注册 2003-6-24
来自 哈尔滨
状态 离线
以前我也写过一些ACM的程序,有时候因为输出的格式没有按指定的格式输出而出错!一般来说每个ACM的站点有最基础的程序设计,一点点做就知道他的模式了!

www.lovevc.cn
2007-7-24 17:30#2
查看资料  访问主页  Blog  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题  


 


所有时间为 GMT+8, 现在时间是 2008-12-2 05:09 Powered by Discuz! 4.1.0 清除 Cookies - XiaoHui.Net 笑汇程序员论坛 - Archiver