0% found this document useful (0 votes)
32 views

Algorithm 2

The document contains summaries of several algorithms: 1) A quadratic equation solver that calculates the roots of a quadratic equation given coefficients a, b, c. It checks for real or complex solutions. 2) An algorithm to find the largest element in an array by iterating through it and tracking the maximum value and its location. 3) An algorithm to find the location of a target item in an array by iterating and checking for matches. It also includes code snippets for Codeforces problems involving sorting an array, dividing cardboard for pictures, and determining if a sum is greater than or equal to 10.

Uploaded by

Md. Tamim Iqbal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Algorithm 2

The document contains summaries of several algorithms: 1) A quadratic equation solver that calculates the roots of a quadratic equation given coefficients a, b, c. It checks for real or complex solutions. 2) An algorithm to find the largest element in an array by iterating through it and tracking the maximum value and its location. 3) An algorithm to find the location of a target item in an array by iterating and checking for matches. It also includes code snippets for Codeforces problems involving sorting an array, dividing cardboard for pictures, and determining if a sum is greater than or equal to 10.

Uploaded by

Md. Tamim Iqbal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Algorithm 2.

Algorithm Name: Quadratic Equation

Code:

#include<bits/stdc++.h>
using namespace std;
int main(){
float a,b,c;
cin>>a>>b>>c;
float d=pow(b,2)-4*a*c;
if(d>0){
float x1=(-b+sqrt(d))/(2*a);
float x2=(-b-sqrt(d))/(2*a);
cout<<"x1="<<x1<<" "<<"x2="<<x2<<endl;
}
else if(d==0){
float x=-b/(2*a);
cout<<"UUNIQUE SOLUTION:"<<x<<endl;
}
else cout<<"NO REAL SOLUTION"<<endl;
return 0;
}
Output:

Algorithm 2.3

Algorithm Name: Largest Element in Array


Code:

#include<bits/stdc++.h>
using namespace std;
int main(){
int ara[10]={1,3,5,3,78,2,1,4,5,23};
int LOC=0;
int Max=ara[0];
int k=0,N=10;
start:
k++;
if(k==N){
cout<<"LOC:"<<LOC<<" "<<"MAX:"<<Max<<endl;
exit(0);
}
if(ara[k]>Max) {
Max=ara[k];LOC=k;
}
goto start;
return 0;
}

Output:

Algorithm 2.3

Algorithm Name: Largest Element in Array

Code:

#include<bits/stdc++.h>
using namespace std;
int main(){
int ara[10]={1,2,5,6,7,8,23,4,53};
int item=23;
int loc=0;
for(int i=1;i<10;i++){
if(item==ara[i]){
loc=i;
cout<<"Loc:"<<loc<<endl;
break;
}
}
return 0;
}

Output:

Problem Platform: Codeforces


Problem No & Name: 1853A & A. Desorting
Link: https://codeforces.com/contest/1853/problem/A
#include<bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
int main(){
faster;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int>v(n);
int count=0;
int min=INT_MAX;
for(int i=0;i<n;i++) cin>>v[i];
for(int i=0;i<n-1;i++) {
if(v[i]>v[i+1]) count=1;
if((v[i+1]-v[i])<min) min=v[i+1]-v[i];
}
if(count==1) cout<<"0"<<endl;
else{
int res=(min/2)+1 ; cout<<res<<endl; }
}
return 0; }
Problem Platform: Codeforces

Problem No & Name:1850E & E. Cardboard for Pictures

Link: https://codeforces.com/contest/1850/problem/E

#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
long long int n,c;long long int r,sum=0,res;
cin>>n>>c;
vector<int>ara(n);
for(int i=0;i<n;i++) {
cin>>ara[i];
sum+=ara[i];
c=c-(ara[i]*ara[i]);
}
r=(sum/n);
res=(-r+(int)sqrt((r*r)+(c/n)))/2;
cout<<res<<endl;
}
return 0;
}
Problem Platform: Codeforces

Problem No & Name:1850A & A. To My Critics

Link: https://codeforces.com/contest/1850/problem/A

#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int a,b,c;
cin>>a>>b>>c;
int d=(a>b)?b:a;
int e=(d>c)?c:d;
int sum=a+b+c-e;
if(sum>=10) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
Output:

You might also like