- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- float a,b,v;
- float x,y;
- float dis,mn=1000,ans=0;
- cin>>x>>y;
- cin>>t;
-
- while(t--)
- {
- cin>>a>>b>>v;
- if(a==x and b==y) {ans=1;}
- dis=sqrt( (x-a)*(x-a) +(y-b)*(y-b) );
- mn = min(mn, dis/v);
-
- }
- if(ans) cout<<"0.00000000000000000000"<<endl;
- else printf("%.20f\n",mn);
-
- return 0;}
Monday, June 29, 2020
A - Beru-taxi(706A - Beru-taxi)
Sunday, June 28, 2020
787A - The Monster
787A - The Monster.cpp
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).
The second line contains two integers c and d (1 ≤ c, d ≤ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
input
Copy
20 2
9 19
output
Copy
82
input
Copy
2 1
16 12
output
Copy
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
20 2 9 19
82
2 1 16 12
-1
- ///bismillah
- #include<iostream>
- using namespace std;
- int main(){
- long long a,b,c,d,f=0;
- long int sum1[300],sum2[300];
- cin>>a>>b;
- cin>>c>>d;
- for(int i=0;i<101;i++)
- { sum1[i]= b+i*a;
-
- }
- for(int i=0;i<101;i++)
- { sum2[i]= d+i*c;
-
- }
- for(int j=0;j<101;j++){
- for(int i=0;i<101;i++) {
- if(sum2[j]==sum1[i])
- { cout<<sum2[j]; f=1; break; }
-
- }
- if(f==1) break;}
-
-
- if(f==0) cout<<-1;
- return 0;
-
-
- }
-
Saturday, June 27, 2020
680A - Bear and Five Cards
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
The only line of the input contains five integers t 1, t 2, t 3, t 4 and t 5 (1 ≤ t i ≤ 100) — numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
7 3 7 3 20
26
7 9 3 1 8
28
10 10 10 10 10
20
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
- Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
- Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int a[5],sum=0,x=0,y=0;
- int b[100000]={0};
- for(int i=0;i<5;i++)
- {cin>>a[i];
- b[a[i]]++;
- if( b[a[i]]==2) x=max(x,a[i]);
- else if( b[a[i]]==3) y=a[i];
- sum = sum +a[i];}
- cout<<sum-max(2*x,3*y);
- return 0; }
676A - Nicholas and Permutation
- A. Nicholas and PermutationNicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.InputThe first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation.The second line of the input contains n distinct integers a 1, a 2, ..., a n (1 ≤ a i ≤ n), where a i is equal to the element at the i-th position.OutputPrint a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.ExamplesinputCopy
5 4 5 1 3 2
outputCopy3
inputCopy7 1 6 5 3 4 7 2
outputCopy6
inputCopy6 6 5 4 3 2 1
outputCopy5
NoteIn the first sample, one may obtain the optimal answer by swapping elements 1 and 2.In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. - #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n; cin>>n;
- int a[n];int x;
- vector<pair<int,int>>v;
- for(int i=1;i<=n;i++)
- { cin>>x;
- v.push_back(make_pair(x,i));
- }
- sort(v.begin(),v.end());
- {
- int a=v[0].second;///5
- int b=v[n-1].second;///3
- cout << max(max(n - b, b - 1), max(n - a, a - 1));
- }
Wednesday, June 24, 2020
670A - Holidays
A. HolidaysOn the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
InputThe first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.
OutputPrint two integers — the minimum possible and the maximum possible number of days off per year on Mars.
ExamplesinputCopy14
outputCopy4 4
inputCopy2
outputCopy0 2
NoteIn the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
- #include<iostream>
- using namespace std;
- int main()
- {
- long n;
- cin>>n;
- long d=0,x=0;int i=1;
- long m=n;
- ///max
- d=n/7;
- x= n- 7*d;
- if(x>=2 and x!=0) x=2;
- else if(x<2 and x!=0) x=1;
- ///min
- int mn=0;
- while(m--){
- n=n-5;
- if(n>=2 and n!=0){ mn+=2; n=n-2;}
- else if(n>=1 and n!=0 ){ mn+=1; n=n-1;}
- //cout<<n<<" ";
- }
- cout<<mn<<" ";
- cout<<2*d+x;
- return 0;
- }
Aptitude test assistant programmer 2018
#include <stdio.h> #include <stdlib.h> int main() { char str[100]; int i; int space=0; printf("Enter a string\n")...
-
104A - Blackjack #include < bits / stdc ++. h > using namespace std ; int main (){ int n ; cin >> n ; int d = n - 10 ; ...
-
A. YES or YES? There is a string s � of length 3 3 , consisting of uppercase and lowercase English letters. Check if it is equal to &qu...
-
#include <iostream> using namespace std ; int main () { int n ; int q = 2 ; int c = 0 ; cin >> n ; if ( n % 2 == ...