-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
545 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
int t; | ||
//int sum = 0; | ||
|
||
cin>>t; | ||
|
||
while(t--){ | ||
int sum = 0; | ||
int a,i; | ||
int n; | ||
cin>>a; | ||
for(i=0;i<a;i++){ | ||
cin>>n; | ||
sum=sum+n; | ||
} | ||
if(sum%2 == 0){ | ||
cout<<"YES"<<endl; | ||
} | ||
|
||
else{ | ||
cout<<"NO"<<endl; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
int t; | ||
cin>>t; | ||
int a,b,c,d,x,y; | ||
|
||
while (t--) | ||
{ | ||
cin>>x>>y; // CURRENT LOCATION | ||
cin>>a>>b;// BOB's location | ||
cin>>c>>d;// Carol's Location | ||
|
||
if(c<=x && x<=a && d<=y && y<=b || b<=y && y<=d && a<=x && x<=c){ | ||
cout<<"1"<<endl; | ||
} | ||
|
||
else{ | ||
int r = (abs(a-x) + abs(b-y) + 1) + (abs(c-x) + abs(d-y) + 1) - (abs(a-c) + abs(b-d)); | ||
int s = ((r+1)/2); | ||
cout<<s<<endl; | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include<stdio.h> | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
int x; | ||
cin>>x; | ||
string s; | ||
cin>>s; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
int t; | ||
cin>>t; | ||
|
||
while(t--){ | ||
int n,k,x; | ||
int i,j; | ||
bool check = true; | ||
cin>>n>>k>>x; | ||
|
||
if(k==x==1){ | ||
cout<<"NO"<<endl; | ||
} | ||
|
||
if( n%2 !=0 && k==2 && x==1){ | ||
cout<<"NO"<<endl; | ||
} | ||
|
||
if(x!= 1){ | ||
cout<<"Yes"<<endl; | ||
cout<<n*1<<endl; | ||
for(j=1;j<=(n*1);j++){ | ||
cout<<"1"<<" "; | ||
} | ||
cout<<endl; | ||
} | ||
|
||
|
||
if(n % 2 == 0){ | ||
|
||
cout<<"YES"<<endl; | ||
cout<<n/2<<endl; | ||
for(i=1;i<=n;i++){ | ||
cout<<"2"<<" "; | ||
} | ||
cout<<endl; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <iostream> | ||
#include<bits/stdc++.h> | ||
#include<string.h> | ||
#include<cmath> | ||
|
||
using namespace std; | ||
|
||
int countDigit(long long n) | ||
{ | ||
int count=0; | ||
while (n != 0) { | ||
count++; | ||
n = n / 10; | ||
} | ||
return count; | ||
} | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
int n; | ||
int i,j,digit,temp,k,h; | ||
while(t--){ | ||
cin >> n; | ||
int temp=n; | ||
int original; | ||
original = n; | ||
int maxnum=max(n,0); | ||
h = countDigit(n); | ||
if(n < 5){ | ||
cout << n << endl; | ||
} | ||
else if(n>=5 && n<=10){ | ||
cout << 10 << endl; | ||
} | ||
else{ | ||
for(k=1; k<=h;k++){ | ||
digit = temp % 10; | ||
if(digit >= 5){ | ||
n = n + pow(10,k) - (pow(10,k-1)*digit); | ||
} | ||
else{ | ||
n = n - (pow(10,k-1) * digit); | ||
} | ||
temp=n/pow(10,k); | ||
maxnum=max(maxnum,n); | ||
temp%=10; | ||
} | ||
cout<<maxnum<<endl; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
|
||
int main(){ | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
long long n, count=0, start; | ||
cin >> n; | ||
for(int i=1; i<=9; i++) | ||
{ | ||
start=i; | ||
while(start<=n) | ||
{ | ||
count++; | ||
start=start*10+i; | ||
} | ||
} | ||
cout << count << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
|
||
int main(){ | ||
int t; | ||
cin>>t; | ||
int a,b; | ||
|
||
while(t--){ | ||
cin>>a; | ||
if(a % 3 == 0){ | ||
cout<<a/3<<" "<<a/3<<endl; | ||
} | ||
|
||
else if( a % 3 == 1){ | ||
cout<<a/3 + 1<<" "<<a/3<<endl; | ||
} | ||
|
||
else if(a % 3 == 2){ | ||
cout<<a/3 <<" "<<a/3 + 1 <<endl; | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() { | ||
int n,m; | ||
cin>>n>>m; | ||
int a = n-1; | ||
int b = m-1; | ||
int result=(a)/(b); | ||
cout<<n+result; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <numeric> | ||
using namespace std; | ||
|
||
int smallest(int arr[], int size) { | ||
if (size <= 0) { | ||
return -1; | ||
} | ||
|
||
int smallest = arr[0]; | ||
|
||
for (int i = 1; i < size; ++i) { | ||
if (arr[i] < smallest) { | ||
smallest = arr[i]; | ||
} | ||
} | ||
|
||
return smallest; | ||
} | ||
|
||
int findIndex(int arr[], int n, int target) { | ||
for (int i = 0; i < n; i++) { | ||
if (arr[i] == target) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
int main() { | ||
|
||
int t; | ||
cin >> t; | ||
|
||
while (t--) { | ||
int x, n; | ||
cin >> x >> n; | ||
|
||
int a[x]; | ||
int b[x]; | ||
|
||
for (int i = 0; i < x; i++) { | ||
cin >> a[i]; | ||
} | ||
|
||
for (int i = 0; i < x; i++) { | ||
cin >> b[i]; | ||
} | ||
|
||
while (n--) { | ||
int maxBIndex = distance(b, max_element(b, b + x)); | ||
int minA = smallest(a, x); | ||
int minAIndex = findIndex(a, x, minA); | ||
|
||
if (minAIndex != -1 ) { | ||
swap(a[minAIndex], b[maxBIndex]); | ||
sort(a,a+x); | ||
sort(b,b+x); | ||
} | ||
} | ||
|
||
cout << accumulate(a, a + x, 0) << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include<iostream> | ||
#include<cstdlib> | ||
using namespace std; | ||
|
||
|
||
int main(){ | ||
|
||
int t,i,j,n,m; | ||
int k,a,b,x,y; | ||
cin>>t; //test cases. | ||
|
||
while(t--){ | ||
bool check = true; | ||
cin>>n>>m; //size of mall. | ||
cin>>k; //number of Vika's friends. | ||
cin>>x>>y; //Vika's location | ||
|
||
for(i=1;i<=k;i++){ | ||
cin>>a>>b; // location of each friend; | ||
if((abs(x-a) + abs(y-b)) % 2 == 0){ | ||
check = false; | ||
} | ||
} | ||
if(!check){ | ||
cout<<"NO"<<endl; | ||
} | ||
if(check){ | ||
cout<<"YES"<<endl; | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.