diff --git a/HDOJ/1000_autoAC.cpp b/HDOJ/1000_autoAC.cpp new file mode 100644 index 0000000..7094e82 --- /dev/null +++ b/HDOJ/1000_autoAC.cpp @@ -0,0 +1,10 @@ +#include +#include +using namespace std; +int main() +{ + int a,b; + while(cin>>a>>b) + cout< +using namespace std; +int main() +{ + int n,sum; + while(cin>>n) + { + sum = 0; + for(int i = 1;i <= n;++i) + sum += i; + cout< +#include +using namespace std; +void add ( char a[], char b[] ) +{ + char sum[1010] = {' '}; + int flg = 0; + int temp = 0; + int len_a = strlen ( a ); + int len_b = strlen ( b ); + int i = len_a; + int j = len_b; + for ( ; i > 0; i-- ) + { + if ( j > 0 ) + { + temp = a[i-1] + b[j-1] + flg - 96; + j--; + } + else temp = a[i-1] + flg - 48; + if ( temp >= 10 ) + { + flg = 1; + } + else flg = 0; + temp = temp % 10; + sum[i] = temp + 48; + } + if ( flg == 1 ) sum[0] = 49; + i = 0; + while ( i <= len_ ) + { + if ( sum[i] != ' ' ) cout << sum[i]; + i++; + } + cout << endl; +} +int main() +{ + int N; + while ( cin >> N ) + { + for ( int i = 1; i <= N; i++ ) + { + char a[1000]; + char b[1000]; + cin >> a; + cin >> b; + int len_a = strlen ( a ); + int len_b = strlen ( b ); + cout << "Case " << i << ":\n" << a << " + " << b << " = "; + if ( len_a >= len_ ) + { + add ( a, b ); + } + else add ( b, a ); + if ( i != N ) cout << endl; + } + } + return 0; +} diff --git a/HDOJ/1003_autoAC.cpp b/HDOJ/1003_autoAC.cpp new file mode 100644 index 0000000..55c0aec --- /dev/null +++ b/HDOJ/1003_autoAC.cpp @@ -0,0 +1,36 @@ +#include +int data[100000]; +int main() +{ + int i,j,k,l,sum,b,e,max=0,t; + scanf("%d",&i); + for (j=1;j<=i;j++) + { + max = -100000; + scanf("%d",&k); + for (sum=0, l=0, t=0 , e=0;l=0) + { + sum+=data[l]; + } + else + { + sum = data[l]; + t = l; + } + if (sum>max) + { + max = sum; + b = t; + e = l; + } + } + printf("Case %d:\n",j); + printf("%d %d %d\n",max,b+1,e+1); + if (j != i) + printf("\n"); + } + return 1; +} diff --git a/HDOJ/1004_autoAC.cpp b/HDOJ/1004_autoAC.cpp new file mode 100644 index 0000000..896144f --- /dev/null +++ b/HDOJ/1004_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +char ballons[1000][15]; +int sum[1000]; +int ballons_idx; +int n; +int InBallons(char* tmp) +{ + int i; + for (i=0;imax) + { + max = sum[i]; + idx = i; + } + } + return idx; +} +int main() +{ + int i; + char tmp[15]; + scanf("%d",&n); + while(n) + { + ballons_idx = 0; + memset(sum,0,sizeof(int)*1000); + for (i=0;i +int main() +{ + int f[200],a,b,n,i; + while(scanf("%d%d%d",&a,&b,&n),a||b||n) + { + if(n>2) + { + f[1]=f[2]=1; + for(i=3;i<200;i++) + { + f[i]=(a*f[i-1]+b*f[i-2])%7; + if(f[i-1]==1&&f[i]==1) + break; + } + i-=2; + n=n%i; + if(n==0) + printf("%d\n",f[i]); + else + printf("%d\n",f[n]); + } + else + printf("1\n"); + } + return 0; +} diff --git a/HDOJ/1006_autoAC.cpp b/HDOJ/1006_autoAC.cpp new file mode 100644 index 0000000..1397e6e --- /dev/null +++ b/HDOJ/1006_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +double max(double a,double b,double c){ + if(b>a) a=b; + if(c>a) a=c; + return a; +} +double min(double a,double b,double c){ + if(b>d,d!=-1){ + t=0; + for(int i=0;i<11;i++){ + for(int j=(int)((tmh*i+d/vmh-d/vsm)/tsm);j<=(int)((tmh*(i+1)-d/vmh-d/vsm)/tsm);j++){ + for(int k=(int)((tsm*j+d/vsm-d/vsh)/tsh);k<=(int)((tsm*(j+1)-d/vsm-d/vsh)/tsh);k++){ + start=max(tsh*k+d/vsh,tsm*j+d/vsm,tmh*i+d/vmh); + end=min(tsh*(k+1)-d/vsh,tsm*(j+1)-d/vsm,tmh*(i+1)-d/vmh); + if(start +using namespace std; +#include +#include +struct Point +{ + double x; + double y; +}; +int num; +Point points[100001]; +Point assist[100001]; +inline bool cmpx(Point a ,Point b ) +{ + return a.x < b.x; +} +inline bool cmpy(Point a ,Point b ) +{ + return a.y < b.y; +} +inline double space(Point a, Point b) +{ + return (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y); +} +inline double minBinary(double a,double b) +{ + return apoints[half].x-sqrtMin) + assist[cnt++]=points[i]; + sort(assist,assist+cnt,cmpy); + for (int i=0;isqrtMin) + break; + min=minBinary(min,space(assist[i],assist[j])); + } + return min; +} +int main() +{ + while(scanf("%d",&num)!=EOF&&num) + { + int min=0; + for (int i=0;i +int main() +{ + int i,n,a[101],sum; + while(scanf("%d",&n),n) + { + sum=0; a[0]=0; + for(i=1;i<=n;i++) + scanf("%d",a+i); + for(i=0;ia[i+1]) + { + sum+=(a[i]-a[i+1])*4+5; + } + } + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1009_autoAC.cpp b/HDOJ/1009_autoAC.cpp new file mode 100644 index 0000000..cd92bc6 --- /dev/null +++ b/HDOJ/1009_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +struct Exchange{ + int room; + int javabean; +}; +int cmp( const void *a , const void *b ) +{ + struct Exchange *c = (Exchange *)a; + struct Exchange *d = (Exchange *)b; + if (d->room*1.0/d->javabean > c->room*1.0/c->javabean) + return 1; + else if (d->room*1.0/d->javabean < c->room*1.0/c->javabean) + return -1; + else return 0; +} +double summation(Exchange* ex,int len,int javabeans) +{ + double sum=0; + qsort(ex,len,sizeof(Exchange),cmp); + for(int i=0;i0) + { + sum+=ex[i].room; + javabeans-=ex[i].javabean; + } + else + { + sum+=javabeans*1.0/ex[i].javabean*ex[i].room; + break; + } + } + return sum; +} +int main() +{ + int m,n; + while(scanf("%d%d",&m,&n)!=EOF) + { + if(m==-1&&n==-1) + break; + Exchange* e=new Exchange[n]; + for(int i=0;i +#include +int time,atx,aty,n,m; +char map[26][26]; +bool flag; +void dfs(int x,int y,int t) +{ + if(x<0||x>=n||y<0||y>=m) + return; + if(flag==true||(t==0&&x==atx&&aty==y)) + { + flag=true; + return; + } + int temp=t-abs(x-atx)-abs(y-aty); + if(temp<0 || temp&1) + return; + map[x][y]='X'; + if(map[x+1][y]!='X') + { + dfs(x+1,y,t-1); + if(flag) + return; + } + if(map[x][y+1]!='X') + { + dfs(x,y+1,t-1); + if(flag) + return; + } + if(map[x-1][y]!='X') + { + dfs(x-1,y,t-1); + if(flag) + return; + } + if(map[x][y-1]!='X') + { + dfs(x,y-1,t-1); + if(flag) + return; + } + map[x][y]='.'; +} +int main() +{ + int i,j,x,y,wall; + while(scanf("%d%d%d",&n,&m,&time)&&(n!=0||m!=0||time!=0)) + { + flag=false; + wall=0; + for(i=0;i +#include +using namespace std; +#include +int roomNumber,trooperNumber; +vector path[101]; +int dp[101][101]; +bool visited[101]; +int cost[101]; +int max(int a,int b) +{ + return a>b?a:b; +} +void solve(int deep) +{ + visited[deep]=true; + for (int i=0;i=cost[deep];j--) + for (int index=1;index+j<=trooperNumber;index++) + if(dp[value][index]) + dp[deep][j+index]=max(dp[deep][j+index],dp[deep][j]+dp[value][index]); + } +} +int main() +{ + while (scanf("%d%d",&roomNumber,&trooperNumber)!=EOF) + { + if(roomNumber==-1&&trooperNumber==-1) + break; + for (int i=0;i<=roomNumber;i++) + { + path[i].clear(); + } + memset(dp,0,sizeof(dp)); + memset(visited,0,sizeof(visited)); + int tempA; + for(int i=1;i<=roomNumber;i++) + { + scanf("%d%d",&cost[i],&tempA); + cost[i]=(cost[i]+19)/20; + for (int j=cost[i];j<=trooperNumber;j++) + dp[i][j]=tempA; + } + int tempB; + for(int i=1;i<=roomNumber-1;i++) + { + scanf("%d%d",&tempB,&tempA); + path[tempB].push_back(tempA); + path[tempA].push_back(tempB); + } + if(trooperNumber==0) + printf("0\n"); + else + { + solve(1); + printf("%d\n",dp[1][trooperNumber]); + } + } + return 0; +}