Skip to content

Commit d1fd3ca

Browse files
committed
08 JULY 2021
1 parent d6736c3 commit d1fd3ca

13 files changed

+421
-28
lines changed

codeshef/CIELRCPT.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
#define INF 10000009
5+
vector<int>menus;
6+
vector<int>dp(100002,-1);
7+
int f(int p){
8+
if(p==0){
9+
return 0;
10+
}
11+
if(p<0){
12+
return INF;
13+
}
14+
if(dp[p]!=-1)
15+
return dp[p];
16+
17+
int best = INF;
18+
for(auto a:menus){
19+
best = min(best,f(p-a)+1);
20+
dp[p]=best;
21+
}
22+
return best;
23+
}
24+
25+
void solve(){
26+
ll sum;
27+
cin>>sum;
28+
int t = f(sum);
29+
cout<<t<<endl;
30+
}
31+
int main(){
32+
int t;
33+
cin>>t;
34+
for(int i =11;i>=0;i--){
35+
menus.push_back(pow(2,i));
36+
}
37+
dp[0]=0;
38+
dp[1]=1;
39+
while(t--){
40+
solve();
41+
}
42+
return 0;
43+
}

codeshef/CORTSENT.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
bool checkGroup(string str){
5+
// finds its groups
6+
if(str[0] >='a' && str[0] <='m'){ // first group
7+
for(int i =1;i<str.length();i++){
8+
if(!(str[i] >='a' && str[i] <='m')){
9+
return false;
10+
}
11+
}
12+
return true;
13+
}
14+
else if (str[0] >='N' && str[0] <='Z'){
15+
for(int i =1;i<str.length();i++){
16+
if(!(str[i] >='N' && str[i] <='Z')){
17+
return false;
18+
}
19+
}
20+
return true;
21+
}
22+
23+
return false;
24+
}
25+
26+
void solve(){
27+
int n;
28+
cin>>n;
29+
vector<string> ar;
30+
for(int i =0;i<n;i++){
31+
string str;
32+
cin>>str;
33+
ar.push_back(str);
34+
}
35+
bool ans = true;
36+
for(auto a:ar){
37+
ans = ans && checkGroup(a);
38+
}
39+
if(ans){
40+
cout<<"YES\n";
41+
}else{
42+
cout<<"NO\n";
43+
}
44+
}
45+
46+
int main() {
47+
int t;
48+
cin>>t;
49+
while(t--){
50+
solve();
51+
}
52+
return 0;
53+
}

codeshef/CTIME.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
void solve(){
5+
ll n,k,f;
6+
cin>>n>>k>>f;
7+
vector<pair<int,int>>timeslots;
8+
for(int i=0;i<n;i++){
9+
ll start,end;
10+
cin>>start>>end;
11+
timeslots.push_back(make_pair(start,end));
12+
}
13+
ll ans = 0;
14+
vector<pair<int,int>>::iterator it = timeslots.begin();
15+
ll last_end = it->second;
16+
it++;
17+
for(; it != timeslots.end();it++){
18+
ans += it->first - last_end;
19+
last_end = it->second;
20+
}
21+
// cout<<ans<<" \t";
22+
if(ans >= k || f - last_end >= k ){
23+
cout<<"Yes\n";
24+
}else{
25+
cout<<"No\n";
26+
}
27+
}
28+
29+
30+
int main() {
31+
int t;
32+
cin>>t;
33+
while(t--){
34+
solve();
35+
}
36+
return 0;
37+
}

codeshef/EITA.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
void solve(){
5+
int d,x,y,z;
6+
cin>>d>>x>>y>>z;
7+
int s1 = 7 * x;
8+
int s2 = y *d + (7-d)*z;
9+
if(s1 > s2){
10+
cout<<s1<<endl;
11+
}else{
12+
cout<<s2<<endl;
13+
}
14+
}
15+
16+
17+
18+
int main() {
19+
int t;
20+
cin>>t;
21+
while(t--){
22+
solve();
23+
}
24+
return 0;
25+
}

codeshef/FAIRELCT.cpp

+25-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include<math.h>
88
using namespace std;
99
typedef long long ll ;
10-
ifstream fin("tests");
10+
// ifstream cin("tests");
1111
int increasing(int a,int b){
1212
return b>a;
1313
}
@@ -23,60 +23,59 @@ void print(vector<ll> ar){
2323
}
2424
void solve(){
2525
ll n,m;
26-
fin>>n>>m;
26+
cin>>n>>m;
2727
vector<ll> jackson(n,0);
2828
vector<ll> johnson(m,0);
2929
ll jackson_votes = 0;
3030
ll johnson_votes = 0;
3131

3232
for(int i =0;i<n;i++){
33-
fin>>jackson[i];
33+
cin>>jackson[i];
3434
}
3535
for(int i =0;i<m;i++){
36-
fin>>johnson[i];
36+
cin>>johnson[i];
3737
}
3838

3939
sort(jackson.begin(),jackson.end(),increasing);
4040
sort(johnson.begin(),johnson.end(),decreasing);
4141

42-
for(auto u:jackson){
43-
jackson_votes+=u;
42+
43+
for(auto a:jackson){
44+
jackson_votes+=a;
4445
}
45-
for(auto u:johnson){
46-
johnson_votes+=u;
46+
for(auto a:johnson){
47+
johnson_votes+=a;
4748
}
48-
int i =0;int j =0;
49-
int swaps =0;
50-
bool successful = false;
51-
while(i<jackson.size() && j< johnson.size()){
49+
50+
int swap = 0;
51+
int i=0;
52+
int j=0;
53+
bool f = false;
54+
while(i <= jackson.size() && j<=jackson.size()){
5255
if(jackson_votes > johnson_votes){
53-
successful = true;
56+
f = true;
5457
break;
5558
}
56-
jackson_votes-=jackson[i];
57-
jackson_votes+=johnson[j];
58-
59-
johnson_votes-=johnson[j];
60-
johnson_votes+=jackson[i];
61-
62-
int temp = jackson[i];
63-
jackson[i] = johnson[j];
64-
johnson[j] = temp;
59+
// cout<<jackson_votes<<" "<<johnson_votes<<endl;
60+
jackson_votes=jackson_votes-jackson[i] + johnson[j];
61+
johnson_votes=johnson_votes-johnson[j]+jackson[i];
62+
swap++;
6563
i++;
6664
j++;
67-
swaps++;
6865
}
69-
if(successful){
70-
cout<<swaps<<endl;
66+
67+
if(f){
68+
cout<<swap<<endl;
7169
}else{
7270
cout<<-1<<endl;
7371
}
72+
7473
}
7574

7675
int main() {
7776

7877
ll t;
79-
fin>>t;
78+
cin>>t;
8079
while(t--){
8180
solve();
8281
}

codeshef/HOOPS.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
void solve(){
5+
ll n;
6+
cin>>n;
7+
cout<<(n/2)+1<<endl;
8+
}
9+
10+
11+
12+
int main() {
13+
int t;
14+
cin>>t;
15+
while(t--){
16+
solve();
17+
}
18+
return 0;
19+
}

codeshef/KPATHQRY.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
vector<vector<int>>graph;
4+
vector<bool>visited;
5+
void print(){
6+
int i = 1;
7+
for(auto g:graph){
8+
cout<<i<<" ";
9+
for(auto a:g){
10+
cout<<(a+1)<<" ";
11+
}
12+
cout<<endl;
13+
i++;
14+
}
15+
}
16+
void dfs(int s ){
17+
visited[s]=true;
18+
cout<<(s+1)<<" ";
19+
for(auto a : graph[s]){
20+
if(!visited[a]){
21+
dfs(a);
22+
}
23+
}
24+
}
25+
void solve(){
26+
int n;
27+
cin>>n;
28+
graph = vector<vector<int>>(n);
29+
visited = vector<bool>(n,false);
30+
for(int i =1;i<=n-1;i++){
31+
int u,v;
32+
cin>>u>>v;
33+
u--;
34+
v--;
35+
graph[u].push_back(v);
36+
graph[v].push_back(u);
37+
}
38+
int q ;
39+
cin>>q;
40+
vector<int> vertices;
41+
while(q--){
42+
int k;
43+
cin>>k;
44+
vertices = vector<int>(k);
45+
for(int i =0;i<k;i++){
46+
cin>>vertices[i];
47+
}
48+
visited = vector<bool>(n);
49+
for(auto a : vertices){
50+
a--;
51+
// dfs(a);
52+
// cout<<endl;
53+
}
54+
}
55+
print();
56+
}
57+
58+
int main(){
59+
int t ;
60+
cin>>t;
61+
while(t--){
62+
solve();
63+
}
64+
return 0;
65+
}

codeshef/QUIZPLAG.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void solve(){
5+
int n,m,k;
6+
cin>>n>>m>>k;
7+
vector<int> ar;
8+
for(int i =0;i<k;i++){
9+
int a;
10+
cin>>a;
11+
ar.push_back(a);
12+
}
13+
map<int,int> _map ;
14+
for(int i =0;i<k;i++){
15+
if(ar[i]<=n){
16+
map<int,int >::iterator it = _map.find(ar[i]);
17+
if(it != _map.end()){
18+
it->second = it->second + 1;
19+
}else{
20+
_map.insert(make_pair(ar[i],1));
21+
}
22+
}
23+
}
24+
vector<int> plagers ;
25+
26+
for(map<int,int>::iterator it = _map.begin() ; it !=_map.end();it++){
27+
if(it->second > 1){
28+
plagers.push_back(it->first);
29+
}
30+
// cout<<it->first<<", "<<it->second<<"\t";
31+
}
32+
cout<<plagers.size();
33+
for(auto a:plagers){
34+
cout<<" "<<a<<" ";
35+
}
36+
cout<<endl;
37+
}
38+
39+
int main() {
40+
int t;
41+
cin>>t;
42+
while(t--){
43+
solve();
44+
}
45+
return 0;
46+
}

0 commit comments

Comments
 (0)