| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1211 人关注过本帖
标题:ACM(杭电)
只看楼主 加入收藏
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Elevator1008
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32352    Accepted Submission(s): 17536
Problem Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 2
3 2 3 1
0
Sample Output
17
41
分析:同前段时间的腾讯赛的那题,基本上是差不多的..电梯上升需6秒,到指定楼层停5秒,下降需4秒 求该过程共需多少时间

实现:
#include <stdio.h>

int main()
{
    int n, a[101], i, sum;
    while(scanf("%d", &n) != EOF && n > 0)
    {
        a[0] = 0, sum = 0;
        for(i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
            (a[i] > a[i - 1]) ? (sum += (a[i] - a[i - 1]) * 6 + 5) : (sum += (a[i - 1] - a[i]) * 4 + 5);
        }
        printf("%d\n", sum);
    }
    return 0;
}

为提问而来....望大家耐心帮助!
2013-05-07 02:01
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
FatMouse' Trade1009
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31474    Accepted Submission(s): 10160
Problem Description
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
Input
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
Sample Input
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
13.333
31.500
分析:贪心算法的运用...

实现:
#include <stdio.h>

int main()
{
    int i, j, n;
    double a[2000], b[2000], c[2000], sum , t, m;
    while(scanf("%lf%d", &m, &n) != EOF && (m != -1 && n != -1))
    {
        sum = 0.0;
        for(i = 0; i < n; i++)
        {
            scanf("%lf%lf", &a[i], &b[i]);
            c[i] = a[i] / b[i];
        }
        for(i = 0; i < n - 1; i++)
            for(j = 0; j < n - 1 - i; j++)
            {
                if(c[j] < c[j+1])
                {
                    t = c[j]; c[j] = c[j + 1]; c[j + 1] = t;
                    t = a[j]; a[j] = a[j + 1]; a[j + 1] = t;
                    t = b[j]; b[j] = b[j + 1]; b[j + 1] = t;
                }
            }
        for(i = 0; i < n; i++)
        {
            if(m == 0) break;
            if(m >= b[i]) {
                sum = sum + a[i];
                m = m - b[i];
            }
            else
            {
                sum = sum + m / (b[i] / a[i]);
                m = 0;
            }
        }
        printf("%.3f\n",sum);
    }
    return 0;
}

为提问而来....望大家耐心帮助!
2013-05-07 02:05
快速回复:ACM(杭电)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035730 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved