Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. /* File : justAnotherDisc */
  2. /* Author : Vasil Gevezov, Lauri Lujala */
  3. /* Date : 01.10.2014 */
  4. /* version : 9000.1 */
  5.  
  6. /* Description :
  7. * This is a program that checks for overlap between discs. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <math.h>
  12.  
  13. /* This structure stores all the needed data per circle in a single abstract data type. */
  14. typedef struct discInfo{
  15. int x, y, r;
  16.  
  17. }discInfot;
  18.  
  19. /* safeMalloc used to ensure that the memory is allocated properly. */
  20. void *safeMalloc(int arraySize) {
  21. void *ptr = malloc(arraySize);
  22. if (ptr == NULL) {
  23. printf("\nError: mAllocation failed.\n");
  24. exit(-1);
  25. }
  26. return ptr;
  27. }
  28. /* Now the allocated memory will be filled with the values from the input file. */
  29. discInfo *fillArray(int arraySize){
  30.  
  31. discInfo *discArray = (discFormat*)safeMalloc(arraySize*sizeof(discFormat));
  32.  
  33. discInfo content;
  34.  
  35. for ((int)i=0; i < arraySize; i++){
  36. scanf("%d %d %d", &content.x, &content.y, &content.r);
  37. discArray[i] = content;
  38. }
  39. return discArray;
  40. }
  41. /* 5:55 */
  42.  
  43. int overlap((int discAmount),(discInfo *discArray)){
  44.  
  45. int total = discAmount, contact = 0;
  46.  
  47. for ((int)i=0;i < discAmount; i++){
  48. for ((int)u = 0; u < discAmount; u++){
  49. if (sqrt(((discArray[i].x - discArray[u].x)*(discArray[i].x - discArray[u].x))
  50. + ((discArray[i].y - discArray[u].y)*(discArray[i].y - discArray[u].y)))
  51. <= discArray[i].r + discs[u].r) && u != i{
  52. contact++;
  53. }
  54. }
  55. }
  56.  
  57. noContact = total - contact;
  58.  
  59. return noContact;
  60. }
  61.  
  62.  
  63.  
  64. int main(int argc, char argv[]){
  65.  
  66. int arraySize;
  67.  
  68. scanf("%d", arraySize);
  69.  
  70. discInfo *discArray = (discInfo*)safeMalloc(discAmount*sizeof(discInfo*));
  71.  
  72. discs = readInput());
  73.  
  74. printf("number of discs: %d\n", numDiscs);
  75. printf("number of non-overlapping discs: %d\n", nonOverlap);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement