Posts

Showing posts from November, 2016

SPOJ Maximum Sum

//I am struggling //Just Not Good at it // Accepted //I am struggling //Just Not Good at it #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100010; const int inf = 1 << 30; int ar[high]; struct info {     LL pos, maxi; }tree[high * 4] , base; void update(int node, int b , int e , int i ,  LL x) {     if(i>e or i<b) return;     if(b == e)     {         tree[node].maxi = x;         tree[node].pos = i;         return;     }     int Left = node << 1;     int Right = Left + 1;     int mid = (b + e) >> 1;     update(Left , b , mid , i , x);     update(Right, mid+1, e , i , x

UVa 489 - Hangman Judge

//Accepted #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<char, bool>mpci; typedef map<int, bool>mpbi; const int mod = 1000007; const int high = 100; int main() {     fast;     //freopen("out.txt" , "w" , stdout);     int t , i , slen, glen , stroke=0 , cnt=0, j;     string sol , guess;     mpbi mp;     while(cin >> t and t > -1)     {         mp.clear();         cin >> sol >> guess;         stroke = cnt = 0;         slen = sol.length();         glen = guess.length();         bool f=false;         for(i=0; i<glen; i++)         {             f=false;             if(stroke

UVa 231 - Testing the CATCHER

// Longest Decreasing Sub sequence // Accepted #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100; const int inf = 2147483647; vll Mseq , I; int sol(int n) {     int i, len=0, lo=0, hi=0 , mid;     I.clear();     I.push_back(-inf);     for(i=1; i<=n; i++)     {         I.push_back(inf);     }     for(i=0; i<n; i++)     {         lo=0;         hi=len;         while(lo <= hi)         {             mid = (lo+hi) / 2;             if(I[mid] < Mseq[i]) lo=mid+1;             else hi=mid-1;         }         len = max(lo, len);         I[lo] = Mseq[i];     }     return len; } int main() {  

Dev Skill The Last Fibonacci

 ?? Detail: Program to find last digit of n’th Fibonnaci Number #include<bits/stdc++.h> using namespace std; typedef long long LL; #define sf scanf #define pf printf LL f[65] = {0}; LL fib(LL n) {     f[0] = 0;     f[1] = 1;     for (LL i = 2; i <= n; i++)     {         f[i] = (f[i-1] + f[i-2])%10;     }     return f[n]; } LL findLastDigit(LL n) {     fib(60);     return f[n%60]; } int main() {     int t , tc=0;     LL n;     sf("%d", &t);     while(t--)     {         memset(f , 0 , sizeof f);         sf("%lld", &n);         pf("Case %d: %lld is the last digit.\n", ++tc, findLastDigit(n));     }     return 0; }

UVa 13090 - Base of MJ

// the solution will be ans=N/D, but for the base it will be ans=(N-1)/D. // Because if N=30 and D=3, then the real answer will be 10 cause of we have total 10 numbers which summation of digits is divisible by 3 from 1 to 30 // But the problem is 30, 3+0=3 no doubt it is divisible by 3 but 30 is represented by base 31 which is not valid for N //because your N=30, so the answer will be (N-1) / D :) #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100; int main() {     int t , tc=0;     LL N , D, ans;     sf("%d", &t);     while(t--)     {         sf("%lld %lld", &N, &

Dev Skill Make It Palindrome

#include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf const int mx = 1005; char s[mx]; int dp[1005][1005]; int rec(int i, int j) {     if(i >= j) return 0;     if(dp[i][j] >= 0) return dp[i][j];     if(s[i] == s[j]) dp[i][j] = rec(i+1, j-1);     else return dp[i][j] = 1+min(rec(i+1, j) , rec(i, j-1));     return dp[i][j]; } int main() {     int t, ans, tc = 0, n;     sf("%d", &t);     while(t--)     {         sf("%s", &s);         memset( dp, -1, sizeof (dp) );         n = strlen(s);         ans = rec(0, n-1);         pf("Case %d: %d\n", ++tc, ans);     }     return 0; }

Dev Skill Hide and Seek

//Accepted #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<vector> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<char, bool>mpcb; const int mod = 1000007; const int high = 100003; const int inf = 100000005; char s[high]; mpcb mp; int ans=inf; void whole(int len) {     int i=1 , st=1 , cnt=0;     mp['F']=mp['M']=mp['J']=mp['T']=false;     while(i<=len)     {         if(!mp[s[i]])         {             cnt++;             mp[s[i]] = true;             if(cnt == 4)             {                 cnt=0;                 mp['F']=mp['M']=mp['J']

LightOJ 1080 - Binary Simulation

//Accepted #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100003; struct info {     LL sum, prop; }; info tree[3 * high]; void update(int node, int b, int e, int i, int j, int v) {     if(i>e or j<b or b > e) return;     if(b==i and e==j)     {         tree[node].sum+= (v * (e-b+1));         tree[node].prop+=v;         return;     }     int Left = node << 1;     int Right = Left + 1;     int mid = (b + e) >> 1;     if(j<=mid)     {         update(Left, b , mid, i , j , v);     }     else if(i>mid)     {         update(Right, mid+1, e, i, j , v);     }     else     {    

LightOJ 1093 - Ghajini

// Accepted // RMQ and RMQ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100003; const int inf = 1 << 30; LL ar[high], br[high], treemini[4 * high], treemaxi[4 * high]; void buildmini(int node, int b , int e) {     if(b > e) return;     if(b == e)     {         treemini[node] = ar[b];         return;     }     int Left = node << 1;     int Right = Left + 1;     int mid = (b + e) >> 1;     buildmini(Left, b , mid);     buildmini(Right, mid+1, e);     treemini[node] = min(treemini[Left] , treemini[Right]); } LL queryForMini(int node, int b , int e , int i, int j) {     if(i>

LightOJ 1164 - Horrible Queries

// Accepted // Modified #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int high = 100003; struct info {     LL sum, prop; }; info tree[high * 4]; void update(int node, int b , int e , int i, int j , int x) {     if(b==i and e==j)     {         tree[node].sum+=(x * (e - b + 1));         tree[node].prop+=x;         return;     }     int Left = node << 1;     int Right = (node << 1) + 1;     int mid = (b + e) >> 1;     if(j <= mid)     {         update(Left, b , mid , i , j , x);     }     else if(i > mid)     {         update(Right, mid+1 , e , i , j , x);     }     else     {         update(Left, b , mid, i ,

SPOJ HORRIBLE - Horrible Queries

//Next Codeforces Round #354 (Div. 2) // Accepted // Segment Tree (Lazy Propagation) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back //#define i64 long long typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int high = 1 << 18; struct info {     LL sum, prop; }; info tree[high]; void update(int node, int b , int e , int i , int j , LL x) {     if(i == b and j == e)     {         tree[node].sum+=(x * (e - b + 1));         tree[node].prop+=x;         return;     }     int Left = node << 1;     int R

Dev Skill Coin puzzle

//Next Codeforces Round #354 (Div. 2) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back //#define i64 long long #define high 30 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef vector<char>vc; typedef map<char, int>mpci; typedef set<char>sch; struct bmy {     char chboro;     int bcnt; }; bmy boro[30]; struct cmy {     char chchoto;     int ccnt; }; cmy choto[high]; bool cmpboro(bmy a , bmy b) {     return a.bcnt > b.bcnt; } bool cmpchoto(cmy a , cmy b) {     return a.ccnt < b.ccnt;