Weighing 1 gram. One of the machines, however, produces weighing weighing 0.9 grams only. It is allowed.
Sherlock Holmes was decoding an encrypted message. If it is in the form of encryption, it is a DISTANCE and it is written as ODDVNTNE.
Can you help him decipher HTTQYAD?
If you want to find out how to do it, you can’t get it. If you’ve been on the road, you’ve been able to build it up. Task: - from the location of rare-elements.
')
Locations are given in the matrix cell form where the 1 represents the roads and 0 no road. The number of rare-and-a-half-numbers was not given to (20).
This is a function that has been saved. It’s a time when you’ve saved it. This is a function of
It can be compiled, that is, depends on the compiler. Write downward or upward?
Given an array, print the Next Greater Element (NGE) for every element. There is no need for more information. Consider, consider next greater element as -1.
Examples:
a) For any array, rightmost element always has next greater element as -1.
b) for an array which is the sorted in decreasing order, all elements have the next greater element as -1.
c) For the input array [4, 5, 2, 25],Element nge 4 -> 5 5 -> 25 2 -> 25 25 -> -1
d) For the input array [13, 7, 6, 12],Element nge 13 -> -1 7 -> 12 6 -> 12 12 -> -1
Element nge 4 -> 5 5 -> 25 2 -> 25 25 -> -1
Element nge 13 -> -1 7 -> 12 6 -> 12 12 -> -1
using namespace std ; bool ar[21][21]; bool visited[21][21]; int ans[21][21]; int xa[]={0,-1,0,1}; int yb[]={1,0,-1,0}; int n; typedef struct Point{ int x,y; }P; typedef struct C { int x,y; int dis; } C; bool issafe(int x,int y) { return (x>=0 && x<n &&="" y="">=0 && y<n && ar[x][y] && !visited[x][y]); } void bfs(int x,int y) { queue<c> q; C in; in.x=x; in.y=y; in.dis=0; q.push(in); visited[x][y]=1; while(!q.empty()) { C c=q.front(); q.pop(); int a=cx; int b=cy; int d=c.dis; ans[a][b]=d; for(int i=0;i<4;i++) { int nx=a+xa[i]; int ny=b+yb[i]; if(issafe(nx,ny)) { visited[nx][ny]=1; in.x=nx; in.y=ny; in.dis=d+1; q.push(in); } } } } int main() { cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>ar[i][j]; } } int q; cin>>q; P rare[q]; int fans=10000; int mx=-1; for(int i=0;i<q;i++) { int a,b; cin>>a>>b; rare[i].x=a; rare[i].y=b; } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { memset(ans,10000,sizeof(ans)); int flag=0; memset(visited,0,sizeof(visited)); mx=-1; if(ar[i][j]) { bfs(i,j); for(int k=0;k<q;k++) { if(ans[rare[k].x][rare[k].y]==10000) { flag=1; break; } } if(!flag) { for(int k=0;k<q;k++) { mx=max(mx,ans[rare[k].x][rare[k].y]); } } fans=min(fans,mx); } } } cout<<fans<<endl; }
void stupdown(int *main_local_addr) { int fun_local; if (main_local_addr < &fun_local) printf("Stack grows upward\n"); else printf("Stack grows downward\n"); } int main() { // st's local variable int main_local; stupdown(&main_local); return 0; }
// A Stack based C++ program to find next // greater element for all array elements. #include<bits/stdc++.h> using namespace std; /* prints element and NGE pair for all elements of arr[] of size n */ void printNGE(int arr[], int n) { stack<int> s; /* push the first element to stack */ s.push(arr[0]); // iterate for rest of the elements for (int i=1; i<n; i++) { int next = arr[i]; if (s.empty() == false) { // if stack is not empty, then // pop an element from stack int element = s.top(); s.pop(); /* If the popped element is smaller than next, then a) print the pair b) keep popping while elements are smaller and stack is not empty */ while (element < next) { cout << element << " --> " << next << endl; if (s.empty() == true) break; element = s.top(); s.pop(); } /* If element is greater than next, then push the element back */ if (element > next) s.push(element); } /* push next to stack so that we can find next greater for it */ s.push(next); } /* After iterating over the loop, the remaining elements in stack do not have the next greater element, so print -1 for them */ while (s.empty() == false) { cout << s.top() << " --> " << -1 << endl; s.pop(); } } /* Driver program to test above functions */ int main() { int arr[] = {11, 13, 21, 3}; int n = sizeof(arr)/sizeof(arr[0]); printNGE(arr, n); return 0; }
Source: https://habr.com/ru/post/358918/
All Articles