forked from gopalgoel19/Competitive-Programming-Solutions
-
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.
3 codechef problems (gopalgoel19#24)
* Codechef October Challenge 17 perfcont.cpp * Added 3 more problems in codechef * Delete perfcont.cpp
- Loading branch information
1 parent
4cd25a4
commit d203c10
Showing
3 changed files
with
123 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,56 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define INF (int)1e9 | ||
#define EPS 1e-9 | ||
#define REP(i, a, b) for(int i = a; i < b; ++i) | ||
#define PB push_back | ||
#define MP make_pair | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> PII; | ||
// vector<int> VI,chef,chefas; | ||
typedef vector<string> VS; | ||
typedef vector<PII> VII; | ||
|
||
const float PI = 3.1415926535897932384626433832795; | ||
const int MOD = 1000000007; | ||
|
||
int main() | ||
{ | ||
int t,i,j,n,m,temp; | ||
|
||
scanf("%d",&t); | ||
while(t--){ | ||
scanf("%d %d",&n,&m); | ||
vector<int> VI,chef,chefas; | ||
for (i = 1; i <= n; i++) VI.push_back(i); | ||
|
||
for (i = 1; i <= m; i++){ | ||
scanf("%d",&temp); | ||
VI.erase(std::remove(VI.begin(), VI.end(), temp), VI.end()); | ||
} | ||
|
||
sort(VI.begin(),VI.end()); | ||
|
||
for(i=0; i < VI.size(); i++){ | ||
if (i%2==0){ | ||
chef.push_back(VI[i]); | ||
} | ||
else { | ||
chefas.push_back(VI[i]); | ||
} | ||
} | ||
for (i = 0; i < chef.size(); i++){ | ||
printf("%d ",chef[i]); | ||
} | ||
printf("\n"); | ||
for (i = 0; i < chefas.size(); i++){ | ||
printf("%d ",chefas[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
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,42 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define INF (int)1e9 | ||
#define EPS 1e-9 | ||
#define REP(i, a, b) for(int i = a; i < b; ++i) | ||
#define PB push_back | ||
#define MP make_pair | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> PII; | ||
typedef vector<int> VI; | ||
typedef vector<string> VS; | ||
typedef vector<PII> VII; | ||
|
||
const float PI = 3.1415926535897932384626433832795; | ||
const int MOD = 1000000007; | ||
|
||
int main() | ||
{ | ||
int t,n; | ||
scanf("%d",&t); | ||
while(t--){ | ||
scanf("%d",&n); | ||
int arr[n]; | ||
for (int i = 0; i < n; i++) | ||
scanf("%d",&arr[i]); | ||
sort(arr,arr+n); | ||
|
||
int min = arr[1] - arr[0]; | ||
|
||
for (int i = 0; i < n-1; ++i){ | ||
int temp = arr[i+1] - arr[i]; | ||
if (temp<min){ | ||
min = temp; | ||
} | ||
} | ||
printf("%d\n",min); | ||
} | ||
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,25 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define REP(i, a, b) for(int i = a; i < b; ++i) | ||
|
||
int main() | ||
{ | ||
int t,n,i,j,k,val; | ||
cin >> t; | ||
while(t--){ | ||
cin >> n; | ||
int arr[n+1]; | ||
REP(i,1,n+1)scanf("%d",&arr[i]); | ||
scanf("%d",&k); | ||
val = arr[k]; | ||
sort(arr+1,arr+n+1); | ||
REP(i,1,n+1) | ||
if (val == arr[i]){ | ||
cout << i << endl; | ||
break; | ||
} | ||
} | ||
return 0; | ||
} |