012: determining the number of parity
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
Given an integer, it is determined that the number is odd or even.
-
Entry
Only one line input, a positive integer n greater than zero.
-
Export
Only the output line, if n is odd, ODD output; if n is an even number, the output even.
-
Sample input
5
-
Sample Output
odd
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n =0;
scanf("%d",&n);
if(n%2!=0)
{
printf("odd");
}
else
{
printf("even");
}
return 0;
}
013: seeking one yuan quadratic equation roots
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
Using the formula = X1 (-b + sqrt (B B. 4- A C)) / (2 A), X2 = (-b - sqrt (B B. 4- A C)) / (2 A) find a quadratic equation ax2 + bx + c = 0 is the root, wherein a is not equal to 0.
-
Entry
Input line, comprising three floating point numbers a, b, c (separated by a space between them), respectively equation ax2 + bx + c = 0 coefficients.
-
Export
Output a line indicating solution of the equation. If b2 = 4 * a * c, the two real roots are equal, the output form: x1 = x2 = .... If b2> 4 * a * c, two real roots is not equal, the output form: x1 = ...; x2 = ... , where x1> x2. If b2 <4 * a * c, there are two imaginary roots, output: x1 = the real portion of the imaginary part + i; x2 = the real part - imaginary part i, i.e., the imaginary part of the coefficient is greater than the imaginary coefficients x1 and x2 is equal to , 0 when the real part can not be omitted. -B real part = / (2 A), sqrt imaginary part = (. 4 A C B- B) / (2 * A) All real part requires accurate to five decimal places, there is no space between the numbers, symbols.
-
Sample input
样例输入1 1.0 2.0 8.0 样例输入2 1 0 1
-
Sample Output
样例输出1 x1=-1.00000+2.64575i;x2=-1.00000-2.64575i 样例输出2 x1=0.00000+1.00000i;x2=0.00000-1.00000i
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double a,b,c;
scanf("%lf %lf %lf",&a,&b,&c);
double x1 = (-b + sqrt(b*b-4*a*c))/(2*a);
double x2 = (-b - sqrt(b*b-4*a*c))/(2*a);
if(b*b==4*a*c)
printf("x1=x2=%.5lf",x1);
else if(b*b>4*a*c)
{
if(x1 > x2)
printf("x1=%.5lf;x2=%.5lf",x1,x2);
else
printf("x1=%.5lf;x2=%.5lf",x2,x1);
}
else
{
double a1 = -b / (2*a);
double a2 = sqrt(4*a*c-b*b) / (2*a);
if(b == 0)
{
a1 = 0;
}
printf("x1=%.5lf+%.5lfi;x2=%.5lf-%.5lfi",a1,a2,a1,a2);
}
return 0;
}
014: the relationship between point and square
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
There is a square, the four corners of the coordinates (X, y) are (1, -1), (1,1), (- 1, -1), (- 1,1), x is the horizontal axis, y It is the vertical axis. Writing a program, it is determined whether a given point within the square (including a square boundary).
-
Entry
Input line, comprising two integers x, y, separated with a space, a graph (x, y).
-
Export
Output line, if the point in the square, the output yes, otherwise output no.
-
Sample input
1 1
-
Sample Output
yes
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int a=0,b=0;
scanf("%d %d",&a,&b);
if(a>=-1&&a<=1&&b>=-1&&b<=1)
{
printf("yes");
}
else
{
printf("no");
}
return 0;
}
015: 2 apples and worms
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
N You bought a box of apples, unfortunately, is buying the box got into a worm. X insects every hour to eat an apple, assuming an apple before eating insects will not eat another, then after y number of hours you have complete apple?
-
Entry
Only the input line, including n, x and y (are integers).
-
Export
Output is only one line, the remaining number of apples
-
Sample input
10 4 9
-
Sample Output
7
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n= 0,x=0,y=0;
scanf("%d %d %d",&n,&x,&y);
int m = (y/x);
if(y%x!=0)
{
m = m + 1;
}
int result = n - m ;
if(n - m < 0)
{
result = 0;
}
printf("%d",result);
return 0;
}
016: Simple Calculator
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
One of the most simple calculator, supports +, -, *, / four operations. Consider only the input and output is an integer, and the calculation result data does not exceed the range of an int.
-
Entry
Only one line input, a total of three parameters, wherein the first and second parameter is an integer, the third parameter to the operator (+, -, *, /).
-
Export
Output only one line, an integer, for the calculation result. However: 1. If the divisor 0 occurs, output: Divided by zero 2. If the operator appears invalid (i.e., not +, -, *, /), one output:! Invalid operator!
-
Sample input
1 2 +
-
Sample Output
3
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int a=0,b=0;
char c = 0;
scanf("%d %d %c",&a,&b,&c);
if(c != '+' && c != '-' && c != '*' && c != '/')
{
printf("Invalid operator!");
}
else if(b == 0)
{
printf("Divided by zero!");
}
else
{
if(c == '+')
{
printf("%d",a+b);
}
else if(c == '-')
{
printf("%d",a-b);
}
else if(c == '*')
{
printf("%d",a*b);
}
else
{
printf("%d",a/b);
}
}
return 0;
}
017: Find the mean and integer
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
Reading n (1 <= n <= 10000) integers, and a mean value thereof seeking.
-
Entry
The first input line is an integer n, there are n represents an integer. Of 2 ~ n + 1 lines contains an integer. Each of the absolute value of an integer of not more than 10,000.
-
Export
Output line, and the first output, and then outputs the average value (reserved to 5 decimal places), separated by a single space between the two numbers.
-
Sample input
4 344 222 343 222
-
Sample Output
1131 282.75000
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n = 0;
int summ = 0;
scanf("%d",&n);
double ave = 0;
for(int i = 0;i<n;i++)
{
int tmp = 0;
scanf("%d",&tmp);
summ += tmp;
}
ave = double(summ)/ double(n);
printf("%d %.5lf",summ,ave);
return 0;
}
018: the maximum element of the sequence of integers span value
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
Given a non-negative integer sequences of length n, calculate the maximum span of the sequence (maximum value = maximum value minus the minimum span).
-
Entry
A total of two rows, the first row sequence number n (1 <= n <= 1000), the behavior of the second sequence of n less than 1000 non-negative integer, with a space between integers.
-
Export
Output line, the span represents the maximum value of the sequence.
-
Sample input
6 3 0 8 7 5 9
-
Sample Output
9
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n = 0;
int minn = 1001;
int maxx = -1;
scanf("%d",&n);
for(int i = 0;i<n;i++)
{
int tmp;
scanf("%d",&tmp);
if(maxx<tmp)
{
maxx = tmp;
}
if (minn>tmp)
{
minn = tmp;
}
}
printf("%d",maxx-minn);
return 0;
}
019: Olympic medal count
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
2008 Beijing Olympic Games, the athletes participated n A national day of finals (1≤n≤17). Now statistics about the number of gold, silver, bronze and total medals A number of countries obtained.
-
Entry
Enter row n + 1, Line 1 A country is involved in the final project the number of days n, followed by n lines, each line is the number of gold, silver and bronze medals obtained in the country one day, separated by a space.
-
Export
An output line, comprising four integer gold country A is obtained, silver, bronze, and the total number of the total number of medals, separated by a space.
-
Sample input
3 1 0 3 3 1 0 0 3 0
-
Sample Output
4 4 3 11
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n = 0;
int gold=0,silver=0,bronze = 0;
scanf("%d",&n);
for(int i = 0;i<n;i++)
{
int g1 = 0,s1= 0,b1 = 0;
scanf("%d %d %d",&g1,&s1,&b1);
gold += g1;
silver += s1;
bronze += b1;
}
printf("%d %d %d %d",gold,silver,bronze,gold + silver + bronze);
return 0;
}
020: computing power
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
It gives a positive integer a and an integer n, seeking power an.
-
Entry
Line, comprising two integers a and n. -1000000 <= a <= 1000000,1 <= n <= 10000.
-
Export
An integer that is the result of power. Topic ensure that the final result of the absolute value of not more than 1,000,000.
-
Sample input
2 3
-
Sample Output
8
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int a = 0,n = 0;
scanf("%d %d",&a,&n);
int i = 1;
int m = a;
while(i != n)
{
a = a*m;
i++;
}
printf("%d",a);
return 0;
}
021: HAART
-
Total time limit:
1000ms
-
Memory Limit:
65536kB
-
description
HAART, originally referred to the "highly active antiretroviral therapy" (HAART), proposed by the Chinese-American scientist David Ho in 1996, is used to treat AIDS by more than three or three antiviral drugs in combination. The therapy can reduce resistance to a single drug application produced maximum inhibition of viral replication, the damaged part or all of the body's immune function recovery, thereby delaying disease progression, prolong life and improve quality of life. People on the basis of HAART also proposed a variety of improved therapies. To verify whether these treatments more effective than in the cocktail therapy, available by way of controlled clinical trials. HAART effective rate hypothesis x, new therapies effective rate y, yx if more than 5%, the better, if xy is greater than 5%, less effective, or almost called effect. Controlled clinical trials are given below n group, wherein the first group with HAART, n-1 other various modifications group therapy. Please write the program determines how effective various treatments to improve.
-
Entry
The first behavior integer n (1 <n <= 20); the remaining two lines each n integers, the first integer is the total number of patients in clinical trials (10,000 or less), the efficacy of the second effective number of cases. This n rows, the first row HAART data, the remaining data to improve the behavior of various therapies.
-
Export
There are n-1 output lines, respectively, corresponding to the effect of improved therapy: better if, Better output; if the result is worse worse output; otherwise the same output
-
Sample input
5 125 99 112 89 145 99 99 97 123 98
-
Sample Output
same worse better same
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n = 0;
scanf("%d",&n);
int total = 0;
int success = 0;
scanf("%d %d",&total,&success);
double start = double(success)/double(total);
for(int i =0;i<n-1;i++)
{
int t1,s1;
scanf("%d %d",&t1,&s1);
double ans = double(s1)/double(t1);
if(ans - start>0.05)
{
printf("better\n");
}
else if(start-ans>0.05)
{
printf("worse\n");
}
else
{
printf("same\n");
}
}
return 0;
}