我想解决这个问题 [英] I want the solution of this problem

查看:89
本文介绍了我想解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码的串行和并行百分比

问题描述

每次项目违反SLA时,项目负责人都会询问开发人员是否找到了根本原因。典型的开发人员回应说服务器需要更多的CPU才能使代码快速运行。很多时候,尽管添加了更多的CPU,但代码无法扩展。项目负责人知道,只有代码具有并行性,代码才会随着CPU的增加而扩展。帮助项目负责人找到代码的串行和并行百分比,给定CPU数量和工作完成时间



约束

输出应高达2小数位



输入格式

第一行包含格式为[Number_of_CPUs Job_completion_time]的第一次测量。



第二行包含第二次测量格式[Number_of_CPUs Job_completion_time]



输出

串行代码百分比的百分比格式的并行代码[%_Serial_Code%_Parallel_Code]





说明

示例1



输入



1 100



4 100



输出



100.00 0.00



示例2



输入



2 100



4 50



输出



33.33 66.67


我尝试了什么:



Serial and Parallel Percentage of Code
Problem Description
Every time project violates an SLA, the project leader interrogates the developer for finding root cause. Typical developer responds by saying that the Server needs more CPU for the code to run fast. Many a times, despite adding more CPUs the code does not scale. The project leader knows that code will scale with addition of CPUs only if code has parallelism. Help Project leader find serial and parallel percentage of the code, given number of CPUs and job completion times

Constraints
Output should be upto 2 decimal places

Input Format
The first line contains 1st measurement in format [Number_of_CPUs Job_completion_time].

The second line contains 2nd measurement in format [Number_of_CPUs Job_completion_time]

Output
percentage of serial code percentage of parallel code in format [%_Serial_Code %_Parallel_Code]


Explanation
Example 1

Input

1 100

4 100

Output

100.00 0.00

Example 2

Input

2 100

4 50

Output

33.33 66.67

What I have tried:

import java.util.Arrays;
 
public class ParallelSortTest
{
    private static final int BASE_ARRAY_SIZE = 10000;
 
    // A utility function to generate and return an
    // an array of given size filled with randomly
    // generated elements.
    public static double[] generateArray(int size)
    {
        if (size <= 0 || size > Integer.MAX_VALUE)
            return null;
 
        double[] result = new double[size];
        for (int i = 0; i < size; i++)
            result[i] = Math.random();
 
        return result;
    }
 
    // Driver code to compare two sortings
    public static void main(String[] args)
    {
        for (int i = 1; i < 10000; i *= 10)
        {
            int size = BASE_ARRAY_SIZE * i;
            double[] arr1 = generateArray(size);
 
            // Creating a copy of arr1 so that we can
            // use same content for both sortings.
            double[] arr2 = Arrays.copyOf(arr1, arr1.length);
            System.out.println("Array Size: " + size);
 
            // Sorting arr1[] using serial sort
            long startTime = System.currentTimeMillis();
            Arrays.sort(arr1);
            long endTime = System.currentTimeMillis();
            System.out.println("Time take in serial: " +
                             (endTime - startTime) + "ms.");
 
            // Sorting arr2[] using serial sort
            startTime = System.currentTimeMillis();
            Arrays.parallelSort(arr2);
            endTime = System.currentTimeMillis();
            System.out.println("Time take in parallel: "
                            + (endTime - startTime) + "ms.");
            System.out.println();
        }
    }
}

推荐答案

我们不做你的作业:它是为一个原因。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这看起来像是一个挑战,在这种挑战中,目标是测试你的技能。所以你的答案就是你无法解决问题。



在这类问题中,就像做作业一样,第一步是找到逻辑,数学。

所以拿一张纸和一支铅笔手工解样。当你得到它,开始编写程序。




我们不做你的HomeWork。

HomeWork未设置为在乞求其他人做你的工作时测试你的技能,它会让你思考并帮助你的老师检查你对你所学课程的理解以及你应用它们时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。



作为程序员,您的工作是创建算法解决特定问题,你不能依赖别人永远为你做,所以有一段时间你必须学会​​如何。而且越快越好。

当你要求解决方案时,就像试图通过培训其他人来学习开车一样。

创建算法基本上是找到数学并做出必要的调整以适应你的实际问题。



[更新]

你问题中的代码不均匀与声明远程相关。

This look like a challenge, in this kind of challenges, the goal is to test your skills. So your answer is that you are unable to solve the problem.

In this kind of problem, just like with homework, the first step is to find the logic, the mathematics.
So take a sheet of paper and a pencil and solve the samples by hand. When you got it, start writing the program.


We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

[Update]
The code in your question is not even remotely related to the statement.
引用:

任何人都可以解释输出是怎么来的?

can anyone explain how output comes??



这是比赛的核心,他们想知道你是否可以锻炼数学。因此,如果我们只是给你答案就是表格。

问题解决的原则是:

第一步:拿一张纸和一支铅笔

第二步:手动解决问题,找到数学或算法

第三步:你的程序自动化你找到的解决方案。


That is the core of the contest, they want to know if you can workout the math. So if we just give you the answer it is sheeting.
The principle of problem solving is :
First step: take a sheet of paper and a pencil
Second step: solve the problem by hand, find the maths or algorithm
Third step: your program is automating the solution you found.


这篇关于我想解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆