Saturday, 1 October 2011

ACM 10221-Satellites

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<sstream>
#include<utility>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#define pi 2*acos(0.0)
using namespace std;

int main()
{
    long double s,a,arc,chord,deg,rad;char type[5];
    //freopen("in.txt","r",stdin);
    while(scanf("%Lf%Lf%s",&s,&a,type)==3)
    {
        if(!strcmp(type,"min"))
        {
            if(a>180)
                a=360-a;
            deg=a/60.0;
            rad=(pi*deg)/180.0;
        }
        else
        {
            if(a>180)
                a=360-a;
            deg=a;
            rad=(pi*deg)/180.0;
        }
        arc=(s+6440)*rad;
        chord=2*(s+6440)*sin(rad/2.0);
        printf("%0.6Lf %0.6Lf\n",arc,chord);
    }
    return 0;
}

ACM 10219-Find the ways !

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<sstream>
#include<utility>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
using namespace std;

int main()
{
    long double n,r,i,digitn,digitr;
    //freopen("in.txt","r",stdin);
    while(scanf("%Lf%Lf",&n,&r)==2)
    {
        digitn=0,digitr=0;
        for(i=r;i>=1;i--)
        {
            digitn+=log10(n--);
            digitr+=log10(i);
        }
        cout<<floor(digitn-digitr)+1<<endl;
    }
    return 0;
}

ACM 424- Integer Inquiry

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<sstream>
#include<utility>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#define M 110
using namespace std;

int strLen(char[]);
void strRev(char[]);
void longAdd(char[],char[]);
int main()
{
    char num[M],res[M];
    memset(res,'\0',M);
    //freopen("in.txt","r",stdin);
    while(gets(num))
    {
        strRev(num);
        longAdd(res,num);
        memset(num,'\0',M);
    }
    strRev(res);
    printf("%s\n",res);
    return 0;
}
void longAdd(char res[],char num[])
{
    int i,a,b,c=0;
    for(i=0;res[i]||num[i];i++)
    {
        a=res[i]?res[i]-48:0;
        b=num[i]?num[i]-48:0;
        res[i]=(a+b+c)%10+48;
        c=(a+b+c)/10;
    }
    if(c)
        res[i]=c+48;
}
int strLen(char str[])
{
    int i;
    for(i=0;str[i];i++);
    return(i);
}
void strRev(char str[])
{
    int i,len=strLen(str),n=len/2;
    char ch;
    for(i=0;i<n;i++)
    {
        ch=str[i];
        str[i]=str[len-i-1];
        str[len-i-1]=ch;
    }
}

ACM 10959-The Party, Part I

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<sstream>
#include<utility>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#define M 1000
using namespace std;
int G[M][M],P,D,d[M];
void BSF(int s)
{
    queue<int>Q;int color[M],h,i;
    memset(color,0,sizeof(color));
    d[s]=0;color[s]=1;
    Q.push(s);
    while(!Q.empty()) //if Q is not empty,it return false
    {
        h=Q.front();Q.pop();
        for(i=0;i<P;i++)
        {
            if(G[h][i]==1 && color[i]==0)
            {
                color[i]=1;
                d[i]=d[h]+1;//d=depth
                Q.push(i);
            }
            color[h]=2;
        }
    }
}
int main()
{
    int i,j,t,r,c;
    //freopen("in.txt","r",stdin);
    cin>>t;
    while(t--)
    {
        cin>>P>>D;
        for(i=0;i<P;i++)
            for(j=0;j<P;j++)
                G[i][j]=0;

        for(i=0;i<D;i++)
        {
            cin>>r>>c;
            G[r][c]=G[c][r]=1;
        }
        BSF(0);
        for(i=1;i<P;i++)
        {
            cout<<d[i]<<'\n';
        }
        if(t)
            cout<<endl;
    }
    return(0);
}

Wednesday, 1 June 2011

uva 694-The collatz sequences

uva 10018-Reverse and Add

#include<stdio.h>
unsigned long reverse(register unsigned long);
int main()
{
    register unsigned long n,num,rev,i;
    //freopen("in.txt","r",stdin);
    scanf("%lu",&n);
    while(n--)
    {
        scanf("%lu",&num);
        for(i=0;;i++)
        {
            rev=reverse(num);
            if(!(num^rev))
                break;
            num=num+rev;
        }
        printf("%lu %lu\n",i,num);
    }
    return 0;
}
unsigned long reverse(register unsigned long num)
{
    unsigned long r=0;
    while(num)
    {
        r=r*10+num%10;
        num=num/10;
    }
    return r;
}

uva 10110-Light,more light

uva 10013-Super long sums

uva 10008-What's Cryptanalysis

uva 900-Brick Wall Patterns

uva 10062-Tell me the frequencies!

uva 10041-Bito's Fanoly

uva 492- Pig-Latin

uva 299-train swapping

uva 10252-Common Permutation

Thursday, 19 May 2011

uva 11917-Do Your Own Homework

uva 11879-Multiple of 17

uva 11878-Home work cheaker

uva 11877-The cocola store

uva 11689-Soda surpuler

uva 11646-Athelatic Track

uva 11636-Hellow World!

acm 11547-Automatic Answer

acm 11530-SMS Typing

uva 11461-Sequence Number

uva 11417-GCD

uva 11172-Relational operator

uva 10970-Big Choclet

10929-You can say 11

10924-Prime Words

10924-Prime Word

Wednesday, 18 May 2011

10812-Beat The Spread!

10783-Odd sum

10699-Count the factors

10696-f91

10346-Peter’s Smokes

10222-Decode the Mad man

10110-Light,more light

10082-WERTYU

10071-Back to High School Physics

10070-Leap Year or Not Leap Year and …

10055-Hashmat the brave warrior

10035-Primary Arithmetic

10025-The 1 2 ... n = k problem

10019-Funny Encryption Method

579-Clock hand

543-Goldbases conjection

543-Goldbach's Conjecture

294-Divisors

264-Count on Cantor

256-Quirksome squares

146-ID Code

Tuesday, 17 May 2011

494-Kinter girden counting game

488-Traingle Wave

458-The Decedor

445-Marvelous mages

406-prime cut

374-Big Mod

272-Text Quotes

136-Ugly Number

113-power of criptography

102-Ecological Bin Package

100-The 3n+1 Problem