33 lines
		
	
	
		
			571 B
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			33 lines
		
	
	
		
			571 B
		
	
	
	
		
			C
		
	
	
	
	
	
| 
								 | 
							
								#include <math.h>
							 | 
						||
| 
								 | 
							
								#include <stdio.h>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define SIZE 999
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int two_crystal_balls_search(int array[], int size, int value)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
									int i = 0;
							 | 
						||
| 
								 | 
							
									int step = sqrt((double)(size));
							 | 
						||
| 
								 | 
							
									for (; i < size; i = i + step)
							 | 
						||
| 
								 | 
							
										if (array[i] >= value)
							 | 
						||
| 
								 | 
							
											break;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									printf("Step is: %d\n", step);
							 | 
						||
| 
								 | 
							
									printf("The first one broke at: %d\n", i);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									i = i - step;
							 | 
						||
| 
								 | 
							
									for (; i < i + step; ++i)
							 | 
						||
| 
								 | 
							
										if (array[i] >= value)
							 | 
						||
| 
								 | 
							
											return i;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									return -1;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int main()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
									int array[SIZE];
							 | 
						||
| 
								 | 
							
									for (int i = 0; i < SIZE; ++i)
							 | 
						||
| 
								 | 
							
										array[i] = i;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									printf("The balls break at: %d\n", two_crystal_balls_search(array, SIZE, 567));
							 | 
						||
| 
								 | 
							
								}
							 |