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
#include<algorithm> | |
#include<iostream> | |
#include<cstring> | |
using namespace std; | |
template<class T> | |
struct point{ | |
T x,y; | |
point &operator+=(const point &a){ x+=a.x; y+=a.y; } | |
point &operator-=(const point &a){ x-=a.x; y-=a.y; } |
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
class ChristmasTreeDecorationDiv2 { | |
public: | |
int solve(vector<int> col, vector<int> x, vector<int> y) { | |
int cnt=0; | |
for(int i=0;i<x.size();i++) | |
{ | |
if(col[x[i]-1]!=col[y[i]-1]) | |
cnt++; | |
} | |
return cnt; |
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
class NumberGameAgain { | |
public: | |
long long solve(int k, vector<long long> table) { | |
const long long int MAX=((long long)2<<(k-1)); | |
sort(table.begin(), table.end()); | |
long long int cnt=MAX-2; | |
for(int i=0;i<table.size();i++) | |
{ | |
long long int ii=table[i]/2; | |
int tree=1; |
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
class BuyingTshirts { | |
public: | |
int meet(int T, vector<int> Q, vector<int> P) { | |
int ans=0; | |
int qq=0; | |
int pp=0; | |
for(int i=0;i<Q.size();i++) | |
{ | |
qq+=Q[i]; |
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
struct point | |
{ | |
point() : x(0), y(0) { } | |
point(double x_, double y_) : x(x_), y(y_) { } | |
double x, y; | |
}; | |
point operator-(const point& a, const point& b) { return point(a.x - b.x, a.y - b.y); } | |
point operator+(const point& a, const point& b) { return point(a.x + b.x, a.y + b.y); } | |
typedef point vector2d; |
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
class ShufflingCardsDiv2 { | |
public: | |
string shuffle(vector<int> permutation) { | |
const int n=permutation.size(); | |
vector<int> ga,gb; | |
for(int i=0;i<n;i++) | |
{ | |
if(i%2==0) | |
ga.push_back(permutation[i]); |
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
inline int toInt(std::string s) {int v; std::istringstream sin(s);sin>>v;return v;} | |
class ForgetfulAddition { | |
public: | |
int minNumber(string expression) { | |
int ans=9999999; | |
for(int i=1;i<expression.size();i++) | |
{ |
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
class LightSwitchingPuzzle { | |
public: | |
int minFlips(string state) { | |
int ans=0; | |
for(int i=0;i<state.size();i++) | |
{ | |
if(state[i]=='Y') | |
{ | |
ans++; | |
for(int j=i;j<state.size();j+=(i+1)) |
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
class TheKingsArmyDiv2 { | |
public: | |
int getNumber(vector<string> state) { | |
int ans=2; | |
int dx[]={1,-1,0,0}; | |
int dy[]={0,0,1,-1}; | |
for (int i=0; i < state.size(); i++) { | |
for (int j=0; j < state[i].size(); j++) { | |
if(state[i][j]=='H') | |
{ |
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
class TheKingsFactorization { | |
public: | |
vector<long long> getVector(long long N, vector<long long> primes) { | |
for (int i=0; i<primes.size() ;i++) { | |
N/=primes[i]; | |
} | |
for (int n=2; n<1000000&&N>1; n++) { | |
if(N%n==0) |