Two trains are going along each track. The speed of the first train is 50 KMs / h and the speed of the second train is 70 KMs / h. A distance between two trains is 100 KMs. The first flies from the first train to the second train. Once it reaches the second train ... Calculate the total distance traveled by the bee. Speed of bee is 40 KMs / h.
The king of a small country invites 240 senators to his annual party. As a tradition, each senator brings a bottle of wine. Soon after they’re trying to get a bottle of poisoned wine. Unfortunately, it’s not a rule. However, the King has 5 prisoners. It doesn’t help you. After drinking the poisoned wine, one dies within 24 hours. The King needs to continue to plan. It is a quest to ensure that it has reached the level of the poisoned wine bottle.
Given the number of 0s and 1s, it contains the number of 0s and 1s.
Examples:
Input: arr [] = {1, 0, 1, 1, 1, 0, 0}
Output: 1 to 6 (Starting and Ending indexes of output subarray)
')
Input: arr [] = {1, 1, 1, 1}
Output: No such subarray
Input: arr [] = {0, 0, 1, 1, 0}
Output: 0 to 3 Or 1 to 4
Number of numbers from 1 to n.
Examples:
Input: n = 3
Output: 4
Input: n = 6
Output: 9
Input: n = 7
Output: 12
Input: n = 8
Output: 13
Given an unsorted n-sized array of integers. Array elements are in range from 1 to n. One number from set {1, 2, ... n} is missing and one number occurs in array. Find these two numbers.
Examples:
arr [] = {3, 1, 3}
Output: 2, 3 // 2 is missing and 3 occurs twice
arr [] = {4, 3, 6, 2, 1, 1}
Output: 1, 5 // 5 is missing and 1 occurs twice
#include<stdio.h> #include<stdlib.h> void printTwoElements(int arr[], int size) { int i; printf("\n The repeating element is"); for(i = 0; i < size; i++) { if(arr[abs(arr[i])-1] > 0) arr[abs(arr[i])-1] = -arr[abs(arr[i])-1]; else printf(" %d ", abs(arr[i])); } printf("\nand the missing element is "); for(i=0; i<size; i++) { if(arr[i]>0) printf("%d",i+1); } } /* Driver program to test above function */ int main() { int arr[] = {7, 3, 4, 5, 5, 6, 2}; int n = sizeof(arr)/sizeof(arr[0]); printTwoElements(arr, n); return 0; }
Source: https://habr.com/ru/post/347636/
All Articles