Created
July 16, 2014 13:30
-
-
Save maksadbek/896f1ee20e6a74ee3c41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int taxi(int one, int two, int three, int four) | |
{ | |
int cars = 0; | |
cars = four; | |
if((three - one) != 0) | |
{ | |
cars += three - one; | |
three = (three % one); | |
} | |
else | |
{ | |
cars += three; | |
one = one - three; | |
} | |
if(one > 1){ | |
if((two - one/2) != 0) | |
{ | |
cars += two - one/2; | |
two = two % one/2; | |
} | |
else | |
{ | |
cars += two; | |
} | |
one = two; | |
} | |
else | |
{ | |
cars += two / 2; | |
two = two % 2; | |
cars += two; | |
cars += one; | |
} | |
return cars; | |
} | |
int main() | |
{ | |
int n; | |
int one=0, two=0, three=0, four=0; | |
std::cin>>n; | |
for(int i=0; i<n; i++) | |
{ | |
int n; | |
std::cin>>n; | |
switch(n) | |
{ | |
case 1: | |
one++; | |
break; | |
case 2: | |
two++; | |
break; | |
case 3: | |
three++; | |
break; | |
case 4: | |
four++; | |
default: | |
break; | |
} | |
} | |
int carsNeed = 0; | |
carsNeed = taxi(one,two,three,four); | |
std::cout<<carsNeed<<std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment