PTA freshman training competition - 4

The sound of the cello is like a river. The left bank is my unforgettable memory. The right bank is my bright time to hold. The flowing in the middle is my slight sadness every year.

7-1 year of birth

The above is a wonderful post on Sina Weibo: "I was born in 1988, and only when I was 25 did I encounter four different years." That is to say, it was not until 2013 that the requirement of "four numbers are different" was met. Please fill in the sentence "I was born in year y, and I didn't meet the same number of years until I was x".

Input format:

Enter the number n of different numbers in the birth year y and target year given in one line, where y is between [1, 3000], n can be 2, or 3, or 4. Note that years with less than 4 digits should be preceded by zeros. For example, year 1 is considered as year 0001, with 2 different numbers 0 and 1.

Output format:

According to the input, output x and the year that can meet the requirements. Numbers are separated by one space, and there must be no extra space at the beginning and end of the line. The year should be output in 4 digits. Note: the so-called "n numbers are different" means that different numbers are exactly n. For example, "2013" is considered to meet the conditions of "4-digit numbers are different", but it is not considered to meet the conditions of 2-digit or 3-digit numbers are different.

Enter example 1:

1988 4

Output example 1:

25 2013

Enter example 2:

1 2

Output example 2:

0 0001
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int hanshu(int cs,int bt)
{
    int i,flag=0;
    set<int> a;
    for(i=cs; i<10000; i++)
    {
        a.clear();
        a.insert(i/1000);
        a.insert(i/100%10);
        a.insert(i/10%10);
        a.insert(i%10);
        if(*a.end()==bt)
        {
            flag=i;//cout<<i/1000<<i/100%10<<i/10%10<<i%10<<endl;
            break;
        }
    }
    return flag;
}
int main()
{
    int cs,bt,i;
    cin>>cs>>bt;
    int ns=hanshu(cs,bt)-cs;
    cout<<ns;
    printf(" %04d",hanshu(cs,bt));
    return 0;
}

7-2 like

There is a "like" function on Weibo. You can like your blog and like it. Each blog post has some labels to describe its characteristics, and the type of blog you like indirectly describes your characteristics. This question requires you to write a program to analyze the characteristics of a person by counting the records of his likes.

Input format:

Input a positive integer N (≤ 1000) in the first line, which is the number of blog posts that the user likes. Then N lines, each line gives a description of the characteristics of a blog post that it likes. The format is "K F 1 * f k", where 1 ≤ K ≤ 10, f i (i=1, * k) is the number of the feature tag. We number all the feature tags from 1 to 1000. Numbers are separated by spaces.

Output format:

Count the most frequent feature tag in all the liked blog posts, and output its number and occurrence times in one line, with a space between the numbers. If there are parallels, the output number is the largest.

Input example:

4
3 889 233 2
5 100 3 233 2 73
4 3 73 889 2
2 233 123

Output example:

233 3
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int ls,mx,N,K,F,jg[1010];
int main()
{
    cin>>N;
    while(N--)
    {
        cin>>K;
        for(int i=0; i<K; i++)
        {
            cin>>F;
            jg[F]++;
        }
    }
    for(int i=0; i<=1000; i++)
        if(jg[i]>=mx)
        {
            mx=jg[i];
            ls=i;
        }
    cout<<ls<<' '<<mx<<endl;
    return 0;
}

 

7-3 Valentine's Day

The above is a wonderful post in the circle of friends: "February 14 Valentine's day, I decided to benefit you. The second and the fourteenth, I'd like to introduce you two Let's eat Please..., both of you. Now I'll give you a list of my favorite friends. Please find out the two unlucky people who are going to treat us.

Input format:

Input the names of people who don't know how many likes are given according to the order of likes. Each person's name takes up one line, which is a non empty word with no more than 10 English letters. End with enter. An English period. Mark the end of input. This symbol is not included in the list of likes.

Output format:

Output the conclusion in one line according to the likes: if there is the second person A and the 14th person B, output "A and B are inviting you to dinner..."; if there is only A but no B, output "A is the only one for you..."; if there is no A, output "Momo... No one is for you...".

Enter example 1:

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

Output example 1:

Magi and Potaty are inviting you to dinner...

Enter example 2:

LaoLao
FatMouse
whoever
.

Output example 2:

FatMouse is the only one for you...

Enter example 3:

LaoLao
.

Output example 3:

Momo... No one is for you ...

 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int main()
{
    string s,s1,s2;
    int t=0;
    while(cin>>s)
    {
        if(s[0]=='.')
            break;
        t++;
        if(t==2)
            s1=s;
        if(t==14)
            s2=s;
    }
    if(t>=14)
        cout<<s1<<" and "<<s2<<" are inviting you to dinner...";
    if(t>=2&&t<14)
        cout<<s1<<" is the only one for you...";
    if(t<2)
        cout<<"Momo... No one is for you ...";
    return 0;
}

 

7-4 A times B

Let's see I didn't cheat you - this is A question you can complete in 10 seconds: given two integers A and B with an absolute value of no more than 100, output A times B.

Input format:

The input gives two integers A and B (− 100 ≤ A,B ≤ 100) in the first line, separated by spaces.

Output format:

The value of A multiplied by B is output in one line.

Input example:

-8 13

Output example:

-104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int A,B;
int main(){
    cin>>A>>B;
    cout<<A*B<<endl;
    return 0;
}

 

7-5 A divided by B

It's really a simple question - given two integers a and B whose absolute values are not more than 100, you are required to output the results in the format of "A/B = quotient".

Input format:

The input gives two integers A and B (− 100 ≤ A,B ≤ 100) in the first line, separated by spaces.

Output format:

Output the result in one line: if the denominator is a positive number, output "A/B = quotient"; if the denominator is a negative number, enclose the denominator in parentheses for output; if the denominator is zero, the quotient of output should be Error. The quotient of the output shall be 2 decimal places.

Enter example 1:

-1 2

Output example 1:

-1/2=-0.50

Enter example 2:

1 -3

Output example 2:

1/(-3)=-0.33

Enter example 3:

5 0

Output example 3:

5/0=Error
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int A,B;
int main()
{
    cin>>A>>B;
    if(B==0)
        cout<<A<<'/'<<B<<'='<<"Error"<<endl;
    else if(B<0)
    {
        cout<<A<<'/'<<'('<<B<<')'<<'=';
        printf("%.2f\n",A*1.0/B);
    }
    else
    {
        cout<<A<<'/'<<B<<'=';
        printf("%.2f\n",A*1.0/B);
    }
    return 0;
}

 

7-6 new world

This super simple question has no input.

You just need to output the programmer's motto "Hello World" in the first line, and the updated version of "Hello New World" in the second line.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int main(){
    cout<<"Hello World"<<endl;
    cout<<"Hello New World"<<endl;
    return 0;
}

7-7 ancient style typesetting

The ancient Chinese characters were typeset vertically from right to left. This question asks you to write the procedure, presses the archaic typesetting to a paragraph of text.

Input format:

Enter a positive integer N (< 100) in the first line, which is the number of characters in each column. The second line gives a non empty string no longer than 1000, ending with a carriage return.

Output format:

Typeset the given string in archaic format with N characters in each column (except that the last column may be less than N).

Input example:

4
This is a test case

Output example:

asa T
st ih
e tsi
 ce s
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
char s[1010],a[110][110];
int main()
{
    int n,i=0,j,k;
    scanf("%d",&n);
    getchar();
    char c;
    while(1)
    {
        c=getchar();
        if(c=='\n')
            break;
        s[i]=c;
        i++;
    }
    int t=strlen(s),l=0;
    int m=(t+n-1)/n;
    for(j=m-1; j>=0; j--)
    {
        for(k=0; k<n; k++)
        {
            if(l<t)
                a[k][j]=s[l++];
            else
                a[k][j]=' ';
        }
    }
    for(int j=0; j<n; j++)
    {
        for(int k=0; k<m; k++)
            cout<<a[j][k];
        cout<<endl;
    }
    return 0;
}

 

7-8 height difference of the best couple

Experts found that the best height difference between lovers follows a formula: (height of the woman) × 1.09 = (height of the man). If it's the same, your height difference, whether it's holding hands, hugging or kissing, is the most harmonious difference.

Next, please write a program to calculate the best height of his / her lover for any user.

Input format:

Enter the first line to give a positive integer N (≤ 10), which is the number of users to query. Then N lines, each line gives the gender and height of the user to be queried according to the format of "gender height", where "gender" is "F" for female, "M" for male; "height" is the real number between [1.0, 3.0].

Output format:

For each query, calculate the best height of the couple for the user in a row, and keep 2 decimal places.

Input example:

2
M 1.75
F 1.8

Output example:

1.61
1.96
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int N;
char ch;
double h;
int main(){
    cin>>N;
    while(N--){
        getchar();
        cin>>ch>>h;
        if(ch=='M')
            printf("%.2f\n",h/1.09);
        else
            printf("%.2f\n",h*1.09);
    }
    return 0;
}

 

7-9 divide people into groups

In social networks, we have defined an "activity" for everyone. Now we hope to divide people into two categories according to this index, namely, outgoing (high activity) and introverted (low activity). It is required that the size of the two groups should be as close as possible, and their total activity gap should be as wide as possible.

Input format:

Enter the first line to give a positive integer N (2 ≤ N ≤ 10 5). The next line gives N positive integers, which are the activity of each person, separated by spaces. The title ensures that these figures and their sum do not exceed 231.

Output format:

Output in the following format:

Outgoing #: N1
Introverted #: N2
Diff = N3

Among them, N1 is the number of extroverts; N2 is the number of introverts; N3 is the absolute value of the difference between the total activity of the two groups.

Enter example 1:

10
23 8 10 99 46 2333 46 1 666 555

Output example 1:

Outgoing #: 5
Introverted #: 5
Diff = 3611

Enter example 2:

13
110 79 218 69 3721 100 29 135 2 6 13 5188 85

Output example 2:

Outgoing #: 7
Introverted #: 6
Diff = 9359
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int N,s[100010],out,in,diff;
int main()
{
    cin>>N;
    for(int i=0; i<N; i++)
        cin>>s[i];
    sort(s,s+N);
    if(N%2==0)
    {
        out=in=N/2;
        for(int i=out; i<N; i++)
            diff+=s[i];
        for(int i=0; i<in; i++)
            diff-=s[i];
    }
    else
    {
        out=(N+1)/2;
        in=N/2;
        for(int i=out-1; i<N; i++)
            diff+=s[i];
        for(int i=0; i<in; i++)
            diff-=s[i];
    }
    printf("Outgoing #: %d\n",out);
    printf("Introverted #: %d\n",in);
    printf("Diff = %d\n",diff);
    return 0;
}

 

7-10 polynomial A divided by B

This is still A question about A/B, except that A and B are replaced by polynomials. You need to calculate the quotient Q and the remainder r of the division of two polynomials, where the order of R must be less than the order of B.

Input format:

The input is divided into two lines, each line gives A nonzero polynomial, first A, then B. The format of each line is as follows:

N e[1] c[1] ... e[N] c[N]

Where N is the number of nonzero terms of the polynomial, e[i] is the index of the ith nonzero term, and c[i] is the coefficient of the ith nonzero term. Each item is given in the order of exponential decrement to ensure that all indices are different non negative integers, all coefficients are non-zero integers, and all integers are in the range of integer type.

Output format:

The output format is the same as the input format, and the output coefficient remains one decimal place after the decimal point. The numbers in the same row shall be separated by one space, and there shall be no extra space at the beginning and end of the row. Note: the zero polynomial is a special polynomial with a corresponding output of 0.00.0. However, nonzero polynomials cannot output terms with zero coefficients (including 0.0 after rounding). In the example, the copolynomials actually have a constant term of - 1 / 27, but they are not output because they are rounded to 0.0.

Input example:

4 4 1 2 -3 1 -1 0 -1
3 2 3 1 -2 0 1

Output example:

3 2 0.3 1 0.2 0 -1.0
1 1 -3.1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
double a[100010],b2[100010],c[100010];
int b1[100010],n,fir,m,x,ct1,ct2;
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        cin>>a[x];
        if(i==0)
            fir=x;
    }
    cin>>m;
    for(int i=0; i<m; i++)
        cin>>b1[i]>>b2[i];
    for(int i=fir; i>=b1[0]; i--)
    {
        int t=i-b1[0];
        c[t]=a[i]/b2[0];
        for(int j=0; j<m; j++)
            a[t+b1[j]]-=c[t]*b2[j];
    }
    for(int i=fir; i>=0; i--)
    {
        if(fabs(c[i])>=0.05)
            ct1++;
        if(fabs(a[i])>=0.05)
            ct2++;
    }
    cout<<ct1;
    for(int i=fir; i>=0; i--)
        if(fabs(c[i])>=0.05)
            printf(" %d %.1f",i,c[i]);
    if(ct1==0)
        cout<<" 0 0.0";
    cout<<endl;
    cout<<ct2;
    for(int i=fir; i>=0; i--)
        if(fabs(a[i])>=0.05)
            printf(" %d %.1f",i,a[i]);
    if(ct2==0)
        cout<<" 0 0.0"<<endl;
    return 0;
}

 

7-11 pay close attention

There is a "silent follow" on Sina Weibo. A person who is quietly followed by a user does not appear on the user's follow-up list, but the system will push the microblog published by the person who is quietly followed to the user. Now let's be an online detective. According to someone's list of concerns and their likes to other users, we can pick out people who may be quietly followed by them.

Input format:

Input the first line to give a user's attention list, the format is as follows:

Number n user 1 user 2 User N

Where N is a positive integer of no more than 5000, each user i (i=1,..., N) is the ID of the user concerned, is a string of four digits in length consisting of numbers and English letters, and the items are separated by spaces.

After that, the user's likes are given: first, a positive integer M of no more than 10000 is given, then line M, each line gives a user ID that is liked by the user and the number of likes (no more than 1000) for the user, separated by spaces. Note: the user ID is the unique identity of a user. The topic guarantees that there are no duplicate users in the list of concerns, and there are no duplicate users in the message of likes.

Output format:

We think that the people who are praised by the user more than the average number of their likes and are not on their attention list are likely to be the people they quietly pay attention to. According to this assumption, please output the user ID alphabetically in ascending order, which may be the person it quietly follows, one ID per line. If there is no such person, output "Bing Mei You".

Enter example 1:

10 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao
8
Magi 50
Pota 30
LLao 3
Ammy 48
Dave 15
GAO3 31
Zoro 1
Cath 60

Output example 1:

Ammy
Cath
Pota

Enter example 2:

11 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao Pota
7
Magi 50
Pota 30
LLao 48
Ammy 3
Dave 15
GAO3 31
Zoro 29

Output example 2:

Bing Mei You
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
struct node
{
    string name;
    int num;
} p[100010];
map<string,int>mp;
set<string>se;
int n,sum=0;
double aver;
string s;
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>s;
        mp[s]++;
    }
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>p[i].name>>p[i].num;
        sum+=p[i].num;
    }
    aver=(double)sum/n;
    for(int i=0; i<n; i++)
    {
        if(mp[p[i].name])
            continue;
        if(p[i].num<aver)
            continue;
        se.insert(p[i].name);
    }
    if(se.size()==0)
        cout<<"Bing Mei You"<<endl;
    else
    {
        set<string>::iterator it;
        for(it=se.begin(); it!=se.end(); it++)
            cout<<*it<<endl;
    }
    return 0;
}

 

7-12 Kung Fu heirs

It depends on fate whether a martial art can be inherited and developed for a long time. Generally speaking, there is always a discount for the martial arts taught by the master to the disciples, so the more they pass on, the weaker their martial arts will be Until one generation of a certain generation suddenly appears a disciple with a very high talent (or has eaten the elixir and dug up a special secret Collection), he will suddenly enlarge the power of Kung Fu by N times - we call this kind of disciple "the one who gets the way".

Here we are going to examine the genealogy of the disciples and grandchildren of a certain ancestor: suppose that there is only one master in the Genealogy (except that there is no master in the genealogy); each master can bring a lot of disciples; and suppose that the generations are strict and orderly, that is, each generation i descendant of the martial arts of the ancestor can only worship one master in the generation i-1 descendant. We assume that the skill value of the ancestor is known to be Z, and each generation passed down will reduce r%, unless a generation of disciples get the way. Now we give the school pedigree, and ask you to calculate the total power of all those who get the Tao.

Input format:

Input three positive integers in the first line, which are: N (≤ 10.5) - the total number of the whole school (so each person is numbered from 0 to N − 1, and the grandmaster's number is 0); Z - the grandmaster's skill value (not necessarily an integer, but at least a positive number); r - the discount percentage of each generation of Kung Fu (not more than a positive number of 100). Next there are N lines. Line i (i=0,..., N − 1) describes the apprentice passed by the person with number i. The format is:

K​i​​ ID[1] ID[2] ⋯ ID[K​i​​]

Where K i is the number of apprentices, followed by the number of each apprentice, with spaces between the numbers. If K i is zero, it means that this is a person who gets the way. At this time, a number followed indicates the multiple of his martial arts being magnified.

Output format:

Output the total power of all the recipients in one line, and only keep the integral part. Make sure that the input and correct output are no more than 10 10.

Input example:

10 18.0 1.00
3 2 3 5
1 9
1 4
1 7
0 7
2 6 1
1 8
0 9
0 4
0 3

Output example:

404
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
vector<int>V[100010];
int n,m,k;
double z,r,sum,val[100010];
void dfs(int id,double w)
{
    if(val[id])
        sum+=w*val[id];
    else
    {
        for(int i=0; i<V[id].size(); i++)
            dfs(V[id][i],w*r);
    }
    return;
}
int main()
{
    cin>>n>>z>>r;
    r=(100-r)/100;
    for(int i=0; i<n; i++)
    {
        cin>>m;
        if(m==0)
            cin>>val[i];
        else
        {
            for(int j=0; j<m; j++)
            {
                cin>>k;
                V[i].push_back(k);
            }
        }
    }
    dfs(0,z);
    cout<<(int)sum<<endl;
    return 0;
}

 

7-13 very bouncy ball

In order to learn physics well, morimori, who just went to senior one, bought a ball of "very play". Although it's a very elastic ball, it's just a general elastic ball. After playing elastic ball for a while, Morison suddenly thought, if he plays hard on the ground, how far can the ball go? He's not very good. Can you help him out? Of course, in order to learn physics, we simplify the environment:

  • Suppose that Morisen is a particle, and the coordinate axis is set with Morisen as the origin, then Morisen is located at (0,0) point.
  • The mass of the ball is w/100 kg (kg), and the acceleration of gravity is 9.8 m/s Square (m/s 2).
  • The process of Morison using force to play the ball on the ground can be simplified as that the ball is thrown from (0,0) point to the first quadrant at an angle ang (0 < ang < π / 2) chosen by Morison, and the kinetic energy is assumed to be 1000 joules (J) when thrown.
  • The ball is only affected by gravity in the air. When the vertical coordinate of the ball is 0, it can be regarded as landing. When landing, it loses p% kinetic energy and bounces back.
  • The ground can be regarded as a rigid body, ignoring the shape of the ball, air resistance and friction resistance.

The formula that Morison prepared for you:

  • Kinetic energy formula: E=m × v 2 / 2
  • Newton mechanics formula: F=m × a
  • Gravity: G=m × G

Among them:

  • E - kinetic energy in joules
  • m - mass in kilogram
  • v - speed in meters per second
  • a - acceleration in meters per second square
  • g - acceleration of gravity

Input format:

The input gives two integers in one line: 1 ≤ w ≤ 1000 and 1 ≤ p ≤ 100, respectively, representing the mass of the ball magnified 100 times and the percentage p of the lost power.

Output format:

Output the farthest throwing distance in one line, with 3 decimal places reserved.

Input example:

100 90

Output example:

226.757
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
#define wc 1e-6
typedef long long ll;
using namespace std;
double w,p,v2,s;
int main()
{
    cin>>w>>p;
    v2=2*1000*100/w;
    while(v2>wc)
    {
        s+=v2/9.8;
        v2*=1-p/100;
    }
    printf("%.3f\n",s);
    return 0;
}

 

802 original articles published, 42 praised, 40000 visitors+
His message board follow

Tags: less

Posted on Thu, 13 Feb 2020 04:04:41 -0800 by mark_18