knowledgediarybd.com

Your Virtual Knowledge Campus

Other UVA Problem Solutions

other-problem-solutionThere are a lot of problems  separated from UVa Problem  Categories like: Ad hoc problem,Geometry problem. These problem are known as Other uva problem solutions

Though these problem are included in other problems categories, these problem are more interesting ,easy & critical .I hope you will get pleasure by solving  Other uva problem solutions.

other problems are easy and can be solved by previous knowledge.  But be careful about time, space and special criteria when

solving them.

Some Example of  Other uva problem solutions

Problem A

Problem Name: Back To High School & College geometry :

ad hoc problems

In above  figure, ABCD is a parallelogram and AEB is a triangle where E lies on any point of CD. You are given x and y coordinates of A,B and C. You have to find out the area of triangle AEB.

Input

Each line of input to your program will contain the x and y coordinates of three points (A,B and C) in the order AxAyBxByCxCy. These coordinates will be real (float or integer) numbers separated from each other by one or more spaces.

Output:

Print the area of triangle in one line with 2 digits after the decimal point. Print a new line after the end of each output. Be careful!!! Area is always a positive number.

Sample input

0 0 0 2 2 2

-1.5 -2.3 -3.1 4 2.9 3

0.1 9 2.5 -6 -4 -6.7

Sample Output

2.00

18.10

49.59

Solution:

It is very easy geometry problem under Ad hoc problems categories . Area of triangle AEB is equal to area of triangle ABC. And using co-ordinate geometry area of ABC is,

abe

Program Code:

#include <cstdio>

#include <cmath>

using namespace std;

int main()

{

float ax,ay,bx,by,cx,cy,d,x,y;

while(scanf("%f %f %f %f %f %f",&ax,&ay,&bx,&by,&cx,&cy)==6)

{

printf("%.2f\n",fabs(0.5*(ax*(by-cy)+ay*(cx-bx)+(bx*cy-cx*by))));

}

return 0;

}

Problem – No:2

 uva Problem Name: Apple-The Innovation

“Apple” the innovation of “Steve jobs”.  He is best known as the co-founder, chairman, and chief executive officer of Apple Inc. Jobs has received a number of honors and public recognition for his influence in the technology and music industries. He has widely been referred to as “legendary”, a “futurist” or simply “visionary”, and has been described as the “Father of the Digital Revolution”, a “master of innovation”, and a “design perfectionist”. Unfortunately he died in October 5, 2011.

Once Eisty dreamed a dream that he met with Steve Jobs. Steve played a nice game with him. He told Eisty to take some imaginary apples & not to tell the number of apples. Eisty took 39 apples. Then Steve told to take same number of apples from his friend. Then told to take from him 12 apples and sum the total. Eisty did & then he had 90 apples. Steve told to give half of the total apples to the poor and return the apples of his friend. Then Steve told u have 6 apples remaining. Eisty was surprised to see how Steve could tell the remaining number as he didn’t know the number of apples !!

Steve is absent in the present world. But Eisty believes that God spread out the talents all around the world. That’s why he want to know how many Steve Jobs will be from all over the world and  so want to play the same game that was played with Steve Jobs. Now your task is to do the same task as Steve did, input the number of apples like Steve provided and print the remaining number of apples.

Input:
Input starts with an integer T (T<=1000) , the number of test cases. Each test case will contain an integer. All integers will be less than 10,000 and greater than 0.You can assume that no operation overflows a 32-bit integer.

Output:
For each test case , output a single line giving the case number followed by the remaining numbers of apples. See the sample output for exact format.

                   Sample input:                     Sample Output:
2
10
11
Case 1: 5.00
Case 2: 5.50

Solution:

Input File: To run this program you must save it as: input.txt

20                    // Test case
257
123
2569
124
5896
2548
12
10
11
25
24
2486
4
8
264
63
56
654
4862
96

Program Code:

#include<stdio.h>
int main(){
int i,n;
float a;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&n);

for(i=1;i<=n;i++){
scanf("%f",&a);
printf("Case %d: %.2f\n",i,a/2);

}

Output File Looks Like Below and must save as it : output.txt

Case 1: 128.50
Case 2: 61.50
Case 3: 1284.50
Case 4: 62.00
Case 5: 2948.00
Case 6: 1274.00
Case 7: 6.00
Case 8: 5.00
Case 9: 5.50
Case 10: 12.50
Case 11: 12.00
Case 12: 1243.00
Case 13: 2.00
Case 14: 4.00
Case 15: 132.00
Case 16: 31.50
Case 17: 28.00
Case 18: 327.00
Case 19: 2431.00
Case 20: 48.00

Related Post or You may felt Interest:

  1. Introduction of acm ICPC & UVa Online Judge
  2. Programming Sites & Resources
  3. Introduction & Ad Hoc Problems Solution
  4. Data Structures & Libraries problem Solution
  5. UVa Mathematics Problem Solution
  6. String Processing Problem Solution
  7. Computational Geometry Problem Solution
  8. Graphs Problem Solution
knowledgediarybd.com © 2017
shares