Easy Problems
Here are the set of easy problems, these are just a bit above super easy set of problems.
- UVa 00621 - Secret Research (case analysis for only 4 possible outputs)
- UVa 10114 - Loansome Car Buyer * (just simulate the process)
- UVa 10300 - Ecological Premium (ignore the number of animals)
- UVa 10963 - The Swallowing Ground (for two blocks to be mergeable, the gaps between their columns must be the same)
- UVa 11332 - Summing Digits (simple recursions)
- UVa 11559 - Event Planning * (one linear pass)
- UVa 11679 - Sub-prime (check if after simulation all banks have ≥ 0 reserves)
- UVa 11764 - Jumping Mario (one linear scan to count high+low jumps)
- UVa 11799 - Horror Dash * (one linear scan to find the max value)
- UVa 11942 - Lumberjack Sequencing (check if the input is sorted asc/descending)
- UVa 12015 - Google is Feeling Lucky (traverse the list twice)
- UVa 12157 - Tariff Plan (LA 4405, KualaLumpur08, compute and compare)
- UVa 12468 - Zapping (easy; there are only 4 possibilities)
- UVa 12503 - Robot Instructions (easy simulation)
- UVa 12554 - A Special ... Song (simulation)
- IOI 2010 - Cluedo (use 3 pointers)
- IOI 2010 - Memory (use 2 linear passes)
Here is the link to the folder: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=608
I share the solution and hints of only a few problems.
UVa 10114 - Loansome Car Buyer
Just do what the problem says, more of an implementation problem.
//Uva 10114 Loansome Car Buyer | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main(int argc, char const *argv[]) { | |
int n, dec; | |
double downp,l; | |
while (true) { | |
cin>>n>>downp>>l>>dec; | |
if(n<0) | |
break; | |
float arr[n+1]={0}; | |
while (dec--) { | |
int i; | |
float temp; | |
cin>>i>>temp; | |
arr[i] = temp; | |
} | |
for (size_t i = 0; i < n+1; i++) { | |
if(arr[i]==0) | |
arr[i] = arr[i-1]; | |
} | |
int now=0; | |
float loan = l; | |
float permonth = (l/n); | |
float value = (l+downp)*(1-arr[0]); | |
while (value<loan) { | |
now++; | |
value = value*(1-arr[now]); | |
loan = loan - permonth; | |
} | |
cout<<now<<" month"; | |
if(now!=1) | |
cout<<'s'; | |
cout<<endl; | |
} | |
} |
UVa 10300 - Ecological Premium
Not worth a share, just ignore the number of animals. Think before starting to type.
//Uva 10300 Ecological Premium | |
int main(int argc, char const *argv[]) { | |
int n; | |
cin>>n; | |
while (n--) { | |
int f; | |
cin>>f; | |
int sum=0; | |
int a,b, c; | |
while(f--){ | |
cin>>a>>b>>c; | |
sum += (a*c); | |
} | |
cout<<sum<<endl; | |
} | |
return 0; | |
} |
UVa 11332 - Summing Digits
A combination of two problems: Do simple recursion and calculate the sum of digits of a number.
//Uva 11332 Summing Digits | |
int sumofdigits(unsigned long long int a){ | |
int sum=0; | |
while (a!=0) { | |
sum = sum + (a%10); | |
a = a/10; | |
} | |
return sum; | |
} | |
int solve(unsigned long long int a){ | |
if(a/10==0) | |
return a; | |
return solve(sumofdigits(a)); | |
} | |
int main(int argc, char const *argv[]) { | |
unsigned long long int n; | |
// scanf("%ulld", &n); | |
cin>>n; | |
while (n!=0) { | |
int t = solve(n); | |
cout<<t<<endl; | |
cin>>n; | |
} | |
return 0; | |
} |
UVa 10963 - The Swallowing Ground
The two plates can be joined if the distance between north and south plates is constant throughout.
// Uva The swallowing Groung | |
int main(int argc, char const *argv[]) { | |
int n; | |
cin>>n; | |
while (n--) { | |
int W; | |
bool can = true; | |
cin>>W; | |
int y1, y2; | |
cin>>y1>>y2; | |
int temp = (y1-y2); | |
W--; | |
while (W--) { | |
cin>>y1>>y2; | |
if(y1-y2!=temp){ | |
can = false; | |
} | |
} | |
if(can){ | |
cout << "yes" << '\n'; | |
}else{ | |
cout << "no" << '\n'; | |
} | |
if(n){ | |
cout<<endl; | |
} | |
} | |
return 0; | |
} |
UVa 11559 - Event Planning
You can stay at a hotel if among all weeks, the weekend with maximum number of rooms vacant is greater than number of friends. All other hotels are ruled out.
Now among those calculate the prices for each, print the minimum in case it is lesser than the budget.
// //Uva 11559 Event Planning | |
int main(int argc, char const *argv[]) { | |
int N, B, H, W; | |
while(scanf("%d %d %d %d", &N, &B, &H, &W)==4){ | |
int p; | |
int minprice = B+1; | |
for(int l=0;l<H;l++){ | |
scanf("%d", &p); | |
int max=0; | |
int temp; | |
for(int k=0;k<W;k++) { | |
scanf("%d", &temp); | |
if(temp>max) | |
max = temp; | |
} | |
if(max>=N){ | |
if(N*p<minprice) | |
minprice = N*p; | |
} | |
} | |
if(minprice>B) | |
cout << "stay home" << '\n'; | |
else | |
cout <<minprice<< '\n'; | |
} | |
return 0; | |
} |
UVa 11764 - Jumping Mario
Must be easy to solve. No hints required.
//Uva 11679- Jumping Mario | |
int main(int argc, char const *argv[]) { | |
int T; | |
scanf("%d", &T); | |
for(int i=0;i<T;i++) { | |
int N; | |
scanf("%d", &N); | |
int current; | |
scanf("%d\n", ¤t); | |
N--; | |
int temp; | |
int high=0; | |
int low=0; | |
for(int j=0;j<N;j++) { | |
scanf("%d", &temp); | |
if(temp<current) | |
low++; | |
else if(temp>current) | |
high++; | |
current = temp; | |
} | |
printf("Case %d: %d %d\n",i+1, high, low); | |
} | |
return 0; | |
} |
UVa 11799 - Horror Dash
Do a linear scan to find the max speed, this is the answer.
//Uva 11799 Horror Dash | |
int main(int argc, char const *argv[]) { | |
int T; | |
scanf("%d", &T); | |
for (int i = 0; i < T; i++) { | |
int N; | |
int max = 0; | |
scanf("%d", &N); | |
int temps; | |
for (size_t j= 0; j < N; j++) { | |
scanf("%d", &temps); | |
if(temps>max) | |
max = temps; | |
} | |
printf("Case %d: %d\n", i+1, max); | |
} | |
return 0; | |
} | |
UVa 11942 - Lumberjack Sequencing
We have to check either input is in ascending or descending form or not. Do a liner scan and check it. I did it using the xor operation, you can do it using some other method.
//Uva Lumber Jack Sequencing | |
int main(int argc, char const *argv[]) { | |
int N; | |
scanf("%d\n", &N); | |
std::cout << "Lumberjacks:" << '\n'; | |
while (N--) { | |
int temp; | |
cin>>temp; | |
bool ascb = false; | |
bool desb = false; | |
int asc; | |
for (size_t i = 0; i < 9; i++) { | |
cin>>asc; | |
if(asc>temp){ | |
ascb = true; | |
temp = asc; | |
} | |
if(asc<temp){ | |
desb = true; | |
temp = asc; | |
} | |
} | |
if(ascb^desb) | |
cout << "Ordered" << '\n'; | |
else | |
cout << "Unordered" << '\n'; | |
} | |
return 0; | |
} |
No comments:
Post a Comment