Uva 11559 – Event Planning

Problem Link Solution :- Event Planning C++ /*--------------------------------------------*/ //Problem Setter: Shahriar Manzoor //Uva Problem No: 11559 //Problem Name : Event Planning //Type : Ad hoc //Author : Shipu Ahamed //University : BUBT //E-mail : shipuahamed01@gmail.com /*--------------------------------------------*/ #include<stdio.h> int main() { long frnd,bud,hotel,week,amount,cost=15000000,b,p,visit,i,j,room; while(scanf("%ld%ld%ld%ld",&frnd,&bud,&hotel,&week)==4) { for(i=0;i<hotel;i++) { scanf("%ld",&amount); for(j=0;j<week;j++) { scanf("%ld",&room); p=0; if(room>=frnd) { p=amount*frnd; if(cost>p) cost=p; } } } if(cost>bud) printf("stay homen"); else printf("%ldn",cost); cost=15000000; } return 0; } 123456789101112131415161718192021222324252627282930313233343536373839404142 /*--------------------------------------------*///Problem Setter: Shahriar Manzoor//Uva Problem No: 11559//Problem Name  : Event Planning//Type          : Ad hoc//Author        : Shipu Ahamed//University    : BUBT//E-mail        : shipuahamed01@gmail.com/*--------------------------------------------*/ #include<stdio.h>int main(){    long frnd,bud,hotel,week,amount,cost=15000000,b,p,visit,i,j,room;    while(scanf("%ld%ld%ld%ld",&frnd,&bud,&hotel,&week)==4)    {        for(i=0;i<hotel;i++)        {            scanf("%ld",&amount);            for(j=0;j<week;j++)            {                scanf("%ld",&room);                p=0;                if(room>=frnd)                {                    p=amount*frnd;                    if(cost>p)                    cost=p;                }            }        }            if(cost>bud)            printf("stay homen");            else            printf("%ldn",cost);            cost=15000000;          }     return...

Uva 694 – The Collatz Sequence

Problem Link Solution :- The Collatz Sequence C++ /*------------------------------------------------*/ //Problem Setter: Miguel Revilla //Uva Problem No: 694 //Problem Name : The Collatz Sequence //Type : Ad hoc //Author : Shipu Ahamed //University : BUBT //E-mail : shipuahamed01@gmail.com /*--------------------------------------------*/ #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream> #include<cctype> #include<map> #include<stack> #include<cstdlib> #include <queue> #include <vector> #include<algorithm> #define ll long long #define sc scanf #define pf printf #define Pi 2*acos(0.0) using namespace std; int main() { ll n,e,c,a; int no=0; while(sc("%lld %lld",&n,&e)==2) { if(n<0&&e<0) break; c=0; a=n; while(n<=e) { if(n==1) { c++; break; } else if(n%2==0) { c++; n/=2; } else if(n%2==1) { c++; n=n*3+1; } } pf("Case %d: A = %lld, limit = %lld, number of terms = %lldn", ++no,a,e,c); } return 0; } 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 /*------------------------------------------------*///Problem Setter: Miguel Revilla //Uva Problem No: 694//Problem Name  : The Collatz Sequence//Type          : Ad hoc//Author        : Shipu Ahamed//University    : BUBT//E-mail        : shipuahamed01@gmail.com/*--------------------------------------------*/ #include<cstdio>#include<cstring>#include<string>#include<cmath>#include<iostream>#include<cctype>#include<map>#include<stack>#include<cstdlib>#include <queue>#include <vector>#include<algorithm>#define ll long long#define sc scanf#define pf printf#define Pi 2*acos(0.0)using namespace std;int main(){   ll n,e,c,a;   int no=0;   while(sc("%lld %lld",&n,&e)==2)   {       if(n<0&&e<0)       break;       c=0;       a=n;       while(n<=e)       {           if(n==1)           {               c++;               break;           }           else if(n%2==0)           {               c++;               n/=2;           }           else if(n%2==1)           {               c++;               n=n*3+1;           }        }       pf("Case %d: A = %lld, limit = %lld, number of terms = %lldn",          ++no,a,e,c);   }    return 0;}...

Uva 11466 – Largest Prime Divisor

Problem Link Solution :- C++ /****************************************************************** *** Problem No : 11466 *** *** Problem Name : Largest Prime Divisor *** *** Type : Number theory *** *** Author : Shipu Ahamed (Psycho Timekiller) *** *** E-mail : shipuahamed01@gmail.com *** *** University : BUBT,Dept. of CSE *** *** Team : BUBT_Psycho *** *** Facebook : http://www.facebook.com/DeesheharaShipu *** ******************************************************************/ #include<algorithm> #include<iostream> #include<iterator> #include<cassert> #include<sstream> #include<fstream> #include<cstdlib> #include<cstring> #include<utility> #include<complex> #include<string> #include<cctype> #include<cstdio> #include<vector> #include<bitset> #include<stack> #include<queue> #include<cmath> #include<deque> #include<list> #include<set> #include<map> #define ll long long #define sc scanf #define pf printf #define pi 2*acos(0.0) #define ft first #define se second #define Max 10001000 #define st(s) s.size(); #define r(input) freopen("input.txt","r",stdin) #define w(output) freopen("output.txt","w",stdout) #define maxall(v) *max_element(v.begin(),v.end()) #define minall(v) *min_element(v.begin(),v.end()) #define Sort(v) sort(v.begin(),v.end()) #define un(v) Sort(v), v.erase(unique(v.begin(),v.end()),v.end()) #define cover(a,d) memset(a,d,sizeof(a)) using namespace std; bool prime[Max]; ll p[1000000],k=0; void sieve() { ll i,j; prime[1]=false; for(i=2;i<=10001000;i++) { if(prime[i]!=false) { p[k++]=i; for(j=i+i;j<=10001000;j+=i) { prime[j]=false; } } } } int main() { cover(prime,true); sieve(); ll n,i,j,a; int c; while(scanf("%lld",&n)==1) { if(n==0) break; if(n<0) n*=-1; for(i=0,c=0;i<k&&n>1&&p[i]<=n;i++) { if(n%p[i]==0) { //pf("%lldn",p[i]); c++; while(n>1 && n%p[i]==0) { n/=p[i]; } a=p[i]; } if(n==1) break; } if(n==1) { if(c>1) printf("%lldn",a); else printf("-1n"); } else { if(c>0) printf("%lldn",n); else printf("-1n"); } } } /*input 1000 20 32 1 -1 -10 61536575712 8172385155 90090 12 199900 -26356 -32 8748234 23462482 23457826407 234872648001 436598 345387 2347 17 37 0 output: 5 5 -1 -1 -1 5 324889 16509869 13 3 1999 599 -1 113 690073 77418569 348559 521 16447 -1 -1 -1 */ 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 /*********************************************************************   Problem No    : 11466                                     ******   Problem Name  : Largest Prime Divisor                     ******   Type          : Number theory                             ******   Author        : Shipu Ahamed (Psycho Timekiller)          ******   E-mail        : shipuahamed01@gmail.com                  ...

Uva 11278 – One-Handed Typist

Problem Link Solution :- One-Handed Typist C++ /*------------------------------------------------*/ //Problem Setter: Sonny Chan //Uva Problem No: 11278 //Problem Name : One-Handed Typist //Type : Ad hoc. //Author : Shipu Ahamed //University : BUBT //E-mail : shipuahamed01@gmail.com /*--------------------------------------------*/ #include<algorithm> #include<iostream> #include<iterator> #include<cassert> #include<sstream> #include<fstream> #include<cstdlib> #include<cstring> #include<utility> #include<complex> #include<string> #include<cctype> #include<cstdio> #include<vector> #include<bitset> #include<stack> #include<queue> #include<cmath> #include<deque> #include<list> #include<set> #include<map> #define sc scanf #define pf printf #define ll long long #define pi 2*acos(0.0) #define ff first #define se second #define inf (1<<30) //infinity value #define pb push_back #define mod 1000000007 #define ST(v) sort(v.begin(),v.end()) #define cover(a,d) memset(a,d,sizeof(a)) #define input freopen("in.txt","r",stdin) #define output freopen("out.txt","w",stdout) #define maxall(v) *max_element(v.begin(),v.end()) #define minall(v) *min_element(v.begin(),v.end()) #define un(v) ST(v), v.erase(unique(v.begin(),v.end()),v.end()) using namespace std; ll gcd(ll a, ll b) { if (b==0) return a; return gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } bool cmp(ll a,ll b) { return a > b; } int main() { string a="`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./"; string ares="`123qjlmfp/[]456.orsuyb;=\789aehtdck-0zx,inwvg'"; string b="~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?"; string bres="~!@#QJLMFP?{}$%^>ORSUYB:+|&*(AEHTDCK_)ZX<INWVG""; string s; while(getline(cin,s)) { int l=s.size(); int l1=a.size(); int l2=b.size(); int j=0; while(l!=0) { if(s[j]==' ') { pf("%c",s[j++]); l--; } for(int i=0;i<l1;i++) { if(s[j]==a[i]) { pf("%c",ares[i]); l--; j++; } } for(int i=0;i<l1;i++) { if(s[j]==b[i]) { pf("%c",bres[i]); l--; j++; } } } pf("n"); } return 0; } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 /*------------------------------------------------*///Problem Setter: Sonny Chan//Uva Problem No: 11278//Problem Name  : One-Handed Typist//Type          : Ad hoc.//Author        : Shipu Ahamed//University    : BUBT//E-mail        : shipuahamed01@gmail.com/*--------------------------------------------*/ #include<algorithm>#include<iostream>#include<iterator>#include<cassert>#include<sstream>#include<fstream>#include<cstdlib>#include<cstring>#include<utility>#include<complex>#include<string>#include<cctype>#include<cstdio>#include<vector>#include<bitset>#include<stack>#include<queue>#include<cmath>#include<deque>#include<list>#include<set>#include<map> #define sc scanf#define pf printf#define ll long long#define pi 2*acos(0.0) #define ff first#define se second#define inf (1<<30)                                              //infinity value#define pb push_back#define mod  1000000007#define ST(v) sort(v.begin(),v.end())#define cover(a,d) memset(a,d,sizeof(a))#define input freopen("in.txt","r",stdin)#define output freopen("out.txt","w",stdout)#define maxall(v) *max_element(v.begin(),v.end())#define minall(v) *min_element(v.begin(),v.end())#define un(v) ST(v), v.erase(unique(v.begin(),v.end()),v.end()) using namespace std; ll gcd(ll a, ll b){ if (b==0) return a; return gcd(b, a%b);} ll lcm(ll a,...

Uva 10324 – Zeros and Ones

Problem Link Solution :- Zeros and Ones C++ /*------------------------------------------------*/ //Uva Problem No: 10324 //Problem Name : Zeros and Ones //Type : Ad hoc //Author : Shipu Ahamed //University : BUBT //E-mail : shipuahamed01@gmail.com /*--------------------------------------------*/ #include<stdio.h> #include<string.h> int main() { char s[1000015]; int t=1,n,p1,p2,i,c,tem; while(scanf("%s",s)==1) { if(strcmp(s,"n")==0) break; scanf("%d",&n); printf("Case %d:n",t++); while(n--) { scanf("%d%d",&p1,&p2); if(p1>p2) { tem=p1; p1=p2; p2=tem; } if(p1==p2) { printf("Yesn"); continue; } for(i=p1;i<p2;i++) { if(s[i]==s[i+1]) c=1; else { c=0; break; } } if(c==1) printf("Yesn"); else printf("Non"); } } return 0; } 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 /*------------------------------------------------*///Uva Problem No: 10324//Problem Name  : Zeros and Ones//Type          : Ad hoc//Author        : Shipu Ahamed//University    : BUBT//E-mail        : shipuahamed01@gmail.com/*--------------------------------------------*/ #include<stdio.h>#include<string.h> int main(){    char s[1000015];    int t=1,n,p1,p2,i,c,tem;    while(scanf("%s",s)==1)    {        if(strcmp(s,"n")==0)        break;        scanf("%d",&n);        printf("Case %d:n",t++);        while(n--)        {            scanf("%d%d",&p1,&p2);            if(p1>p2)            {            tem=p1;            p1=p2;            p2=tem;            }            if(p1==p2)            {               printf("Yesn");               continue;            }            for(i=p1;i<p2;i++)            {                 if(s[i]==s[i+1])                c=1;                else                {                  c=0;                  break;                }            }            if(c==1)            printf("Yesn");            else            printf("Non");        }    }    return 0;}...