//accepted
#include<iostream>
using namespace std;
int main()
{
int now[14],need[13],t=0,n,i,j;
while(cin>>n)
{
if(n<0)break;
now[0]=n;
for(i=1;i<=12;i++)
cin>>now[i];
for(j=0;j<12;j++)
cin>>need[j];
cout<<"Case "<<++t<<":\n";
for(i=0;i<12;i++)
{
// cout<<now[i]<<' '<<need[i]<<now[i]-need[i]<<' ';
if(now[i]-need[i]>=0)
{
now[i+1]=now[i+1]+now[i]-need[i];
cout<<"No problem! :D\n";
}
else
{
now[i+1]+=now[i];
cout<<"No problem. :(\n";
}
}
}
return 0;
}
Sunday, 27 May 2012
UVa 11577 Letter Frequency Solution
//accepted
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int J,Num[28],n,M,L,K;
char str[202];
while(scanf("%d\n",&n)==1){
while(n--)
{
int I[27]={0};
gets(str);
L=strlen(str);
for(J=0;J<L;J++)
{
if(str[J]=='a'||str[J]=='A')
I[0]++;
else if(str[J]=='b'||str[J]=='B')
I[1]++;
else if(str[J]=='c'||str[J]=='C')
I[2]++;
else if(str[J]=='d'||str[J]=='D')
I[3]++;
else if(str[J]=='e'||str[J]=='E')
I[4]++;
else if(str[J]=='f'||str[J]=='F')
I[5]++;
else if(str[J]=='g'||str[J]=='G')
I[6]++;
else if(str[J]=='h'||str[J]=='H')
I[7]++;
else if(str[J]=='i'||str[J]=='I')
I[8]++;
else if(str[J]=='j'||str[J]=='J')
I[9]++;
else if(str[J]=='k'||str[J]=='K')
I[10]++;
else if(str[J]=='l'||str[J]=='L')
I[11]++;
else if(str[J]=='m'||str[J]=='M')
I[12]++;
else if(str[J]=='n'||str[J]=='N')
I[13]++;
else if(str[J]=='o'||str[J]=='O')
I[14]++;
else if(str[J]=='p'||str[J]=='P')
I[15]++;
else if(str[J]=='q'||str[J]=='Q')
I[16]++;
else if(str[J]=='r'||str[J]=='R')
I[17]++;
else if(str[J]=='s'||str[J]=='S')
I[18]++;
else if(str[J]=='t'||str[J]=='T')
I[19]++;
else if(str[J]=='u'||str[J]=='U')
I[20]++;
else if(str[J]=='v'||str[J]=='V')
I[21]++;
else if(str[J]=='w'||str[J]=='W')
I[22]++;
else if(str[J]=='x'||str[J]=='X')
I[23]++;
else if(str[J]=='y'||str[J]=='Y')
I[24]++;
else if(str[J]=='z'||str[J]=='Z')
I[25]++;
}
M=0;
for(L=200;L>=0;L--)
{for(J=0;J<27;J++)
{
if(I[J]==L&&M<=I[J])
{
printf("%c",J+97);
M=I[J];
}
}
}
cout<<endl;
}}
return 0;
}
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int J,Num[28],n,M,L,K;
char str[202];
while(scanf("%d\n",&n)==1){
while(n--)
{
int I[27]={0};
gets(str);
L=strlen(str);
for(J=0;J<L;J++)
{
if(str[J]=='a'||str[J]=='A')
I[0]++;
else if(str[J]=='b'||str[J]=='B')
I[1]++;
else if(str[J]=='c'||str[J]=='C')
I[2]++;
else if(str[J]=='d'||str[J]=='D')
I[3]++;
else if(str[J]=='e'||str[J]=='E')
I[4]++;
else if(str[J]=='f'||str[J]=='F')
I[5]++;
else if(str[J]=='g'||str[J]=='G')
I[6]++;
else if(str[J]=='h'||str[J]=='H')
I[7]++;
else if(str[J]=='i'||str[J]=='I')
I[8]++;
else if(str[J]=='j'||str[J]=='J')
I[9]++;
else if(str[J]=='k'||str[J]=='K')
I[10]++;
else if(str[J]=='l'||str[J]=='L')
I[11]++;
else if(str[J]=='m'||str[J]=='M')
I[12]++;
else if(str[J]=='n'||str[J]=='N')
I[13]++;
else if(str[J]=='o'||str[J]=='O')
I[14]++;
else if(str[J]=='p'||str[J]=='P')
I[15]++;
else if(str[J]=='q'||str[J]=='Q')
I[16]++;
else if(str[J]=='r'||str[J]=='R')
I[17]++;
else if(str[J]=='s'||str[J]=='S')
I[18]++;
else if(str[J]=='t'||str[J]=='T')
I[19]++;
else if(str[J]=='u'||str[J]=='U')
I[20]++;
else if(str[J]=='v'||str[J]=='V')
I[21]++;
else if(str[J]=='w'||str[J]=='W')
I[22]++;
else if(str[J]=='x'||str[J]=='X')
I[23]++;
else if(str[J]=='y'||str[J]=='Y')
I[24]++;
else if(str[J]=='z'||str[J]=='Z')
I[25]++;
}
M=0;
for(L=200;L>=0;L--)
{for(J=0;J<27;J++)
{
if(I[J]==L&&M<=I[J])
{
printf("%c",J+97);
M=I[J];
}
}
}
cout<<endl;
}}
return 0;
}
UVa 11244 Counting Stars Solution
//accepted
#include<cstdio>
using namespace std;
int main()
{
int dim[8][2]={{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0}};
int c,r,i,j,k,tx,ty,l,n;
while(scanf("%d%d",&r,&c)==2&&r&&c)
{
char star[101][101]={0};
for(i=0;i<r;i++)
scanf("%s",&star[i]);
n=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
l=1;
if(star[i][j]=='*')
for(l=0,k=0;k<8;k++)
{
tx=i+dim[k][0];ty=j+dim[k][1];
if(tx>=0&&ty>=0&&tx<r&&ty<c&&star[tx][ty]=='*')
{
l++;
}
}
if(l==0)n++;
}
}
printf("%d\n",n);
}
return 0;
}
/*
.....
....*
....*
...*.
*....
*/
#include<cstdio>
using namespace std;
int main()
{
int dim[8][2]={{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0}};
int c,r,i,j,k,tx,ty,l,n;
while(scanf("%d%d",&r,&c)==2&&r&&c)
{
char star[101][101]={0};
for(i=0;i<r;i++)
scanf("%s",&star[i]);
n=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
l=1;
if(star[i][j]=='*')
for(l=0,k=0;k<8;k++)
{
tx=i+dim[k][0];ty=j+dim[k][1];
if(tx>=0&&ty>=0&&tx<r&&ty<c&&star[tx][ty]=='*')
{
l++;
}
}
if(l==0)n++;
}
}
printf("%d\n",n);
}
return 0;
}
/*
.....
....*
....*
...*.
*....
*/
UVa 10922 2 the 9s Solution
//accepted
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char a[1002];
int s,d,i,j,k,l,q;
bool w;
while(cin>>a)
{
l=strlen(a);
if(l==1&&a[0]=='0')return 0;
s=0;
for(i=0;i<l;i++)
s+=a[i]-48;
if(s%9==0)w=true;
else w=false;
j=1;q=0;d=s;
if(w==true)
while(d!=9&&d>9)
{q=0;
while(d!=0)
{
q+=d%10;
d=d/10;
}
d=q;
j++;
}
if(w==true)
printf("%s is a multiple of 9 and has 9-degree %d.\n",a,j);
else if(w==false)
printf("%s is not a multiple of 9.\n",a);
}
return 0;
}
UVa 10773 Back to Intermediate Math Solution
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int tc,t=1;
double u,v,dist,t1,t2,td;
cin>>tc;
while(tc--)
{
scanf("%lf%lf%lf",&dist,&v,&u);
if(v==0 || u == 0 || v >=u)
{
printf("Case %d: can't determine\n",t++);
continue;
}
t1 = (1.0*dist)/(u*1.0);
t2 = (1.0*dist)/(sqrt((u*u)-(v*v))*1.0);
td = fabs(t2-t1);
printf("Case %d: %.3lf\n",t++,td);
}
return 0;
}
UVa 10642 Can You Solve It? Solution
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#define abs(a) a<0 ? (-a) : (a)
using namespace std;
int main()
{
long long int xx1,yy1,a,b,x1,i,x2,y1,y2,dist,tc=1,crdist,down,up,cnt=1;
scanf("%lld",&tc);
while( tc--)
{
scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
a = (x1+y1);
b = (x2+y2);
if(b<a)
{
xx1 = x2;
x2 = x1;
x1 = xx1;
yy1 = y2;
y2 = y1;
y1 = yy1;
}
if(a == b)
printf("Case %lld: %lld\n",cnt++,abs(x2-x1));
else{
up = y1;
down = x2;
dist = 0;
long long int a1=a,b1=b;
if(a1>b1) {a1=b;b1=a;}
for(i = a1+1; i < b1; i++)
dist += (i+1);
crdist = up + down + dist + 1;
printf("Case %lld: %lld\n",cnt++,crdist);
}
}
return 0;
}
UVa 10579 Fibonacci Numbers Solution
//accepted
#include<iostream>
using namespace std;
int fcc[5002][1005];
void fib()
{
long int a,i,j,k;
fcc[0][1000]=0;fcc[1][1000]=fcc[2][1000]=1;
for(i=3;i<5000;i++)
{
for(j=1000;j>=0;j--)
{
fcc[i][j]=fcc[i][j]+fcc[i-1][j]+fcc[i-2][j];
if(fcc[i][j]>9)
{
fcc[i][j-1]+=(fcc[i][j]/10);
fcc[i][j]=fcc[i][j]%10;
}
}
}
}
int main()
{
int a,s,i,j,l=0;
fib();
while(cin>>a)
{
for(i=0;;i++)
{ if(fcc[a][i]!=0)break; }
for(j=i;j<=1000;j++)
{cout<<fcc[a][j];
}
cout<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int fcc[5002][1005];
void fib()
{
long int a,i,j,k;
fcc[0][1000]=0;fcc[1][1000]=fcc[2][1000]=1;
for(i=3;i<5000;i++)
{
for(j=1000;j>=0;j--)
{
fcc[i][j]=fcc[i][j]+fcc[i-1][j]+fcc[i-2][j];
if(fcc[i][j]>9)
{
fcc[i][j-1]+=(fcc[i][j]/10);
fcc[i][j]=fcc[i][j]%10;
}
}
}
}
int main()
{
int a,s,i,j,l=0;
fib();
while(cin>>a)
{
for(i=0;;i++)
{ if(fcc[a][i]!=0)break; }
for(j=i;j<=1000;j++)
{cout<<fcc[a][j];
}
cout<<endl;
}
return 0;
}
UVa 10474 Where is the Marble? Solution
//accepted
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10001],b[10001];
int main()
{
int q,n,s,d,i,k,j,l;
l=0;
while(scanf("%d%d",&n,&q)==2)
{
if(n==0&&q==0) break;
for(i=0;i<n;i++)scanf("%d",&a[i]);
for(i=0;i<q;i++)scanf("%d",&b[i]);
sort(a,a+n);
printf("CASE# %d:\n",++l);
for(i=0;i<q;i++)
{k=0;
for(j=0;j<n;j++)
{
if(b[i]==a[j]&&k!=1)
{
printf("%d found at %d\n",b[i],j+1);
k=1;
}
}
if(k==0)printf("%d not found\n",b[i]);
}
}
return 0;
}
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10001],b[10001];
int main()
{
int q,n,s,d,i,k,j,l;
l=0;
while(scanf("%d%d",&n,&q)==2)
{
if(n==0&&q==0) break;
for(i=0;i<n;i++)scanf("%d",&a[i]);
for(i=0;i<q;i++)scanf("%d",&b[i]);
sort(a,a+n);
printf("CASE# %d:\n",++l);
for(i=0;i<q;i++)
{k=0;
for(j=0;j<n;j++)
{
if(b[i]==a[j]&&k!=1)
{
printf("%d found at %d\n",b[i],j+1);
k=1;
}
}
if(k==0)printf("%d not found\n",b[i]);
}
}
return 0;
}
UVa 10394 Twin Primes Solution
//10394 - Twin Primes.cpp
//20000000
//100000
//Accepted
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 18409900
using namespace std;
bool prime[M];
int pc = 0,tw = 1;
long long int twins[100001];
void seieve()
{
long long int i,j,k,l;
prime[0] = prime[1] = true;
k=2;
for(i = 2 ; i <= M ; i++)
{
while(i<=M && prime[i]) i++;
//cout<<i<<" ";
if(i - k == 2)
twins[tw++] = k;
k=i;
for(j = i*i ; j<=M ; j+=i)
prime[j] = true;
}
}
int main()
{
int a;
seieve();
while(cin>>a)
{
printf("(%lld, %lld)\n",twins[a],twins[a]+2);
}
return 0;
}
//20000000
//100000
//Accepted
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 18409900
using namespace std;
bool prime[M];
int pc = 0,tw = 1;
long long int twins[100001];
void seieve()
{
long long int i,j,k,l;
prime[0] = prime[1] = true;
k=2;
for(i = 2 ; i <= M ; i++)
{
while(i<=M && prime[i]) i++;
//cout<<i<<" ";
if(i - k == 2)
twins[tw++] = k;
k=i;
for(j = i*i ; j<=M ; j+=i)
prime[j] = true;
}
}
int main()
{
int a;
seieve();
while(cin>>a)
{
printf("(%lld, %lld)\n",twins[a],twins[a]+2);
}
return 0;
}
Wednesday, 16 May 2012
UVa 10106 Product Solution
#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
struct Bigint {
string a; // to store the digits
int sign; // sign = -1 for negative numbers, sign = 1 otherwise
Bigint() {} // default constructor
Bigint( string b ) { (*this) = b; } // constructor for string
int size() { // returns number of digits
return a.size();
}
Bigint inverseSign() { // changes the sign
sign *= -1;
return (*this);
}
Bigint normalize( int newSign ) { // removes leading 0, fixes sign
for( int i = a.size() - 1; i > 0 && a[i] == '0'; i-- )
a.erase(a.begin() + i);
sign = ( a.size() == 1 && a[0] == '0' ) ? 1 : newSign;
return (*this);
}
void operator = ( string b ) { // assigns a string to Bigint
a = b[0] == '-' ? b.substr(1) : b;
reverse( a.begin(), a.end() );
this->normalize( b[0] == '-' ? -1 : 1 );
}
bool operator < ( const Bigint &b ) const { // less than operator
if( sign != b.sign ) return sign < b.sign;
if( a.size() != b.a.size() )
return sign == 1 ? a.size() < b.a.size() : a.size() > b.a.size();
for( int i = a.size() - 1; i >= 0; i-- ) if( a[i] != b.a[i] )
return sign == 1 ? a[i] < b.a[i] : a[i] > b.a[i];
return false;
}
bool operator == ( const Bigint &b ) const { // operator for equality
return a == b.a && sign == b.sign;
}
Bigint operator + ( Bigint b ) { // addition operator overloading
if( sign != b.sign ) return (*this) - b.inverseSign();
Bigint c;
for(int i = 0, carry = 0; i<a.size() || i<b.size() || carry; i++ ) {
carry+=(i<a.size() ? a[i]-48 : 0)+(i<b.a.size() ? b.a[i]-48 : 0);
c.a += (carry % 10 + 48);
carry /= 10;
}
return c.normalize(sign);
}
Bigint operator - ( Bigint b ) { // subtraction operator overloading
if( sign != b.sign ) return (*this) + b.inverseSign();
int s = sign; sign = b.sign = 1;
if( (*this) < b ) return ((b - (*this)).inverseSign()).normalize(-s);
Bigint c;
for( int i = 0, borrow = 0; i < a.size(); i++ ) {
borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);
c.a += borrow >= 0 ? borrow + 48 : borrow + 58;
borrow = borrow >= 0 ? 0 : 1;
}
return c.normalize(s);
}
Bigint operator * ( Bigint b ) { // multiplication operator overloading
Bigint c("0");
for( int i = 0, k = a[i] - 48; i < a.size(); i++, k = a[i] - 48 ) {
while(k--) c = c + b; // ith digit is k, so, we add k times
b.a.insert(b.a.begin(), '0'); // multiplied by 10
}
return c.normalize(sign * b.sign);
}
Bigint operator / ( Bigint b ) { // division operator overloading
if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 );
Bigint c("0"), d;
for( int j = 0; j < a.size(); j++ ) d.a += "0";
int dSign = sign * b.sign; b.sign = 1;
for( int i = a.size() - 1; i >= 0; i-- ) {
c.a.insert( c.a.begin(), '0');
c = c + a.substr( i, 1 );
while( !( c < b ) ) c = c - b, d.a[i]++;
}
return d.normalize(dSign);
}
Bigint operator % ( Bigint b ) { // modulo operator overloading
if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 );
Bigint c("0");
b.sign = 1;
for( int i = a.size() - 1; i >= 0; i-- ) {
c.a.insert( c.a.begin(), '0');
c = c + a.substr( i, 1 );
while( !( c < b ) ) c = c - b;
}
return c.normalize(sign);
}
void print() {
if( sign == -1 ) putchar('-');
for( int i = a.size() - 1; i >= 0; i-- ) putchar(a[i]);
}
};
int main()
{
string s1,s2;
Bigint a,b,c;
while(cin>>s1>>s2)
{
a=s1;
b=s2;
c=a*b;
c.print();
cout<<endl;
}
return 0;
}
Tuesday, 15 May 2012
UVa 392 Polynomial Showdown Solution
#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
int main()
{
int coefficients[10],start,i;
while(cin>>coefficients[0])
{
for(i=1;i<9;i++)
cin>>coefficients[i];
start=8;
for(i=0;i<9;i++)
if(coefficients[i]!=0)
{
start=i;
break;
}
if(start==8)
cout<<coefficients[start];
else
{
if(coefficients[start]==-1)
cout<<"-";
else if(coefficients[start]==1)
cout<<"";
else
cout<<coefficients[start];
cout<<"x";
if(start!=7)
cout<<"^"<<8-start;
for(i=start+1;i<9;i++)
if(coefficients[i]!=0)
{
if(coefficients[i]<0)
cout<<" - ";
else
cout<<" + ";
if((coefficients[i]!=-1 && coefficients[i]!=1) || i==8)
{
if(coefficients[i]<0)
cout<<coefficients[i]*(-1);
else
cout<<coefficients[i];
}
if(i!=8)
cout<<"x";
if(i!=7 && i!=8)
cout<<"^"<<8-i;
}
}
cout<<endl;
}
return 0;
}
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
int main()
{
int coefficients[10],start,i;
while(cin>>coefficients[0])
{
for(i=1;i<9;i++)
cin>>coefficients[i];
start=8;
for(i=0;i<9;i++)
if(coefficients[i]!=0)
{
start=i;
break;
}
if(start==8)
cout<<coefficients[start];
else
{
if(coefficients[start]==-1)
cout<<"-";
else if(coefficients[start]==1)
cout<<"";
else
cout<<coefficients[start];
cout<<"x";
if(start!=7)
cout<<"^"<<8-start;
for(i=start+1;i<9;i++)
if(coefficients[i]!=0)
{
if(coefficients[i]<0)
cout<<" - ";
else
cout<<" + ";
if((coefficients[i]!=-1 && coefficients[i]!=1) || i==8)
{
if(coefficients[i]<0)
cout<<coefficients[i]*(-1);
else
cout<<coefficients[i];
}
if(i!=8)
cout<<"x";
if(i!=7 && i!=8)
cout<<"^"<<8-i;
}
}
cout<<endl;
}
return 0;
}
Monday, 14 May 2012
রাউটার
এক নেটওয়ার্ক থেকে আরেক নেটওয়ার্কে ডাটা পাঠানোর পদ্ধতিকে বলা হয় রাউটিং। আর রাউটিং এর জন্য ব্যবহুত ডিভাইস হলো রাউটার। ইহা ওএসআই মডেল এর নেটওয়ার্ক লেয়ারে কাজ করে।
সুইচ
সুইজ হলো একাধিক পোর্ট বিশিষ্ট ব্রিজ।ইহা প্রতিটি নোডের ম্যাক এড্রেস এর তালিকা সংরক্ষন করে। ইহা ওএসআই মডেল এর ডাটালিংক লেয়ারে কাজ করে।
ব্রিজ
ব্রিজ এমন একটি ডিভাইস যা একাধিক নেটওয়ার্ক সেগমেন্টকে যুক্ত করে থাকে। এটি প্রতিটি সেগমেন্ট বিভিন্ন ডিভাইসের হিসেব রাখার জন্য ব্রিজিং টেবিল তৈরি করে। ইহা ওএসআই মডেল এর ডাটালিংক লেয়ারে কাজ করে।
হাব
হাব হলো একাধিক পোর্ট বিশিষ্ট রিপিটার। এটি কাজ করে ইলেকট্রিক সিগন্যাল নিয়ে। নেটওয়ার্ক এড্রেস কিংবা নেটওয়ার্ক এডাপ্টারের ম্যাক এড্রস নিয়ে হাবের মাথাব্যাথা নেই। এটিও কাজ করে ওএসআই মডেল এর ফিজিক্যাল লেয়ারে।
রিপিটার
রিপিটার হলো এমন একটি ডিভাইস যা সিগন্যালকে এমপ্লিফাই করার জন্য ব্যবহার করা হয়। ১৮৫ মিটার দূরত্ব অতিক্রম করার আগেই আপনি একটি রিপিটার ব্যবহার করে সেই সিগন্যালকে এমপ্লিফাই করে দিলে সেটি আরো ১৮৫ মিটার অতিক্রম করতে পারে। এটি কাজ করে ওএসআই মডেল এর ফিজিক্যাল লেয়ারে।
ট্যুইস্টেড পেয়ার ক্যাবল
ট্যুইস্টেড পেয়ার ক্যাবল দুই দরনের হয়ে থাকে।
- ১. শিল্ডেড ট্যুইস্টেড পেয়ার ক্যাবল
- ২. আনশিল্ডেড ট্যুইস্টেড পেয়ার ক্যাবল
- শিল্ডেড ট্যুইস্টেড পেয়ার ক্যাবল
শিল্ডেড ট্যুইস্টেড পেয়ার ক্যাবলে প্রতিটি ট্যুইস্ট জোড়া থাকে একটি করে শক্ত আচ্ছাদনের ভেতর। ফলে ইলেকট্রিক ইন্টারফের্যান্স অনেক কম থাকে। এই ক্যাবলের ডাটা ট্রান্সফার স্পীড ৫০০ এমবিপিএস হয়ে থাকে।
আনশিল্ডেড ট্যুইস্টেড পেয়ার ক্যাবল
আনশিল্ডেড ট্যুইস্টেড পেয়ার ক্যাবলে পেয়ারের বাইরে অতিরিক্ত কোন শিল্ডিং থাকে না কেবল বাহিরে একটি প্লাষ্টিকের জেকেট থাকে। এই ক্যাবলের ডাটা ট্রান্সফার রেট ১৬ এমবিপিএস।
টপোলজি
একটি নেটওয়ার্কে কম্পিউটারগুলো কিভাবে সংযুক্ত আছে তার ক্যাটালগকেই টপোলজি বলে। নেটওয়ার্ক ডিজাইনের ক্ষেত্রে টপোলজি বিশেষ ভূমিকা রাখে। টপোলজি বিভিন্ন ধরনের হতে পারে।
যেমন- বাস টপোলজি, স্টার টপোলজি, রিং টপোলজি,মেশ টপোলজি ইত্যাদি। নীচে বিভিন্ন টপোলজিগুলো দেওয়া হলো:
যেমন- বাস টপোলজি, স্টার টপোলজি, রিং টপোলজি,মেশ টপোলজি ইত্যাদি। নীচে বিভিন্ন টপোলজিগুলো দেওয়া হলো:
নেটওয়ার্ক
নেটওয়ার্কের প্রকারভেদ :
নেটওয়ার্কে সাধারণত তিন ভাগে ভাগ করা যায়।- LAN
- MAN
- WAN
- Local Area Network (LAN): একই বিল্ডিং এর মাঝে অবস্থিত বিভিন্ন কম্পিউটার নিয়ে গঠিত নেটওয়ার্রকে লোকাল এরিয়া নেটওয়ার্ক বলে। এই নেটওয়ার্ক এর ডাটা ট্রান্সফার গতি ১০এমবিপিএস। এই নেটওয়ার্ক এ ব্যবহিত ডিভাইসগুলো হলো রিপিটার, হাব, নেটওয়ার্ক ইন্টারফেস ইত্যাদি।
- Metropolitan Area Network (MAN) : একই শহরের মধ্যে অবস্থিত কয়েকটি ল্যানের সমন্বয়ে গঠিত ইন্টারফেসকে বলা হয় মেট্রোপলিটন এরিয়া নেটওয়ার্ক । এ ধরনের নেটওয়ার্ক ৫০-৭৫ মাইল পর্যন্ত বিস্তৃত হতে পারে। এই নেটওয়ার্কর ডাটা ট্রান্সফার স্পিড গিগাবিট পার সেকেন্ড। এ ধরনের নেটওয়ার্ক এ ব্যবহিত ডিভাইস গুলো হলো রাউটার, সুইজ, মাইক্রোওয়েভ এন্টেনা ইত্যাদি।
- WAN(Wide Area Network) : দূরবর্তী ল্যানসমূকে নিয়ে গড়ে উঠা নেটওয়ার্ককে ওয়াইড এরিয়া নেটওয়ার্ক বলে। এ ধরনের নেটওয়ার্ক এর ডাটা ট্রান্সফার স্পীড ৫৬ কেবিপিএস থেকে ১.৫৪৪ এমবিপিএস। ওয়্যানের গতি ধীরে ধীরে পরিবর্তন হচ্ছে। এ ধরনের নেটওয়ার্কে ব্যবহিত ডিভাইসগুলো হলো রাউটার, মডেম, ওয়্যান সুইজ ইত্যাদি।
UVa 10655 Contemplation! Algebra Solution
#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
//#include<cmath>
#include<math.h>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
long long MOD=pow(2,64);
struct A{
long long arr[5][5];
};
A MatrixMulti(A a, A b)
{
A result;
int i,j,k;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
result.arr[i][j]=0;
for(k=0;k<2;k++)
{
result.arr[i][j]+=(a.arr[i][k]%MOD*b.arr[k][j]%MOD)%MOD;
result.arr[i][j]=result.arr[i][j]%MOD;
}
result.arr[i][j]=result.arr[i][j]%MOD;
}
return result;
}
A BigMod(A a, long long n)
{
A ret;
int i,j;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
if(i==j)
ret.arr[i][j]=1;
else
ret.arr[i][j]=0;
}
while(n)
{
if(n & 1)
ret=MatrixMulti(ret,a);
a=MatrixMulti(a,a);
n>>=1;
}
return ret;
}
int main()
{
A initialMatrix,ans;
long long n,i,j,t,kk=1,p,q,temp,cnt;
string line;
while(getline(cin,line))
{
cnt=0;
stringstream ss;
ss<<line;
while(ss>>temp)
{
if(cnt==0)
p=temp;
else if(cnt==1)
q=temp;
else if(cnt==2)
n=temp;
cnt++;
}
if(cnt==2)
break;
initialMatrix.arr[0][0]=p;
initialMatrix.arr[0][1]=-q;
initialMatrix.arr[1][0]=1;
initialMatrix.arr[1][1]=0;
if(n==0)
{
cout<<"2"<<endl;
continue;
}
if(n==1)
{
cout<<p<<endl;
continue;
}
ans=BigMod(initialMatrix,n-1);
cout<<(((ans.arr[0][0]*p)%MOD+(ans.arr[0][1]*2)%MOD))%MOD<<endl;
}
return 0;
}
Sunday, 13 May 2012
UVa 444 Encoder and Decoder Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,i,j,d;
char f;
string a,c,e,m;
while(getline(cin,a))
{
if(a[0]-'0'>=0 && a[0]-'0'<=9)
{
e="\0";
for(i=0;i<a.length();i++)
{
m="\0";
if((a[i+1]-'0')>=3) {
d=((a[i+1]-'0'))*10+(a[i]-'0');
f=d;
m+=f;
i++;
}
else{
d=((a[i+2]-'0'))*100+((a[i+1]-'0'))*10+(a[i]-'0');
f=d;
m+=f;
i+=2;
}
e+=m;
}
for(i=e.length()-1;i>=0;i--)
{
cout<<e[i];
}
}
else {
for(i=a.length()-1;i>=0;i--)
{
e="\0";
x=a[i];
stringstream h;
h<<x;
c=h.str();
for(j=c.length()-1;j>=0;j--)
e+=c[j];
cout<<e;
}
}
cout<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,i,j,d;
char f;
string a,c,e,m;
while(getline(cin,a))
{
if(a[0]-'0'>=0 && a[0]-'0'<=9)
{
e="\0";
for(i=0;i<a.length();i++)
{
m="\0";
if((a[i+1]-'0')>=3) {
d=((a[i+1]-'0'))*10+(a[i]-'0');
f=d;
m+=f;
i++;
}
else{
d=((a[i+2]-'0'))*100+((a[i+1]-'0'))*10+(a[i]-'0');
f=d;
m+=f;
i+=2;
}
e+=m;
}
for(i=e.length()-1;i>=0;i--)
{
cout<<e[i];
}
}
else {
for(i=a.length()-1;i>=0;i--)
{
e="\0";
x=a[i];
stringstream h;
h<<x;
c=h.str();
for(j=c.length()-1;j>=0;j--)
e+=c[j];
cout<<e;
}
}
cout<<endl;
}
return 0;
}
UVa 443 Humble Numbers Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
long long a,b,c,d,w,x,y,z,i,j,t,n[10000],e;
memset(n,0,sizeof(n));
a=b=c=d=1;
w=2;
x=3;
y=5;
z=7;
n[1]=1;
t=2;
while(n[6000]==0)
{
if(w<x && w<y && w<z) {
n[t]=w;
a++;
w=n[a]*2;
t++;
}
else if(x<w && x<y && x<z) {
n[t]=x;
b++;
x=n[b]*3;
t++;
}
else if(y<x && y<w && y<z) {
n[t]=y;
c++;
y=n[c]*5;
t++;
}
else if(z<x && z<y && z<w) {
n[t]=z;
d++;
z=n[d]*7;
t++;
}
if(w==x || w==y) {
a++;
w=n[a]*2;
}
else if(x==y || x==z) {
b++;
x=n[b]*3;
}
else if(y==z || y==w) {
c++;
y=n[c]*5;
}
else if(z==w || z==x) {
d++;
z=n[d]*7;
}
}
while(cin>>e)
{
if(e==0) return 0;
if(e%100>=10 && e%100<=19) cout<<"The "<<e<<"th humble number is "<<n[e]<<"."<<endl;
else if(e%10==1) cout<<"The "<<e<<"st humble number is "<<n[e]<<"."<<endl;
else if(e%10==2) cout<<"The "<<e<<"nd humble number is "<<n[e]<<"."<<endl;
else if(e%10==3) cout<<"The "<<e<<"rd humble number is "<<n[e]<<"."<<endl;
else cout<<"The "<<e<<"th humble number is "<<n[e]<<"."<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
long long a,b,c,d,w,x,y,z,i,j,t,n[10000],e;
memset(n,0,sizeof(n));
a=b=c=d=1;
w=2;
x=3;
y=5;
z=7;
n[1]=1;
t=2;
while(n[6000]==0)
{
if(w<x && w<y && w<z) {
n[t]=w;
a++;
w=n[a]*2;
t++;
}
else if(x<w && x<y && x<z) {
n[t]=x;
b++;
x=n[b]*3;
t++;
}
else if(y<x && y<w && y<z) {
n[t]=y;
c++;
y=n[c]*5;
t++;
}
else if(z<x && z<y && z<w) {
n[t]=z;
d++;
z=n[d]*7;
t++;
}
if(w==x || w==y) {
a++;
w=n[a]*2;
}
else if(x==y || x==z) {
b++;
x=n[b]*3;
}
else if(y==z || y==w) {
c++;
y=n[c]*5;
}
else if(z==w || z==x) {
d++;
z=n[d]*7;
}
}
while(cin>>e)
{
if(e==0) return 0;
if(e%100>=10 && e%100<=19) cout<<"The "<<e<<"th humble number is "<<n[e]<<"."<<endl;
else if(e%10==1) cout<<"The "<<e<<"st humble number is "<<n[e]<<"."<<endl;
else if(e%10==2) cout<<"The "<<e<<"nd humble number is "<<n[e]<<"."<<endl;
else if(e%10==3) cout<<"The "<<e<<"rd humble number is "<<n[e]<<"."<<endl;
else cout<<"The "<<e<<"th humble number is "<<n[e]<<"."<<endl;
}
return 0;
}
UVa 440 Eeny Meeny Moo Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
long long a[10000],i,j,f,g,h,l,x;
while(cin>>x)
{
if(x==0) return 0;
f=1;
while(1)
{
memset(a,0,sizeof(a));
f++;
g=f;
h=g;
l=x;
while(1)
{
for(j=1;j<=x;j++)
{
if(h==g && a[j]==0){
a[j]=1;
h=1;
l--;
}
else if(a[j]==0)h++;
if(l==1 || a[2]==1) break;
}
if(l==1 || a[2]==1) break;
}
if(a[2]==1) continue;
else break;
}
cout<<f<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
long long a[10000],i,j,f,g,h,l,x;
while(cin>>x)
{
if(x==0) return 0;
f=1;
while(1)
{
memset(a,0,sizeof(a));
f++;
g=f;
h=g;
l=x;
while(1)
{
for(j=1;j<=x;j++)
{
if(h==g && a[j]==0){
a[j]=1;
h=1;
l--;
}
else if(a[j]==0)h++;
if(l==1 || a[2]==1) break;
}
if(l==1 || a[2]==1) break;
}
if(a[2]==1) continue;
else break;
}
cout<<f<<endl;
}
return 0;
}
UVa 424 Integer Inquiry Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
string rev(string a){
int i,j;
string b="";
for(i=0,j=a.length()-1;i<a.length();i++,j--)
b+=a[j];
return b;
}
string add(string a, string b){
int i,j,x,y,sum,s,temp=0;
string c="";
string e;
if(a.length()<b.length()){
e=a;
a=b;
b=e;
}
for(i=0;i<a.length();i++)
{
if(i<b.length())
{
x=a[i]-'0';
y=b[i]-'0';
sum=x+y+temp;
s=sum%10;
c+=s+'0';
temp=0;
if(sum>9) temp=1;
if(i==a.length()-1 && temp==1)
c+='1';
}
else {
x=a[i]-'0';
sum=temp+x;
s=sum%10;
c+=s+'0';
temp=0;
if(sum>9) temp=1;
if(i==a.length()-1 && temp==1)
c+='1';
}
}
return c;
}
int main()
{
string sum="0",s,a;
while(cin>>s)
{
if(s=="0") break;
a=rev(s);
sum=add(a,sum);
}
cout<<rev(sum)<<endl;
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
string rev(string a){
int i,j;
string b="";
for(i=0,j=a.length()-1;i<a.length();i++,j--)
b+=a[j];
return b;
}
string add(string a, string b){
int i,j,x,y,sum,s,temp=0;
string c="";
string e;
if(a.length()<b.length()){
e=a;
a=b;
b=e;
}
for(i=0;i<a.length();i++)
{
if(i<b.length())
{
x=a[i]-'0';
y=b[i]-'0';
sum=x+y+temp;
s=sum%10;
c+=s+'0';
temp=0;
if(sum>9) temp=1;
if(i==a.length()-1 && temp==1)
c+='1';
}
else {
x=a[i]-'0';
sum=temp+x;
s=sum%10;
c+=s+'0';
temp=0;
if(sum>9) temp=1;
if(i==a.length()-1 && temp==1)
c+='1';
}
}
return c;
}
int main()
{
string sum="0",s,a;
while(cin>>s)
{
if(s=="0") break;
a=rev(s);
sum=add(a,sum);
}
cout<<rev(sum)<<endl;
return 0;
}
UVa 401 Palindromes Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
int i;
string s,b,d;
char c[10000];
memset(c,0,sizeof(c));
c['A']='A';
c['E']='3';
c['H']='H';
c['I']='I';
c['J']='L';
c['L']='J';
c['M']='M';
c['O']='O';
c['S']='2';
c['T']='T';
c['U']='U';
c['V']='V';
c['W']='W';
c['X']='X';
c['Y']='Y';
c['Z']='5';
c['1']='1';
c['2']='S';
c['3']='E';
c['5']='Z';
c['8']='8';
while(cin>>s)
{
b=d="";
for(i=s.length()-1;i>=0;i--)
{
b+=s[i];
//if(c[s[i]]!=0)
d+=c[s[i]];
//else d+=s[i];
}
//cout<<s<<" "<<b<<" "<<d<<endl;
if(s!=b && s!=d) cout<<s<<" -- is not a palindrome."<<endl<<endl;
else if(s==b && s!=d) cout<<s<<" -- is a regular palindrome."<<endl<<endl;
else if(s!=b && s==d) cout<<s<<" -- is a mirrored string."<<endl<<endl;
else cout<<s<<" -- is a mirrored palindrome."<<endl<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
int i;
string s,b,d;
char c[10000];
memset(c,0,sizeof(c));
c['A']='A';
c['E']='3';
c['H']='H';
c['I']='I';
c['J']='L';
c['L']='J';
c['M']='M';
c['O']='O';
c['S']='2';
c['T']='T';
c['U']='U';
c['V']='V';
c['W']='W';
c['X']='X';
c['Y']='Y';
c['Z']='5';
c['1']='1';
c['2']='S';
c['3']='E';
c['5']='Z';
c['8']='8';
while(cin>>s)
{
b=d="";
for(i=s.length()-1;i>=0;i--)
{
b+=s[i];
//if(c[s[i]]!=0)
d+=c[s[i]];
//else d+=s[i];
}
//cout<<s<<" "<<b<<" "<<d<<endl;
if(s!=b && s!=d) cout<<s<<" -- is not a palindrome."<<endl<<endl;
else if(s==b && s!=d) cout<<s<<" -- is a regular palindrome."<<endl<<endl;
else if(s!=b && s==d) cout<<s<<" -- is a mirrored string."<<endl<<endl;
else cout<<s<<" -- is a mirrored palindrome."<<endl<<endl;
}
return 0;
}
UVa 371 Ackermann Functions Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
long long p,t,y,x,i,z,max,n;
map<long long,long long>nt;
map<long long,long long>a;
while(cin>>x>>y)
{
if(x==0 && y==0) return 0;
if(x>y){
n=x;
x=y;
y=n;
}
z=0;
nt.clear();
a.clear();
for(i=x;i<=y;i++)
{
p=i;
t=0;
while(1)
{
if(p%2==0) {
p/=2;
t++;
}
else {
p=(3*p)+1;
t++;
}
if(p==1) break;
}
if(a[t]!=1) {
nt[t]=i;
a[t]=1;
}
if(z==0){
max=t;
z++;
}
else if(max<t) max=t;
}
cout<<"Between "<<x<<" and "<<y<<", "<<nt[max]<<" generates the longest sequence of "<<max<<" values."<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
long long p,t,y,x,i,z,max,n;
map<long long,long long>nt;
map<long long,long long>a;
while(cin>>x>>y)
{
if(x==0 && y==0) return 0;
if(x>y){
n=x;
x=y;
y=n;
}
z=0;
nt.clear();
a.clear();
for(i=x;i<=y;i++)
{
p=i;
t=0;
while(1)
{
if(p%2==0) {
p/=2;
t++;
}
else {
p=(3*p)+1;
t++;
}
if(p==1) break;
}
if(a[t]!=1) {
nt[t]=i;
a[t]=1;
}
if(z==0){
max=t;
z++;
}
else if(max<t) max=t;
}
cout<<"Between "<<x<<" and "<<y<<", "<<nt[max]<<" generates the longest sequence of "<<max<<" values."<<endl;
}
return 0;
}
UVa 357 Let Me Count The Ways Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
#define eps 1e-9
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pi acos(-1.0)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pi acos(-1.0)
using namespace std;
long long coin[5]={1,5,10,25,50};
long long dp[5][30010];
long long func(long long prev,long long m)
{
if(m==0) return 1;
if(m<0) return 0;
if(dp[prev][m]!=-1) return dp[prev][m];
dp[prev][m]=0;
for(long long i=prev;i<5;i++)
{
if((m-coin[i])<0) continue;
dp[prev][m]+=func(i,(m-coin[i]));
}
return dp[prev][m];
}
int main()
{
long long n;
long long ans;
SET(dp);
while(cin>>n)
{
ans=func(0,n);
if(ans==1) cout<<"There is only 1 way to produce "<<n<<" cents change."<<endl;
else cout<<"There are "<<ans<<" ways to produce "<<n<<" cents change."<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
#define eps 1e-9
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pi acos(-1.0)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pi acos(-1.0)
using namespace std;
long long coin[5]={1,5,10,25,50};
long long dp[5][30010];
long long func(long long prev,long long m)
{
if(m==0) return 1;
if(m<0) return 0;
if(dp[prev][m]!=-1) return dp[prev][m];
dp[prev][m]=0;
for(long long i=prev;i<5;i++)
{
if((m-coin[i])<0) continue;
dp[prev][m]+=func(i,(m-coin[i]));
}
return dp[prev][m];
}
int main()
{
long long n;
long long ans;
SET(dp);
while(cin>>n)
{
ans=func(0,n);
if(ans==1) cout<<"There is only 1 way to produce "<<n<<" cents change."<<endl;
else cout<<"There are "<<ans<<" ways to produce "<<n<<" cents change."<<endl;
}
return 0;
}
UVa 353 Pesky Palindromes Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
string rev(string a){
int i,j;
string x;
x="";
for(i=0,j=a.length()-1;i<a.length();i++,j--)
x+=a[j];
return x;
}
int main()
{
map<string,int>nt;
vector<string>ff;
int x,i,d,f,y,j,k;
string s,a,b;
while(cin>>s)
{
ff.clear();
x=s.length();
d=0;
f=x;
y=0;
for(i=0;i<x;i++)
{
for(j=0;j<=i;j++)
{
a="";
for(k=d;k<d+f;k++)
a+=s[k];
b=rev(a);
if(a==b) {
nt[a]++;
if(nt[a]==1) {
ff.push_back(a);
y++;
}
}
d++;
}
d=0;
f--;
}
cout<<"The string '"<<s<<"' contains "<<y<<" palindromes."<<endl;
for(i=0;i<ff.size();i++)
{
nt[ff[i]]=0;
}
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
string rev(string a){
int i,j;
string x;
x="";
for(i=0,j=a.length()-1;i<a.length();i++,j--)
x+=a[j];
return x;
}
int main()
{
map<string,int>nt;
vector<string>ff;
int x,i,d,f,y,j,k;
string s,a,b;
while(cin>>s)
{
ff.clear();
x=s.length();
d=0;
f=x;
y=0;
for(i=0;i<x;i++)
{
for(j=0;j<=i;j++)
{
a="";
for(k=d;k<d+f;k++)
a+=s[k];
b=rev(a);
if(a==b) {
nt[a]++;
if(nt[a]==1) {
ff.push_back(a);
y++;
}
}
d++;
}
d=0;
f--;
}
cout<<"The string '"<<s<<"' contains "<<y<<" palindromes."<<endl;
for(i=0;i<ff.size();i++)
{
nt[ff[i]]=0;
}
}
return 0;
}
UVa 264 Count on Cantor Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
int main()
{
int count=1,n,i,x=1,y=1;
vector<int>a;
vector<int>b;
a.push_back(x);
b.push_back(y);
while(1)
{
x=1;
y++;
a.push_back(x);
b.push_back(y);
for(i=0;i<count;i++)
{
x++;
y--;
a.push_back(x);
b.push_back(y);
if(a.size()>10000000) break;
}
if(a.size()>10000000) break;
count++;
y=1;
x++;
a.push_back(x);
b.push_back(y);
for(i=0;i<count;i++)
{
x--;
y++;
a.push_back(x);
b.push_back(y);
if(a.size()>10000000) break;
}
if(a.size()>10000000) break;
count++;
}
while(cin>>n)
{
cout<<"TERM "<<n<<" IS "<<a[n-1]<<"/"<<b[n-1]<<endl;
}
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
int main()
{
int count=1,n,i,x=1,y=1;
vector<int>a;
vector<int>b;
a.push_back(x);
b.push_back(y);
while(1)
{
x=1;
y++;
a.push_back(x);
b.push_back(y);
for(i=0;i<count;i++)
{
x++;
y--;
a.push_back(x);
b.push_back(y);
if(a.size()>10000000) break;
}
if(a.size()>10000000) break;
count++;
y=1;
x++;
a.push_back(x);
b.push_back(y);
for(i=0;i<count;i++)
{
x--;
y++;
a.push_back(x);
b.push_back(y);
if(a.size()>10000000) break;
}
if(a.size()>10000000) break;
count++;
}
while(cin>>n)
{
cout<<"TERM "<<n<<" IS "<<a[n-1]<<"/"<<b[n-1]<<endl;
}
return 0;
}
UVa 156 Ananagrams Solution
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
using namespace std;
int main()
{
int i,j,h;
vector<string>nt;
vector<string>ff;
vector<string>b;
map<string,int>a;
string s,r;
int c[100000],d[100000];
bool g;
while(cin>>s)
{
if(s=="#") break;
r=s;
for(i=0;i<s.length();i++)
{
if(s[i]>=65 && s[i]<=90) s[i]+=32;
}
nt.push_back(r);
ff.push_back(s);
}
for(i=0;i<ff.size();i++)
{
memset(c,0,sizeof(c));
for(j=0;j<ff[i].length();j++)
c[ff[i][j]]++;
for(j=0;j<ff.size();j++)
{
memset(d,0,sizeof(d));
if(i!=j) {
for(h=0;h<ff[j].length();h++)
d[ff[j][h]]++;
g=true;
for(h=97;h<=122;h++)
{
if(c[h]!=d[h]) {
g=false;
break;
}
}
if(g==true) {
a[ff[i]]=1;
break;
}
}
}
if(a[ff[i]]!=1) b.push_back(nt[i]);
}
sort(b.begin(),b.end());
for(i=0;i<b.size();i++)
cout<<b[i]<<endl;
return 0;
}
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
using namespace std;
int main()
{
int i,j,h;
vector<string>nt;
vector<string>ff;
vector<string>b;
map<string,int>a;
string s,r;
int c[100000],d[100000];
bool g;
while(cin>>s)
{
if(s=="#") break;
r=s;
for(i=0;i<s.length();i++)
{
if(s[i]>=65 && s[i]<=90) s[i]+=32;
}
nt.push_back(r);
ff.push_back(s);
}
for(i=0;i<ff.size();i++)
{
memset(c,0,sizeof(c));
for(j=0;j<ff[i].length();j++)
c[ff[i][j]]++;
for(j=0;j<ff.size();j++)
{
memset(d,0,sizeof(d));
if(i!=j) {
for(h=0;h<ff[j].length();h++)
d[ff[j][h]]++;
g=true;
for(h=97;h<=122;h++)
{
if(c[h]!=d[h]) {
g=false;
break;
}
}
if(g==true) {
a[ff[i]]=1;
break;
}
}
}
if(a[ff[i]]!=1) b.push_back(nt[i]);
}
sort(b.begin(),b.end());
for(i=0;i<b.size();i++)
cout<<b[i]<<endl;
return 0;
}
UVa 136 Ugly Numbers Solution
#include<iostream>
using namespace std;
int main()
{
long n[6000]={0},a=1,b=1,c=1,i,j,x=2,y=3,z=5,t=2;
n[1]=1;
while(n[1500]==0)
{
if(x<y && x<z) {
n[t]=x;
a++;
x=n[a]*2;
t++;
}
else if(y<x && y<z) {
n[t]=y;
b++;
y=n[b]*3;
t++;
}
else if(z<y && z<x) {
n[t]=z;
c++;
z=n[c]*5;
t++;
}
if(x==y) {
a++;
x=n[a]*2;
}
else if(y==z) {
b++;
y=n[b]*3;
}
else if(z==x) {
c++;
z=n[c]*5;
}
}
cout<<"The 1500'th ugly number is "<<n[1500]<<"."<<endl;
return 0;
}
using namespace std;
int main()
{
long n[6000]={0},a=1,b=1,c=1,i,j,x=2,y=3,z=5,t=2;
n[1]=1;
while(n[1500]==0)
{
if(x<y && x<z) {
n[t]=x;
a++;
x=n[a]*2;
t++;
}
else if(y<x && y<z) {
n[t]=y;
b++;
y=n[b]*3;
t++;
}
else if(z<y && z<x) {
n[t]=z;
c++;
z=n[c]*5;
t++;
}
if(x==y) {
a++;
x=n[a]*2;
}
else if(y==z) {
b++;
y=n[b]*3;
}
else if(z==x) {
c++;
z=n[c]*5;
}
}
cout<<"The 1500'th ugly number is "<<n[1500]<<"."<<endl;
return 0;
}
Subscribe to:
Posts (Atom)