Beginning With problem solving: Easy Problems

Easy Problems

Here are the set of easy problems, these are just a bit above super easy set of problems.
  1. UVa 00621 - Secret Research (case analysis for only 4 possible outputs)
  2. UVa 10114 - Loansome Car Buyer * (just simulate the process)
  3. UVa 10300 - Ecological Premium (ignore the number of animals)
  4. UVa 10963 - The Swallowing Ground (for two blocks to be mergeable, the gaps between their columns must be the same)
  5. UVa 11332 - Summing Digits (simple recursions)
  6. UVa 11559 - Event Planning * (one linear pass)
  7. UVa 11679 - Sub-prime (check if after simulation all banks have ≥ 0 reserves)
  8. UVa 11764 - Jumping Mario (one linear scan to count high+low jumps)
  9. UVa 11799 - Horror Dash * (one linear scan to find the max value)
  10. UVa 11942 - Lumberjack Sequencing (check if the input is sorted asc/descending)
  11. UVa 12015 - Google is Feeling Lucky (traverse the list twice)
  12. UVa 12157 - Tariff Plan (LA 4405, KualaLumpur08, compute and compare)
  13. UVa 12468 - Zapping (easy; there are only 4 possibilities)
  14. UVa 12503 - Robot Instructions (easy simulation)
  15. UVa 12554 - A Special ... Song (simulation)
  16. IOI 2010 - Cluedo (use 3 pointers)
  17. IOI 2010 - Memory (use 2 linear passes)



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", &current);
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

Installing albert on ubuntu 19.04

Installing Albert on Ubuntu 19.04... Albert is not still released for ubuntu 19.04. But still, you can install it using the following ...