zoukankan      html  css  js  c++  java
  • 寒假刷题之1——以生态为名义的剥削

      取这个名字just for fun,绝不是有反政府的意思哦。。。


      原题为:

    Problem A

    Ecological Premium

    Input: standard input

    Output: standard output

    Time Limit: 1 second

    Memory Limit: 32 MB

    German farmers are given a premium depending on the conditions at their farmyard. Imagine the following simplified regulation: you know the size of each farmer's farmyard in square meters and the number of animals living at it. We won't make a difference between different animals, although this is far from reality. Moreover you have information about the degree the farmer uses environment-friendly equipment and practices, expressed in a single integer greater than zero. The amount of money a farmer receives can be calculated from these parameters as follows. First you need the space a single animal occupies at an average. This value (in square meters) is then multiplied by the parameter that stands for the farmer's environment-friendliness, resulting in the premium a farmer is paid per animal he owns. To compute the final premium of a farmer just multiply this premium per animal with the number of animals the farmer owns.

    Input

    The first line of input contains a single positive integer n (<20), the number of test cases. Each test case starts with a line containing a single integer f (0<f<20), the number of farmers in the test case. This line is followed by one line per farmer containing three positive integers each: the size of the farmyard in square meters, the number of animals he owns and the integer value that expresses the farmer’s environment-friendliness. Input is terminated by end of file. No integer in the input is greater than 100000 or less than 0.

     

    Output

    For each test case output one line containing a single integer that holds the summed burden for Germany's budget, which will always be a whole number. Do not output any blank lines.

     

    Sample Input

    3
    5
    1 1 1
    2 2 2
    3 3 3
    2 3 4
    8 9 2
    3
    9 1 8
    6 12 1
    8 1 1
    3
    10 30 40
    9 8 5
    100 1000 70

    Sample Output

    38

    86

    7445


      题目实在太长而且都是英语,看得我很蛋疼,我觉得我写程序的时间可能会比不上去看那些英语的时间。。。看来英语很重要啊。。。

       我研究了老半天,题目大概讲放牛放羊的收费问题:

    前面一段内容为:每个动物占据的平均空间(平方米)乘以环境友好型参数等于农民为每只动物交的钱

    input内容为:输入n个农民,然后每个农民分别有f块地,输入f组3个数字,分别代表总面积,牛的个数,友好型参数

    最后输出要交的总费用。。。


       这不是一场以生态为名义的剥削嘛。

       那么就求出每个动物占据的平均空间(平方米)就可以了。。

       然后我发现了发现了一个东西,那就是牛的数量完全不需要用到!

       太坑爹了这题目。。。以前好像也做过这种题目,看来杭州oj很喜欢这种题目。。。

       我觉得我花那么多时间真像个白痴。。。


       ok,开始撸代码了。。。


    #include<stdio.h>
    
    
    int main()
    {
    	long int i, j, sum[20] = {0}, n, f, a, b, c;
    	scanf("%ld", &n);
    	
    	for (i = 0; i < n; i ++){
    		scanf("%ld", &f);
    		for (j = 0; j < f; j ++){
    			scanf("%ld%ld%ld", &a, &b, &c);
    			sum[i] += a * c;
    		}
    	}
    	
    	for (i = 0; i < n; i ++)
    		printf("%ld\n", sum[i]);
    	
    	return 0;
    }


       很快就出来了,调试也正常,accepted了,很好很好。

       其实我是习惯性的用long int型,如果实际上的话用int应该就可以了,而且我想应该不需要那么多变量,for用while代替应该可以省略i,j两个变量,尝试了一下发现后面输出部分的循环就无法实现了,而且考虑到sum[i]这个数组也需要用到i变量,所以最多也就省掉j变量,果然我还是太弱。。。

        不过这次这题是头几题比较容易,后面估计会难点。


    PS:发布后发现排版果然出问题,蛋疼啊,我那规范的排版都抽了,不知道要怎么解决,先这样放着吧。。。(已经用样式解决了)

  • 相关阅读:
    关于uoloadify不能显示效果原因(thinkphp5仿百度糯米)
    thinkphp3.2.3中$this->assign
    PDO
    类的声明 只能有属性和方法(属性没有括号,方法有括号)
    怎删改查
    JS鼠标事件大全
    建表以及 增。删。改。查
    建表、添加数据及数据查询
    html框架
    表的求和及计算
  • 原文地址:https://www.cnblogs.com/java20130723/p/3212220.html
Copyright © 2011-2022 走看看