<repo_name>priyanshujain/STARTX2016<file_sep>/SRTX16E.cpp
/*
Author - <NAME>
*/
//#include <atomic>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cassert>
using namespace std;

#define mod 1000000007
#define inf 100000000000000000LL
struct _{ios_base::Init i; _(){
  cin.sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}}_ ;
typedef long long int  ll;
#define pll pair<ll,ll>
#define ict int t;cin>>t;while(t--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<=b;i++)
#define endl '\n'

const int N = 2001;

int m, n;
double dp[N][N];

int main() {

  std::ifstream in("small.in");
    std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    std::cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!

    std::ofstream out("small.out");
    std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!

	for (int i = 1; i < N; i++) dp[i][0] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 1; j < N; j++) {
			if (i > j) {
				double p1 = (double)i / (i + j);
				double p2 = 1 - p1;
				dp[i][j] = dp[i-1][j] * p1 + dp[i][j-1] * p2;
			}
		}
	}
	int t, tt;
	cin>>t;
	for (int tt = 1; tt <= t; tt++) {
		cin>>n>>m;
    std::cout.setf(std::ios::fixed, std::ios::floatfield);
    cout<<std::setprecision(6);
		cout<<dp[n][m]<<endl;
	}
	return 0;
}
<file_sep>/SRTX16A.cpp
/*
Author - <NAME>
*/
//#include <atomic>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cassert>
using namespace std;
#define REP(i,n) for (int i = 1; i <= n; i++)
typedef long long ll;

int main() {
    std::ifstream in("in.txt");
    std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    std::cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!

    std::ofstream out("out.txt");
    std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
  int t;
  cin>>t;
  for (size_t i = 0; i < t; i++) {
    int N,M;
    cin>>N>>M;
    cout<<N%M<<endl;
  }
  return 0;
}
<file_sep>/SRTX16C.cpp
#include<algorithm>
#include<iostream>
#include<fstream>

#include<cmath>

using namespace std;

int main()
{
  std::ifstream in("in.txt");
  std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf
  std::cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!

  std::ofstream out("out.txt");
  std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
  std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
  int test,n;
  cin>>test;
  while(test--)
  {
    cin>>n;
    int a[n+3];
    for(int i=0;i<n;i++)cin>>a[i];
    a[n] = a[n+1] = a[n+2] = 1;
    int oneStreak = 0, current = 0, jumps = 0;
    bool flag = true;
    while(current != n-1)
    {
        if(a[current + 3] == 0)
        {
            current += 3;
            jumps++;
        }
        else if(a[current + 2] == 0)
        {
          current += 2;
          jumps++;
        }
        else if(a[current + 1] == 0)
        {
          current += 1;
          jumps++;
        }
        else
        {
          flag = false;
          break;
        }
      }
      if(flag)
        cout<<jumps<<"\n";
      else
        cout<<"Never Give Up\n";
    }
  }
<file_sep>/SRTX16D.cpp
/*
** Author - <NAME> (easy_)
*/
#include<iostream>
#define MAX 105
#define ll int
using namespace std;
ll n, m, xe, ye, xi, yi, xw, yw;
bool cave[MAX][MAX];
void flood(ll matrix[MAX][MAX], ll x, ll y, ll xe, ll ye, ll n)
{
    if(!cave[x][y]) //if it's a wall
        return;
    if(matrix[x][y] == 0 || matrix[x][y] > n)
    {
        matrix[x][y] = n;
        if(x == xe && y == ye)
        {
            return;
            //no need to flood more
        }
        else
        {
            n++;
            flood(matrix, x+1, y, xe, ye, n);
            flood(matrix, x-1, y, xe, ye, n);
            flood(matrix, x, y+1, xe, ye, n);
            flood(matrix, x, y-1, xe, ye, n);
        }
    }
}
ll floodWater()
{
    ll mat[MAX][MAX] = {0};

    flood(mat, xw, yw, xe, ye, 1);
    /*
    cout<<"WATER FLOODED\n";
    for(int i = 0; i < n+2; i++)
    {
        for(int j = 0; j < m+2; j++)
        {
            if(mat[i][j] == -1)
                cout<<"x ";
            else
                cout<<mat[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    return mat[xe][ye];
}
ll runSam()
{
    ll mat[MAX][MAX] = {0};

    flood(mat, xi, yi, xe, ye, 1);
    /*
    cout<<"SAM FLOODED\n";
    for(int i = 0; i < n+2; i++)
    {
        for(int j = 0; j < m+2; j++)
        {
            if(mat[i][j] == -1)
                cout<<"x ";
            else
                cout<<mat[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    return mat[xe][ye];
}
int main()
{
    ll cases;
    char c;
    cin>>cases;
    while(cases--)
    {
        cin>>n>>m>>xe>>ye>>xi>>yi>>xw>>yw;
        for(ll i = 1; i <= n ; i++)
        {
            for(ll j = 1; j <= m; j++)
            {
                cin>>c;
                //true if path, false if wall
                if(c == '0')
                    cave[i][j] = true;
                else
                    cave[i][j] = false;
            }
        }
        for(ll i = 0; i < n+2; i++)
        {
            cave[i][0] = false;
            cave[i][m+1] = false;
        }
        for(ll i = 0; i < m+2; i++)
        {
            cave[0][i] = false;
            cave[n+1][i] = false;
        }
        /*
        cout<<"CAVE\n";
        for(ll i = 0; i <= n+1 ; i++)
        {
            for(ll j = 0; j <= m+1; j++)
            {
                cout<<(cave[i][j]?"_":"x")<<" ";
            }
            cout<<endl;
        }*/
        ll w = floodWater();
        ll s = runSam();
        if(s <= w || w == 0)
            cout<<s-1<<"\n";
        else
            cout<<"-1\n";
    }
    return 0;
}
