混口饭吃
小水手

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 编辑 ]
|
|