Posts

Showing posts from February, 2016

Uva 12459 - Bees' ancestors

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define m...

Uva 11424 - GCD - Extreme (I)

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #defin...

Uva 11426 - GCD - Extreme (II)

Rafik Forhad's Code // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size ...

Uva 11889 - Benefit

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define m...

Uva 10420 - List of Conquests

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define m...

Uva 11743 - Credit Check

#include<iostream> #include<cmath> #include<string> #include<cstdio> #include<cstring> using namespace std; typedef long long int LL; LL digit_sum(LL n) {     LL sum=0;     while(n)     {         sum+=(n%10);         n/=10;     }     return sum; } bool isCheck(LL n) {     return n%10; } int main() {     int t;     cin >> t;     getchar();     string s;     while(t--)     {         getline(cin,s);         LL len = s.size(),i,ds=0;         for(i=0;i<len;i+=2)         {             if(s[i]==' ')i++;   ...

Uva 1246 - Find Terrorists

// Verdict :: Accepted // Time :: 0.106 // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End.......

Uva 10042 - Smith Numbers

// Accepted // Time: 0.013 // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> #include<bitset> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size...

Uva 11340 - Newspaper

*** Solution with Brute Force ******* #include<cstdio> #include<cstring> #include<cmath> #include<iostream> using namespace std; #define sf scanf #define pf printf #define mx 1000100 typedef long long LL; struct my {     char c;     LL v; }; my ch[mx+9]; char mch[mx+9]; int main() {     int t;     sf("%d\n",&t);     while(t--)     {         //memset(ch,0,sizeof(ch));         //memset(mch,0,sizeof(mch));         int k;         LL i;         sf("%d\n",&k);         for(i=0;i<k;i++)         {             sf("%c%lld\n",&ch[i].c,...

Uva 11455 - Behold my quadrangle

#include<bits/stdc++.h> #define all(x) x.begin(),x.end() #define x first #define y second using namespace std; typedef long long LL; typedef vector<int>vi; typedef vector<long long>vll; int main() {     int t,i;     vll v;     cin >> t;     while(t--)     {         v.clear();         for(i=0;i<4;i++)         {             LL x;             cin >> x;             v.push_back(x);         }         sort(all(v));         //for(i=0;i<4;i++)cout << v[i] << " ";         LL mxi = *max_element(all(v));         //cout << mxi;         bool f=false;         for(i=0;i<3;i++)...

Uva 10994 - Simple Addition

*** At first i have just found that what is the reminder sum result from 1 to the last range. And then, found the reminder sum result from 1 to the first-1 range. And finally, I have have got the AC result to do Subtraction operation between them :) #include<bits/stdc++.h> using namespace std; typedef long long LL; // Digit_Sum (SPOJ) //int sum(int n) //{ //    if(n<10)return ( (n* (n+1)) / 2 ); //    int t=n,i=0,x; //    while(n/10 !=0) //    { //        //x=n%10; //        i++; //        n/=10; //    } // //    int p = powl(10,i); // //    return ( (n*i*45*p/10) + (n* (n-1) * p/2 ) + n * (t%p + 1) + sum(t%p)); //} // //int main() //{ //    int x,y; //    while(cin >> x >> y) //    { //   ...

Uva 443 - Humble Numbers

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 1500000 #define m...

Uva 10200 - Prime Time

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 1500000 #define mx5 ...

Uva 10179 - Irreducable Basic Fractions

// Accepted // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 150...

Uva 10990 - Another New Function

// Accepted // Time :: 1.049 // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 2000010...

UvaLive 4660 - A+B

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 1500000 #define m...

Uva 993 - Product of digits

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 1500000 #define mx5 ...

Uva 332 - Rational Numbers from Repeating Fractions

// Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 1500000 #define m...

Uva 10139 - Factovisors

// Accepted // Time :: 0.186    // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mset(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 200...

Uva 10852 - Less Prime

// Accepted // Header file begin #include<iostream> #include<cstdio> #include<cstring> #include<map> #include<string> #include<vector> #include<cmath> #include<cctype> #include<sstream> #include<set> #include<list> #include<stack> #include<utility> #include<queue> #include<algorithm> #include<cstdlib> // End //.......... // Macro #define sf scanf #define pf printf #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define mem(c,v) memset(c,v,sizeof(c)) #define cp(a) cout<<" "<<a<<" " #define nl puts("") #define sq(x) ((x)*(x)) #define all(x) x.begin(),x.end() #define reall(x) x.rbegin(),x.rend() #define s_wap(x,y) x^=y;y^=x;x^=y; #define sz size() #define gc getchar() #define pb push_back #define freader freopen("input.txt","r",stdin) // End......... // Size #define mx7 20000100 #define mx6 1500...