#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; }
Saturday, 1 October 2011
ACM 10221-Satellites
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); }
Thursday, 16 June 2011
Wednesday, 1 June 2011
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; }
Thursday, 19 May 2011
Wednesday, 18 May 2011
Subscribe to:
Posts (Atom)