Dennis, Doorknob, Martin Büttner, Chris Jester-Young - Pizzeria!
CJam, 20 bytes
q~1$*4/"CEDM"e*/:$N*
I think this should work :)
Try it online
Explanation:
This first makes a pizza labeled CC…EE…DD…MM… from left to right and top to bottom, then sorts each row in alphabetical order. The only disconnections can happen between the C-E border and E-D border, or E-D border and D-M border (if they fall on adjacent rows). But the sorting ensures that the E's go to the right side and the D's go to the left side, as C<E>D<M, so the E's and the D's remain connected.
q~ read and evaluate the input
1$ copy the width
*4/ multiply with the height and divide by 4
"CEDM"e* repeat each letter in "CEDM" that many times
/ split into rows of the given width
:$ sort each row
N* join with newlines
Pyth, 30 25 bytes
jb.eu_GkbceQs*R/*FQ4"EDMC
Live demo and all test cases.
Cut off 5 bytes thanks to @Jakube!
Same algorithm as my K answer...but a lot shorter.
30-byte version:
jb.e?%k2_bbcjkm*/*FQ4d"EDMC"hQ
Live demo and all test cases for 50-byte version.
K, 61 bytes
{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}
Examples:
ryan@DevPC-LX:~/golf$ rlwrap k2
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
Evaluation. Not for commercial use.
\ for help. \\ to exit.
`0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[4;1]
EDMC
`0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[4;4]
EEEE
DDDD
MMMM
CCCC
`0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[8;3]
EEEEEEDD
MMMMDDDD
MMCCCCCC
`0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[20;5]
EEEEEEEEEEEEEEEEEEEE
DDDDDDDDDDDDDDDEEEEE
DDDDDDDDDDMMMMMMMMMM
CCCCCMMMMMMMMMMMMMMM
CCCCCCCCCCCCCCCCCCCC
ryan@DevPC-LX:~/golf$
I would hate to be the person who has to slice these things...