Saturday, 25 January 2014

UVa Problem ID 11495 (Bubbles and Buckets)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static long swapcount=0;
	public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb=new StringBuffer("");
        while(true)
        {
        	swapcount=0;
        	String s[]=br.readLine().split(" ");
	        int n=Integer.parseInt(s[0]);
	        if(n<2 || n>100000)
	        	break;
	        int a[]=new int[n];
	
	        for (int i = 0; i < n; i++) {
	        	a[i]=Integer.parseInt(s[i+1]);
				if(a[i]<1 || a[i]>n)
					System.exit(0);
				
			}

	        merge_sort(a,0,a.length-1);

	        if(swapcount%2==0)
	        	sb.append("Carlos");
	        else
	        	sb.append("Marcelo");
	        sb.append("\n");
        }
        System.out.print(sb);
    }
	public static void merge_sort(int[] a,int start,int end) {
			if(startmiddle)
			{
				combinedarray[k]=a[j++];
			}
			else if(j>end)
			{
				combinedarray[k]=a[i++];
			}
			else
			{
				if(a[i]>a[j])
				{
					combinedarray[k]=a[j++];
					swapcount+=middle-i+1;
				}
				else
					combinedarray[k]=a[i++];
			}
			
		}
		int p=0;
		for (int j2 = start; j2 <=end; j2++)
		{
			a[j2]=combinedarray[p++];
		}
	}	
	

}

Previous Post
Next Post

0 comments:

Advertisement