Posts

Showing posts from October, 2016

Codeforces Tricky Sum

//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 high 45 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; struct my {     LL p, psum; }; my ar[high]; void store() {     int i=0;     ar[0].p = 1;     ar[0].psum = -1;     for(i=1; i<35; i++)     {         ar[i].p = powl(2 , i);         ar[i].psum = ar[i-1].psum - ar[i].p;     }     //for(i=0; i<35; i++) cout << ar[i].p << " " << ar[i].psum << "; "; } int khoj(int lo, int

Codeforces Bear and Poker

//#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 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int n , i;     LL x;     vll v;     while(cin >> n)     {         v.clear();         for(i=0; i<n; i++)         {             cin >> x;             while(x % 2 == 0)             {                 x /= 2;             }             while(x % 3 == 0)             {                 x /= 3;             }             v.push_back(x);         }         //for(i=0; i<n; i++) cout << v[i] << " ";         bool f=true;         f

Codeforces Lucky Division

//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 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; bool digitcheck(int n) {     while(n)     {         if(n % 10 != 4)         {             if(n % 10 != 7)             {                 return false;             }         }         n/=10;     }     return true; } bool productcheck(int n) {     if(n % 4 == 0) return true;     else if(n % 7 == 0) return true;     else if(n % 47 == 0) return true;     else if

LightOJ 1082 - Array Queries

// Straight forward RMQ (ST) //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 100005 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int ar[high] , tree[high * 4]={-1}; void build(int node , int b , int e) {     if(b == e)     {         tree[node] = b;         //return;     }     else     {         int left = node * 2;         int right = (node * 2) + 1;         int mid = (b + e) / 2;         build(left, b , mid);         build(right , m

LightOJ 1087 - Diablo

// Although my Run time is not good but it is peculiar that I have got // AC using Vector erase function // try with Segment Tree or BIT or BST //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 100005 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<int, int>mpii; int main() {     int t , tc=0 , n , q , i , x;     vii v;     char ch[3];     sf("%d", &t);     while(t--)     {         v.clear();         sf(&qu

UVa 12032 - The Monkey and the Oiled Bamboo

//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 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     //freopen("out.txt" , "w" , stdout);     int t , tc=0 , n , x , i , k = -1 , tmpk;     vii v;     cin >> t;     while(t--)     {         v.clear();         k = -1;         cin >> n;         for(i=0; i<n; i++)         {             cin >> x;             v.push_back(x);         }         k =

LightOJ 1113 - Discover the Web

//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 fixed "http://www.lightoj.com/" typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef stack<string>stkstr; typedef queue<string>qustr; int main() {     fast;     //freopen("out.txt" , "w" , stdout);     int t , tc=0;     cin >> t;     while(t--)     {         cout << "Case " << ++tc << ":\n";         stkstr bs

LightOJ 1276 - Very Lucky Numbers

#include<bits/stdc++.h> using namespace std; #define high 1000000000000 #define sf scanf #define pf printf typedef long long LL; typedef vector<LL>vll; typedef set<LL>sll; vll l_numbers , ans , tmp; sll s; sll::iterator it; LL ar[500000]; void veryLucky(int indx, LL m) {     LL val;     int l_size = l_numbers.size();     if(m > high or m <= 0)     {         return;     }     if(m > 1 and m<=high)     {         s.insert(m);         l_numbers.push_back(m);     }     for(int i=indx; i<l_size; i++)     {         val = l_numbers[i] * m;         if(val > high or val <= 0)         {             break;         }         veryLucky(i, val);     } } void lucky() {     s.insert(4);     s.insert(7);     LL sum = 0 , iv=40, vii=70;     int sz = 2 , i , j;     ar[1] = 4;     ar[2] = 7;     while(iv<=high and vii<=high)     {         for(i=1; i<=2 * sz; i++)         {             if(i > sz)             {                 sum = vii + ar[i - sz];       

LightOJ 1234 - Harmonic Number

// Harmonic Series // 1 + 1/2 + 1/3 + ... + 1/n; // Find the nth sum of Harmonic numbers #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 1000000 #define EulerGamma 0.57721566490153286060651209; typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; double ar[high]; void harmonic() {     int i;     ar[1] = 1.0;     ar[2] = ar[1] + 0.5;     for(i=3; i<=high; i++)     {         ar[i] = (ar[i-1] + (1.0 / (double(i)))) * 1.0;     }     //for(i=1; i<=10; i++) cout << ar[i] <

Uva 12908 The Book Thief

//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 i64 long long #define high 100000005 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; vll v; void sum() {     int i;     v.push_back(0);     for(i=1; i<14144 ; i++)     {         v.push_back(v[i-1] + i);     } } int khojUpore(int lo, int hi, LL itm) {     int mid;     while(lo <= hi)     {         mid = (lo + hi) / 2;         if(v[mid] == itm)         {             lo = mid+1;         }         else if(v[mid] > itm)         {      

LightOJ 1112 - Curious Robin Hood

Reference: শাফায়াতের ব্লগ //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 high 100005 //#define i64 long long typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int ar[high]; LL tree[high * 3]; void build(int node, int b , int e) {     if(b == e)     {         tree[node] = ar[b];         return;     }     int left = node * 2;     int right = (node * 2) + 1;     int mid = (b + e) / 2;     build(left , b , mid);     build(right, mid+1, e);     tree[node] = tree[left] + tree[right]; } int que

LightOJ 1008 - Fibsieve`s Fantabulous Birthday

//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 i64 long long typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int t , tc=0;     LL s , m , n , k, col, row;     cin >> t;     while(t--)     {         cin >> s;         n = ceil(sqrt(s));         m = n*n;         k = m - n + 1; // find the sequence 1 , 3, 7, 13, 21         cout << "Case " << ++tc << ": ";         if(!(n&1))         {             if(s > k)  

LightOJ 1261 - K-SAT Problem

//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 i64 long long #define high 50 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<int, bool>mpbi; int ar[high][high]; int main() {     fast;     int n , m , k , t , tc=0 , i , j , p , x , tmp;     mpbi mp;     cin >> t;     while(t--)     {         //cout << n << " " << m << " " << k;         mp.clear();         cin >> n >> m >> k;         for(i=0; i<

LightOJ 1331 - Agent J

//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 i64 long long #define pi acos(-1.0) typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int t, tc=0;     double r1, r2, r3 , triangle_area , area_setors , a , b , c , s, area_sector_A , area_sector_B, area_sector_C, A , B , C;     //cin >> t;     sf("%d", &t);     while(t--)     {         //cin >> r1 >> r2 >> r3;         sf("%lf %lf %lf", &r1, &r2, &r3);    

LightOJ 1249 - Chocolate Thief

//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 i64 long long #define high 105 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<LL , multiset<string> >mmsll; typedef vector<string>vs; struct my {     string s ;     LL x; }; my ar[high]; bool cmp(my a , my b) {     return a.x > b.x; } int main() {     fast;     int t,tc=0, n , i , l , w ,h ;     cin >> t;     while(t--)     {         cin >> n;         for(i=0; i<n; i++)         {            

LightOJ 1338 - Hidden Secret!

/*/*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 i64 long long #define high 105 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int t , tc=0, i, eklen, duilen;     string ek, dui , first="" , second="";     cin >> t;     cin.ignore();     while(t--)     {         getline(cin , ek);         getline(cin, dui);         first = second = "";         eklen=ek.length();         duilen = dui.length();         for(i=0; i<eklen;

Dev Skill Another Bigmod Problem

//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("") typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; LL multiple(LL a, LL b, LL c) {     if(b==0) return 0;     LL x = multiple(a , b/2, c)%c;     if(b%2==0)     {         return (x%c+x%c)%c;     }     else     {         return ((a%c + (x+x)%c))%c;     } } LL bigmod(LL a, LL b, LL c) {     if(b==0) return 1;     LL x = bigmod(a , b/2, c)%c;     if(b%2==0)     {         return multiple(x , x , c)%c;     }     else     {         return (multiple(a%c , multiple(x , x ,

Dev Skill “What is that” and Prime

//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 high 1000010 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int prime[(high>>6) + 1], prm[(high>>1) +9] , plen=0; #define setbit(n) (prime[n>>6] |= (1 << ((n >> 1) & 31))) #define checkbit(n) (prime[n>>6] & (1 << ((n >> 1) & 31))) void sieve() {     LL i,j;     for(i=3; i*i<high; i+=2)     {         if(!checkbit(i))         {             for(j=i*i; j<high; j+=(2*i))          

Codeforces A. Broken Clock

//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("") typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; void twelve(int h , int m, char ch) {      bool hf=false, mf=false;      string uh="10" , um="0";      if(m>=0 and m<=9)      {          um+=char(m+'0');      }      else      {          um = "";          string tmp="";          stringstream ss;          ss << m;          ss >> tmp;          um+=tmp;      }      if(h>=1 and h<=9)  

Codeforces B. Verse Pattern

//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("") typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<char, int>mpci; int main() {     fast;     int n , i , x , len , j , cnt;     string s;     vii v;     mpci mp;     while(cin >> n)     {         v.clear();         mp.clear();         for(i=0; i<n; i++)         {             cin >> x;             v.push_back(x);         }         bool f=true;         cin.ignore();         for(i=0; i<n; i++)         {             s.c

Codeforces A. One-dimensional Japanese Crossword

//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("") typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<char , bool>mpbc; int main() {     fast;     int n , cnt=0 , i , len=0 , vlen=0 , group=0;     string s;     vii v;     mpbc mp;     while(cin >> n)     {         v.clear();         mp.clear();         cin >> s;         len = s.length();         cnt=0;         group=0;         char ch='B';         for(i=0; i<len+1; i++)         {             if(s[i] == 'B