Блог пользователя M.sayed97

Автор M.sayed97, история, 8 лет назад, По-английски

the idea is when i find 4 I increase the number of taxis by one, and then i combine every 1's and 3's in one taxi, and i combine 2's with each other , and the remaining 2's and 1's i combine them and divide them by 4 and adds the result to number of taxis , if there is any remaining groups i increase the number of taxis by one . I get wrong answer at test case 64 and i don't know why so please any help . here is my submission code.............< 21109241 thanks in advance :D

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Check this modified code:

import java.util.Scanner;

public class copy {
	public static void main (String[]args){
	Scanner sc = new Scanner(System.in);
	int number = sc.nextInt();
	int taxis = 0;
	int []groups = new int [5];
	for (int i = 0; i < number; i++) {
		groups[sc.nextInt()]++;
	}
	taxis +=groups[4];
	taxis+=groups[2]/2;
	groups[2]=groups[2]%2;
	if (groups[3]!=0) 
	{
		if (groups[3]>=groups[1]) 
		{
			
			taxis+=groups[3]+groups[2];
		}
		else 
		{
			groups[1]-=groups[3];
		    taxis+=groups[3];
		    while(groups[2] > 0)
		    {
		        taxis++;
		        groups[1] -=2;
		        groups[2]--;
		    }
		    while(groups[1] > 0)
		    {
		        taxis++;
		        groups[1] -=4;
		    }
		}
	}
	else {
		while(groups[2] > 0)
		    {
		        taxis++;
		        groups[1] -=2;
		        groups[2] --;
		    }
		    while(groups[1] > 0)
		    {
		        taxis++;
		        groups[1] -=4;
		    }
			
	}
	
	System.out.println(taxis);
}

}
  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    thank you very much , i understand now what i did wrong . thank you a lot :D

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    can u plz write it in c?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      #include<bits/stdc++.h>
      using namespace std;
      #define lli long long int
      //char a[2000][2000];
      int main()
      {
      	int n;
      	cin>>n;
      	int a,b[5]={0},ans=0,sum=0;
      	for(int i=0;i<n;i++){
      		scanf("%d",&a);
      		b[a]++;
      	}
      	ans+=b[4];
      	ans+=b[3];
      	if(b[1]>b[3])
      		b[1]=b[1]-b[3];
      	else
      		b[1]=0;
      	sum=(b[1]+2*b[2]);
      	if(sum%4!=0)
      		ans+=1+(sum)/4;
      	else
      		ans+=(sum)/4;
      
      	printf("%d",ans);
      }
      
    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Although, you can see the tutorial/solution for almost all questions.

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Dear abirwaliullah98,

      The following is a GNU C++17 solution for the problem using C++11 lambda expressions.

      35443826

      Best wishes,