2106/04/16练习赛(四)



                             A - Easy Task ZOJ 2969

                                                                    Time Limit: 2000 MS Memory Limit: 65536 KB

   

Description

Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivation. We use x^n to denote xn. To calculate the derivation of a polynomial, you should know 3 rules:
(1) (C)'=0 where C is a constant.
(2) (Cx^n)'=C*n*x^(n-1) where n>=1 and C is a constant.
(3) (f1(x)+f2(x))'=(f1(x))'+(f2(x))'.
It is easy to prove that the derivation a polynomial is also a polynomial.

Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1000) which is the number of test cases. And it will be followed by T consecutive test cases.

There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integer N (0 <= N <= 100). The second line contains N + 1 non-negative integers, CN, CN-1, ..., C1, C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x). Ci is the coefficient of the term with degree i in f(x). (CN!=0)

Output

For each test case calculate the result polynomial g(x) also in a single line.
(1) If g(x) = 0 just output integer 0.otherwise
(2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+...+C0 (Cm!=0),then output the integers Cm,Cm-1,...C0.
(3) There is a single space between two integers but no spaces after the last integer.

Sample Input

3
0
10
2
3 2 1
3
10 0 1 2

Sample Output

0
6 2
30 0 1
题意:
就是求导数,给你们解释一下2 3 2 1这组数据,2是代表最高次幂为2,接下来有3项,3,2,1为系数。F(x)=3x^2+2x+1; 则答案为6 2.17Min1Y.
代码:
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int b[10000];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(b,0,sizeof(b));
        int a;
        cin>>a;
        int c=a;
        for(int i=0;i<=a;i++)
        {
            cin>>b[i];
            if(a!=0&&i==a&&b[i]*c==0)//注意,如果只有常数项输出0.
                break;
            if(i!=0)
            cout<<" "<<b[i]*c;
            else
                cout<<b[i]*c;
            c--;

    }
    cout<<endl;
}
}

B - Faster, Higher, Stronger ZOJ 2970

Time Limit: 2000 MS Memory Limit: 65536 KB

Description

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.

The motto of Olympic Games is "Citius, Altius, Fortius", which means "Faster, Higher, Stronger".

2106/04/16练习赛(四)_第1张图片

In this problem, there are some records in the Olympic Games. Your task is to find out which one is faster, which one is higher and which one is stronger.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case has 3 lines. The first line is the type of the records, which can only be "Faster" "Higher" or "Stronger". The second line is a positive integer N meaning the number of the records in this test case. The third line has N positive integers, i.e. the records data. All the integers in this problem are smaller than 2008.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line. If the type is "Faster", the records are time records and you should output the fastest one. If the type is "Higher", the records are length records. You should output the highest one. And if the type is "Stronger", the records are weight records. You should output the strongest one.

Sample Input

3
Faster
3
10 11 12
Higher
4
3 5 4 2
Stronger
2
200 200

Sample Output

10
5
200
题意:hight和sronger是输出数列中最大值,faster是最小值。22Min1Y.
代码:
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
int b[10000];
string x;
int main()
{
    int t,a;
    cin>>t;
    while(t--)
    {
        memset(b,0,sizeof(b));
        cin>>x;
        cin>>a;
        for(int i=0;i<a;i++)
        cin>>b[i];
        sort(b,b+a);
         if(x=="Faster")
            cout<<b[0]<<endl;

        else
            cout<<b[a-1]<<endl;
    }
}
这两道是比赛中的简单题,但是找题是花太多时间了,好歹都是1Y,没有罚时。

C - Give Me the Number ZOJ 2971

Time Limit: 2000 MS Memory Limit: 65536 KB

Description

Numbers in English are written down in the following way (only numbers less than 109 are considered). Number abc,def,ghi is written as "[abc] million [def] thousand [ghi]". Here "[xyz] " means the written down number xyz .

In the written down number the part "[abc] million" is omitted if abc = 0 , "[def] thousand" is omitted if def = 0 , and "[ghi] " is omitted if ghi = 0 . If the whole number is equal to 0 it is written down as "zero". Note that words "million" and "thousand" are singular even if the number of millions or thousands respectively is greater than one.

Numbers under one thousand are written down in the following way. The number xyz is written as "[x] hundred and [yz] ”. ( If yz = 0 it should be only “[x] hundred”. Otherwise if y = 0 it should be only “[x] hundred and [z]”.) Here "[x] hundred and" is omitted if x = 0 . Note that "hundred" is also always singular.

Numbers under 20 are written down as "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", and "nineteen" respectively. Numbers from 20 to 99 are written down in the following way. Number xy is written as "[x0] [y] ", and numbers divisible by ten are written as "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", and "ninety" respectively.

For example, number 987,654,312 is written down as "nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twelve", number 100,000,037 as "one hundred million thirty seven", number 1,000 as "one thousand". Note that "one" is never omitted for millions, thousands and hundreds.

Give you the written down words of a number, please give out the original number.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1900) which is the number of test cases. It will be followed by T consecutive test cases.

Each test case contains only one line consisting of a sequence of English words representing a number.

Output

For each line of the English words output the corresponding integer in a single line. You can assume that the integer is smaller than 109.

Sample Input

3
one
eleven
one hundred and two

Sample Output

1
11
102
题意:
就是输出描述的数字。
这道题开了很长时间,就是A不掉,烦死了。。。。。
代码:
#include<iostream>
#include<string>
#include<map>
#include<stdio.h>
using namespace std;
map<string ,int >a;
string s;

int main()
{
    a["zero"]=0;
    a["one"]=1;
    a["two"]=2;
    a["three"]=3;
    a["four"]=4;
    a["five"]=5;
    a["six"]=6;
    a["seven"]=7;
    a["eight"]=8;
    a["nine"]=9;
    a["ten"]=10;
    a["eleven"]=11;
    a["twelve"]=12;
    a["thirteen"]=13;
    a["fourteen"]=14;
    a["fifteen"]=15;
    a["sixteen"]=16;
    a["seventeen"]=17;
    a["eighteen"]=18;
    a["nineteen"]=19;
    a["twenty"]=20;
    a["thirty"]=30;
    a["forty"]=40;
    a["fifty"]=50;
    a["sixty"]=60;
    a["seventy"]=70;
    a["eighty"]=80;
    a["ninety"]=90;
    int t;
    cin>>t;
    getchar();
    while(t--)
    {
        int i;
        getline(cin,s,'\n');s=s+' ';//不得不说,队友这道题写的还真是不错,我就不会这个地方,将每个单词提取出来。
        int l=s.length();
        int b=0,num=0,sum=0;
        for(i=0; i<l; i++)
        {
            if(s[i]==' ')
            {
                string str=s.substr(b,i-b);
                b=i+1;
                if(str=="and")
                    continue;
                else if(str=="million")
                {
                    num*=1000000;
                    sum+=num;
                    num=0;
                }
                else if(str=="thousand")
                {
                    num*=1000;
                    sum+=num;
                    num=0;

                }
                else if(str=="hundred")
                {
                    num*=100;
                }
                else num+=a[str];
            }
        }
        sum+=num;
        cout<<sum<<endl;
    }
    return 0;
}

H - Light Bulbs ZOJ 2976

Time Limit: 2000 MS Memory Limit: 65536 KB

Description

Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and get married this year. He bought a new house for his family and hired a company to decorate his house. Wildleopard and his fiancee were very satisfied with the postmodern design, except the light bulbs. Varieties of light bulbs were used so that the light in the house differed a lot in different places. Now he asks you, one of his best friends, to help him find out the point of maximum illumination.

To simplify the problem, we can assume each bulb is a point light source and we only need to consider the grid points of the flat floor of the house. A grid point is a point whose coordinates are both integers. The length and the width of house can be considered infinite. Illumination means the amount of light that go through in one unit area. The illumination of a point can be calculated by simply adding the illumination from each source. The illumination from a source can be calculated by the following equation:

2106/04/16练习赛(四)_第2张图片

, where E is the illumination of the point, I is the luminous intensity of the source, R is the distance between the source and the point and i is the angle between the normal of the plane and the light to the point.

Given the position and the luminous intensity of the light bulbs, you are asked to find the maximum illumination on the floor at the grid points.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 20) which is the number of test cases. And it will be followed by T consecutive test cases.

The first line of each test case contains one integer n(1 <= n <= 100), indicating the number of bulbs of the lamps in the house. The next n lines will contain 4 integers each, Xi, Yi, Zi, Ii, separated by one space, indicating the coordinates and the luminous intensity of the i-th bulb of the lamp. The absolute values of the coordinates do not exceed 100 and Zi is always positive. Ii is a positive integer less than 32768.

Output

Results should be directed to standard output. The output of each test case should be a real number rounded to 0.01, which is the maximum illumination on the floor at the grid points.

Sample Input

3
1
0 0 1 100
4
1 0 1 100
0 1 1 100
-1 0 1 100
0 -1 1 100
4
1 0 100 10000
0 1 100 10000
-1 0 100 10000
0 -1 100 10000

Sample Output

100.00
147.43
4.00
题意:求地面上光强最强的点,光强公式在题中给出。
枚举-100,100中所有的点,利用公式。
代码:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
struct node
{
    double x,y,z,i;
}lap[105];
double Dis(double x1,double y1,double z1,double x2,double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + z1 * z1);
}

int main(){
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        double ans = 0,E = 0,R = 0,cosi = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> lap[i].x >> lap[i].y >> lap[i].z >> lap[i].i;
        }
        for (int x = -100; x < 101; x++)
        {
            for (int y = -100; y < 101; y++)
            {
                E = 0;
                for (int i = 0; i < n; i++)
                {
                    R = Dis(lap[i].x, lap[i].y ,lap[i].z, x, y);
                    cosi = lap[i].z * 1.0 / R;
                    E += lap[i].i * 1.0 / (R * R) * cosi;
                }
                ans = max(ans,E);
            }
        }
        printf("%.2f\n",ans);
    }
    return 0;
}

G - Kinds of Fuwas ZOJ 2975

Time Limit: 2000 MS Memory Limit: 65536 KB

Description

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China as well as becoming a festival for people all over the world.

The official mascots of Beijing 2008 Olympic Games are Fuwa, which are named as Beibei, Jingjing, Haunhuan, Yingying and Nini. Fuwa embodies the natural characteristics of the four most popular animals in China -- Fish, Panda, Tibetan Antelope, Swallow -- and the Olympic Flame. To popularize the official mascots of Beijing 2008 Olympic Games, some volunteers make a PC game with Fuwa.

2106/04/16练习赛(四)_第3张图片

As shown in the picture, the game has a matrix of Fuwa. The player is to find out all the rectangles whose four corners have the same kind of Fuwa. You should make a program to help the player calculate how many such rectangles exist in the Fuwa matrix.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

The first line of each test case has two integers M and N (1 <= M, N <= 250), which means the number of rows and columns of the Fuwa matrix. And then there are M lines, each has N characters, denote the matrix. The characters -- 'B' 'J' 'H' 'Y' 'N' -- each denotes one kind of Fuwa.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the number of the rectangles whose four corners have the same kind of Fuwa.

Sample Input

2
2 2
BB
BB
5 6
BJHYNB
BHBYYH
BNBYNN
JNBYNN
BHBYYH

Sample Output

1
8
题意:找出所有满足四个角相等的矩形的个数。
这道题队友出了真是没想到,第一次感受到队友爱。
代码:
#include<stdio.h>
char fu[250][251];
char wa[5]={'B','J','H','Y','N'};
int main()
{
    int i,t,x,xt,y,y1,y2,now,he;
    scanf("%d",&t);
    while(t--)
    {
        he=0;
        scanf("%d%d",&y,&x);
        for(i=0;i<y;i++)
        {
            scanf("%s",fu[i]);
        }
        for(y1=0;y1<y;y1++)
        {
            for(y2=y1+1;y2<y;y2++)
            {
                for(i=0;i<5;i++)
                {
                    now=0;
                    for(xt=0;xt<x;xt++)
                    {
                        if(wa[i]==fu[y1][xt]&&wa[i]==fu[y2][xt])now++;
                    }
                    he=he+now*(now-1)/2;
                }
            }
        }
        printf("%d\n",he);
    }
}






你可能感兴趣的:(2106/04/16练习赛(四))