Powered By HC TECH : AutoACer Engine

This commit is contained in:
KiritoTRw 2016-08-12 10:14:21 +08:00 committed by GitHub
parent d635275d42
commit 42d56bbc4b
33 changed files with 1387 additions and 0 deletions

19
HDOJ/1018_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
#include<math.h>
int main(){
int i,temp,N;
int number;
long double member=0;
scanf("%d",&N);
while(N--){
scanf("%d",&number);
member=0;
for(i=1,temp=0;i<=number;i++){
member+=log10(i*1.0);
}
temp=floor(member)+1;
printf("%d\n",temp);
}
getchar();
return 0;
}

36
HDOJ/1019_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "stdio.h"
__int64 s[1000];
__int64 hcf(__int64 a,__int64 b)
{
__int64 r=0;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
return(a);
}
__int64 lcd(__int64 u,__int64 v,__int64 h)
{
return(u*v/h);
}
int main(int argc, char* argv[])
{
int n,m,i;
while(scanf("%d",&n)==1)
{
while(n--)
{
scanf("%d",&m);
for(i=0;i<=m-1;i++)
scanf("%I64d",&s[i]);
for(i=0;i<=m-2;i++)
{
s[i+1]=lcd(s[i],s[i+1],hcf(s[i],s[i+1]));
}
printf("%I64d\n",s[m-1]);
}
}
return 0;
}

42
HDOJ/1020_autoAC.cpp Normal file
View File

@ -0,0 +1,42 @@
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char s[10010];
int main()
{
int n;
scanf("%d",&n);
getchar();
while(n--)
{
int len,i,j,count=1;
memset(s,0,sizeof(s));
scanf("%s",s);
len=strlen(s);
i=0;
j=i+1;
while(j<=len)
{
if(s[i]!=s[j])
{
if(count==1)
{
printf("%c",s[i]);
}
else
{
printf("%d%c",count,s[i]);
}
i=j;
j++;
count=1;
}
else
{
j++;
count++;
}
}
printf("\n");
}
}

12
HDOJ/1021_autoAC.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
if(n%8 == 2||n%8 == 6)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
return 0;
}

46
HDOJ/1022_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<stdio.h>
int main()
{
int n,i,j,k;
char in[10],out[10];
int flag[20];
while(scanf("%d %s %s",&n,in,out)!=EOF)
{
char stack[1000];
int top=-1;
i=j=k=0;
while(j<n+1&&i<n)
{
if(stack[top]==out[i]&&top!=-1)
{
top--;
flag[k]=0;
k++;
i++;
}
else
{
top++;
flag[k]=1;
k++;
stack[top]=in[j];
j++;
}
}
if(k!=2*n)
printf("No.\n");
else
{
printf("Yes.\n");
for(i=0; i<n*2; i++)
{
if(flag[i])
printf("in\n");
else
printf("out\n");
}
}
printf("FINISH\n");
}
return 0;
}

83
HDOJ/1023_autoAC.cpp Normal file
View File

@ -0,0 +1,83 @@
#include<stdio.h>
#include<string.h>
int res[101][200] = {0};
int temp[200] = {0};
void add(int *x, int *y){
int i, t;
for(i=0; x[i]!=0&&y[i]!=0; i++){
x[i] += y[i] -'0';
}
for(i; y[i]!=0; i++){
x[i] += y[i];
}
for(t=0; x[t]!=0; t++){
if(x[t+1]!=0){
x[t+1] += (x[t]-'0')/10;
}
else{
if((x[t]-'0')/10!=0){
x[t+1] += (x[t]-'0')/10+'0';
}
else{
x[t+1] = 0;
}
}
x[t] = (x[t]-'0')%10+'0';
}
}
int* multiple(int *x, int *y){
int i, j, length;
for(i=0; i<200; i++){
temp[i] = 0;
}
for(i=0; x[i]!=0; i++){
for(j=0; y[j]!=0; j++){
if(temp[i+j]!=0){
temp[i+j] += (x[i]-'0')*(y[j]-'0');
}
else{
temp[i+j] += (x[i]-'0')*(y[j]-'0')+'0';
}
}
}
length = 0;
while(temp[length]!=0){
length++;
}
for(i=0; i<length; i++){
temp[i+1] += (temp[i]-'0')/10;
temp[i] = (temp[i]-'0')%10 + '0';
}
if(temp[length]!=0){
temp[length] += '0';
}
while(temp[length]!=0){
if((temp[length]-'0')/10!=0){
temp[length+1] += temp[length]/10+'0';
}
temp[length] = (temp[length]-'0')%10+'0';
length++;
}
return temp;
}
int main(){
int n, i, j;
res[0][0] = '1';
res[1][0] = '1';
for(i=2; i<=100; i++){
for(j=0; j<i; j++){
add(res[i], multiple(res[j], res[i-j-1]));
}
}
while(scanf("%d", &n) != EOF){
i=199;
while(i>=0){
if(res[n][i] != 0){
printf("%c", res[n][i]);
}
i--;
}
printf("\n");
}
return 0;
}

40
HDOJ/1024_autoAC.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <cstdio>
#include <iostream>
const int MAX = 1000005;
using namespace std;
int num[MAX], pre_max[MAX];
inline int max(int a, int b)
{
return a > b ? a : b;
}
int DP(int n, int m)
{
for(int i = 1; i <= m; ++i)
{
int tmp = 0;
for(int k = 1; k <= i; ++k)
tmp += num[k];
pre_max[n] = tmp;
for(int j = i+1; j <= n; ++j)
{
tmp = max(pre_max[j-1], tmp) + num[j];
pre_max[j-1] = pre_max[n];
pre_max[n] = max(pre_max[n], tmp);
}
}
return pre_max[n];
}
int main()
{
int n, m;
while(~scanf("%d%d", &m, &n))
{
for(int i = 1; i <= n; ++i)
{
scanf("%d", &num[i]);
pre_max[i] = 0;
}
printf("%d\n", DP(n, m));
}
return 0;
}

53
HDOJ/1025_autoAC.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[500001];
int dp[500001];
int f[500001];
int binary_search(int k, int l, int h)
{
int mid;
while (l <= h)
{
mid = (l + h)/2;
if (f[mid] <= k)
l = mid + 1;
else
h = mid - 1;
}
return h;
}
int main()
{
int n;
int t = 0;
while (scanf("%d", &n) != EOF)
{
++t;
memset(f, -1, sizeof(f));
int i;
int tmp1,tmp2;
for (i = 0; i < n; ++i)
{
scanf("%d %d", &tmp1, &tmp2);
a[tmp1] = tmp2;
}
dp[1] = 1;
f[1] = a[1];
int len = 1;
for (i = 2; i <= n; ++i)
{
int x = binary_search(a[i], 1, len);
dp[i] = x + 1;
if ( f[i] == -1 || a[i] < f[dp[i]] )
f[dp[i]] = a[i];
if (dp[i] > len)
len = dp[i];
}
if (len == 1)
printf("Case %d:\nMy king, at most %d road can be built.\n\n", t, len);
else
printf("Case %d:\nMy king, at most %d roads can be built.\n\n", t, len);
}
return 0;
}

128
HDOJ/1026_autoAC.cpp Normal file
View File

@ -0,0 +1,128 @@
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N(103),MAXN(0x6ffffff);
struct point
{
int x,y;
point *next;
};
struct path_node
{
int pre_x,pre_y,time;
};
int maze[N][N];
path_node path[N][N];
point *ans;
bool inq[N][N];
queue<point> q;
int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
int n,m;
void init()
{
char x;
getchar();
memset(maze,0,sizeof(maze));
memset(path,0,sizeof(path));
memset(inq,0,sizeof(inq));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%c",&x);
if(x=='X') maze[i][j]=-1;
else if(x!='.') maze[i][j]=x-'0';
else maze[i][j]=0;
path[i][j].time=MAXN;
}
getchar();
}
path[0][0].time=0;
path[0][0].pre_x=-1;
}
inline bool passable(int x,int y)
{
if(x<0||x>n-1||y<0||y>m-1||maze[x][y]==-1)
return false;
return true;
}
void search()
{
point s;
s.x=s.y=0;
q.push(s);
inq[s.x][s.y]=true;
while(!q.empty())
{
point u=q.front();
q.pop();
inq[u.x][u.y]=false;
int nx,ny;
for(int i=0;i<4;i++)
{
nx=u.x+dx[i];
ny=u.y+dy[i];
if(path[nx][ny].time>path[u.x][u.y].time+maze[nx][ny]+1&&passable(nx,ny))
{
path[nx][ny].time=path[u.x][u.y].time+maze[nx][ny]+1;
path[nx][ny].pre_x=u.x;
path[nx][ny].pre_y=u.y;
if(!inq[nx][ny])
{
point np;
np.x=nx,np.y=ny;
q.push(np);
inq[nx][ny]=true;
}
}
}
}
}
void print()
{
if(path[n-1][m-1].time!=MAXN)
{
point *node;
int x=n,y=m,t=0;
while(x!=-1)
{
node=new(point);
if(ans)
node->x=x,node->y=y;
else node->x=n-1,node->y=m-1;
node->next=ans;
ans=node;
x=path[node->x][node->y].pre_x;
y=path[node->x][node->y].pre_y;
}
printf("It takes %d seconds to reach the target position, let me show you the way.\n",
path[n-1][m-1].time);
point *p,*next;
for(p=ans;p;p=next)
{
while(maze[p->x][p->y])
{
printf("%ds:FIGHT AT (%d,%d)\n",++t,p->x,p->y);
maze[p->x][p->y]--;
}
if(p->next)
printf("%ds:(%d,%d)->(%d,%d)\n",++t,p->x,p->y,p->next->x,p->next->y);
next=p->next;
delete p;
}
ans=NULL;
}
else
printf("God please help our poor hero.\n");
printf("FINISH\n");
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
init();
search();
print();
}
}

28
HDOJ/1027_autoAC.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a[10000],coun,n,m,i;
int main()
{
while(cin>>n>>m)
{
for(i=0;i<n;i++)
{
a[i] = i+1;
}
vector<int> iv(a,a+n);
coun = 1;
while(next_permutation(iv.begin(),iv.end()))
{
coun++;
if(coun==m)
break;
}
printf("%d",iv[0]);
for(i=1;i<n;i++)
printf(" %d",iv[i]);
printf("\n");
}
return 0;
}

31
HDOJ/1028_autoAC.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int n;
int c1[125], c2[125];
while(~scanf("%d", &n))
{
for(int i = 0; i <= n; ++i)
{
c1[i] = 1;
c2[i] = 0;
}
for(int i = 2; i <= n; ++i)
{
for(int j = 0; j <= n; ++j)
{
for(int k = 0; k <= n/i*i; k += i)
c2[j+k] += c1[j];
}
for(int j = 0; j <= n; ++j)
{
c1[j] = c2[j];
c2[j] = 0;
}
}
printf("%d\n", c1[n]);
}
return 0;
}

27
HDOJ/1029_autoAC.cpp Normal file
View File

@ -0,0 +1,27 @@
#include<stdio.h>
int main()
{
long n,num,cnt,res;
while(EOF != scanf("%d",&n))
{
cnt = 0;
while(n--)
{
scanf("%d",&num);
if(0 == cnt)
{
res = num;
cnt++;
}
else
{
if(res == num)
cnt++;
else
cnt--;
}
}
printf("%d\n",res);
}
return 0;
}

40
HDOJ/1030_autoAC.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
#include <cmath>
using namespace std;
struct Note
{
int x;
int y;
int z;
};
int main()
{
Note a,b;
int m,n;
while(cin>>m>>n)
{
int sa=0;
int sb=0;
int k;
int t=ceil(sqrt(m));
a.x=t;
k=(m-(t-1)*(t-1))/2;
a.y=t-k;
k=((2*t-1)-m+(t-1)*(t-1))/2;
a.z=t-k;
if((2*t-1-m+(t-1)*(t-1))%2==0) sa=1;
if(sa==0) a.z=a.z-1;
t=ceil(sqrt(n));
b.x=t;
k=(n-(t-1)*(t-1))/2;
b.y=t-k;
k=((2*t-1)-n+(t-1)*(t-1))/2;
b.z=t-k;
if((2*t-1-n+(t-1)*(t-1))%2==0) sb=1;;
if(sb==0) b.z=b.z-1;
int ans=0;
ans=abs(a.x-b.x)+abs(a.y-b.y)+abs(a.z-b.z);
cout<<ans<<endl;
}
return 0;
}

52
HDOJ/1031_autoAC.cpp Normal file
View File

@ -0,0 +1,52 @@
#include<iostream>
#include<stdio.h>
#include<fstream>
using namespace std;
struct Node{
int num;
double times;
};
Node T[1000];
int cmp1( const void *a , const void *b )
{
struct Node *c = (Node *)a;
struct Node *d = (Node *)b;
if(c->times != d->times) return d->times - c->times;
}
int cmp2( const void *a , const void *b )
{
struct Node *c = (Node *)a;
struct Node *d = (Node *)b;
return c->num > d->num ? -1 : 1 ;
}
int main()
{
int i,j,k,n,m;
double temp;
while(EOF != scanf("%d %d %d",&n,&m,&k))
{
for(i=0;i<m;i++)
{
T[i].num = i+1 ;
T[i].times = 0;
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%lf",&temp);
T[j].times += temp;
}
}
qsort(T,m,sizeof(T[0]),cmp1);
qsort(T,k,sizeof(T[0]),cmp2);
for(i=0;i<k;i++)
{
printf("%d",T[i].num);
if(i!= k-1)
printf(" ");
}
printf("\n");
}
return 0;
}

40
HDOJ/1032_autoAC.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
using namespace std;
#define MAXNUM 1000000 + 1
int result[MAXNUM];
int main()
{
int beg,end,max,count,temp;
while(cin>>beg>>end)
{
cout<<beg<<" "<<end<<" ";
if(beg > end)
{
temp = beg;beg = end;end = temp;
}
max = count = 0;
for(int t = beg;t <= end;++t)
{
if(result[t])
count = result[t];
else
{
temp = t;
count = 1;
while(temp != 1)
{
if(temp%2 == 0)
temp = temp/2;
else
temp = 3*temp + 1;
++count;
}
result[t] = count;
}
if(count > max)
max = count;
}
cout<<max<<endl;
}
return 0;
}

66
HDOJ/1033_autoAC.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
while (cin>>input)
{
cout<<"300 420 moveto"<<endl;
cout<<"310 420 lineto"<<endl;
int x=310,y=420;
int len=input.length();
int flag=1;
for(int i=0;i<len;i++)
{
if(input[i]=='A')
{
switch(flag)
{
case 1:
y-=10;
flag=2;
break;
case 2:
x-=10;
flag=3;
break;
case 3:
y+=10;
flag=4;
break;
case 4:
x+=10;
flag=1;
break;
}
cout<<x<<" "<<y<<" lineto"<<endl;
}
else
{
switch(flag)
{
case 1:
y+=10;
flag=4;
break;
case 2:
x+=10;
flag=1;
break;
case 3:
y-=10;
flag=2;
break;
case 4:
x-=10;
flag=3;
break;
}
cout<<x<<" "<<y<<" lineto"<<endl;
}
}
cout<<"stroke\nshowpage"<<endl;
}
return 0;
}

60
HDOJ/1034_autoAC.cpp Normal file
View File

@ -0,0 +1,60 @@
#include<iostream>
using namespace std;
int T[500],T1[500],n;
int check()
{
int temp = T[0];
for(int j=1;j<n;j++)
{
if(temp != T[j])
return -1;
}
return temp;
}
bool isEv(int num)
{
return num%2==0?true:false;
}
int main()
{
int i,k,cnt,res;
while(scanf("%d",&n) && n)
{
for(i=0;i<n;i++)
{
scanf("%d",&T[i]);
}
cnt =0;
res = -1;
while(1)
{
res = check();
if(res != -1)
break;
for(i=0;i<n;i++)
{
T1[i] = T[i]/2;
}
for(i=0;i<n;i++)
{
if(i ==n-1)
{
T1[0] += T[n-1]/2;
}
else
{
T1[i+1] += T[i]/2;
}
}
for(i=0;i<n;i++)
{
if(false == isEv(T1[i]))
T1[i]++;
T[i] = T1[i];
}
cnt++;
}
printf("%d %d\n",cnt,res);
}
return 0;
}

54
HDOJ/1035_autoAC.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <stdio.h>
int maze[11][11];
int r,c,b;
int idx;
void step(int x,int y)
{
int t;
if(x<0||x>=r||y<0||y>=c)
{
printf("%d step(s) to exit\n",idx-999);
return;
}
if(maze[x][y]>=1000)
{
printf("%d step(s) before a loop of %d step(s)\n",maze[x][y]-1000,idx-maze[x][y]+1);
return;
}
t=maze[x][y];
idx++;
maze[x][y]=idx;
switch (t)
{
case 'N':
step(x-1,y);
break;
case 'S':
step(x+1,y);
break;
case 'E':
step(x,y+1);
break;
case 'W':
step(x,y-1);
break;
}
}
int main()
{
int i,j;
while (scanf("%d%d",&r,&c),r||c)
{
scanf("%d",&b);
getchar();
for (i=0;i<r;i++)
{
for (j=0;j<c;j++)
maze[i][j]=getchar();
getchar();
}
idx=999;
step(0,b-1);
}
return 0;
}

43
HDOJ/1036_autoAC.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n;
double d;
char* time = new char[8];
scanf("%d%lf", &n, &d);
int num;
while(scanf("%d", &num) != EOF)
{
int sec = 0;
int flag = 0;
for(int i = 0; i < n; i++)
{
scanf("%s", time);
if(time[0] == '-')
{
flag = 1;
}
else
{
sec += (time[0] - '0') * 3600 + ((time[2] - '0') * 10 + time[3] - '0') * 60 + (time[5] - '0') * 10 + time[6] - '0';
}
}
if(flag == 0)
{
sec = int(sec * 1.0 / d + 0.5);
int minute = sec / 60;
int second = sec % 60;
printf("%3d: %d:", num, minute);
if(second < 10)
printf("0");
printf("%d min/km\n", second);
}
else
{
printf("%3d: -\n", num);
}
}
return 0;
}

14
HDOJ/1037_autoAC.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <iostream>
using namespace std;
int main()
{
int a, b, c, min;
while (cin >> a >> b >> c) {
min = a;
if (b < min) min = b;
if (c < min) min = c;
if (min > 168) cout << "NO CRASH" << endl;
else cout << "CRASH " << min << endl;
}
return 0;
}

20
HDOJ/1038_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
const float pi = 3.1415927;
float diameter_inch;
int circle;
float time_sec;
int count = 1;
while(cin>>diameter_inch>>circle>>time_sec && circle != 0){
float distance;
float time_hour;
float speed;
distance = pi * diameter_inch * circle / 5280 / 12;
time_hour = time_sec / 3600;
speed = distance / time_hour;
cout<<"Trip #"<<count++<<": ";
cout<<fixed<<setprecision(2)<<distance<<" "<<speed<<endl;
}
}

44
HDOJ/1039_autoAC.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
int isvowel(char c){
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
return 1;
else
return 0;
}
int isA(char str[]){
int i=0,vowel=0,consonant=0,k;
for(k=0;k<strlen(str);k++){
if(isvowel(str[k])){
i=1;
vowel++;
consonant=0;
if(vowel>2)
return 0;
}
else{
consonant++;
vowel=0;
if(consonant>2)
return 0;
}
if(str[k]!='e'&&str[k]!='o'&&str[k]==str[k+1])
return 0;
}
if(!i)
return 0;
else
return 1;
}
int main(){
char str[25];
while(~scanf("%s",str)){
if(!strcmp(str,"end"))
break;
if(isA(str)){
printf("<%s> is acceptable.\n",str);
}
else
printf("<%s> is not acceptable.\n",str);
}
}

23
HDOJ/1040_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
int t, n, i;
int *d;
cin >> t;
while (t--) {
cin >> n;
d = (int *)malloc(sizeof(int)*n);
for (i = 0; i < n; i++) {
cin >> d[i];
}
sort (d, d+n);
cout << d[0];
for (i = 1; i < n; i++) {
cout << " " << d[i];
}
cout << endl;
}
return 0;
}

29
HDOJ/1041_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<iostream>
#include<string>
using namespace std;
string add(string s1,string s2){
if(s1.length()<s2.length()){
string temp=s1;
s1=s2;
s2=temp;
}
for(int i=s1.length()-1,j=s2.length ()-1;i>=0;i--,j--){
s1[i]=char(s1[i]+( j>=0 ? s2[j]-'0' : 0));
if(s1[i]-'0'>=10) {
s1[i]=char( (s1[i]-'0')%10+'0' );
if(i) s1[i-1]++;
else s1="1"+s1;
}
}
return s1;
}
string f[1005];
int main(){
int n;
f[1]="0"; f[2]="1"; f[3]="1"; f[4]="3"; f[5]="5"; f[6]="11";
for(int i=7;i<=1004;i++)
f[i]=add( f[i-1], add(f[i-2],f[i-2]) );
while(scanf("%d",&n)==1)
cout<<f[n]<<endl;
return 0;
}

25
HDOJ/1042_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<stdio.h>
int main()
{
int a[10000];
int i,j,c,m,n;
while(scanf("%d",&n)!=EOF){
a[0]=1;
m=0;
for(i=1;i<=n;i++)
{
c=0;
for(j=0;j<=m;j++)
{
a[j]=a[j]*i+c;
c=a[j]/10000;
a[j]=a[j]%10000;
}
if(c>0) {m++;a[m]=c;}
}
printf("%d",a[m]);
for(i=m-1;i>=0;i--) printf("%4.4d",a[i]);
printf("\n");
}
return 0;
}

1
HDOJ/1043_autoAC.cpp Normal file
View File

@ -0,0 +1 @@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x

149
HDOJ/1044_autoAC.cpp Normal file
View File

@ -0,0 +1,149 @@
#include<iostream>
#include<queue>
using namespace std;
char map[50][50];
int distan[12][12];
int jewels[12][3];
int mark[50][50];
int visit[12];
int sx,sy,ex,ey,dijige,youjige,cancollect,maxjewels,jieshu;
int u,n,m,t,zhubao,flag;
struct node
{
int x,y,step;
}w,p;
int dir[4][2]={1,0,-1,0,0,1,0,-1};
int bfs(int qx,int qy,int mx,int my)
{
queue<node> q;
w.x=qx;w.y=qy;w.step=0;
while(!q.empty())
q.pop();
q.push(w);
while(!q.empty())
{
p=q.front();
q.pop();
if(p.x==mx&&p.y==my)
return p.step;
for(int i=0;i<4;i++)
{
w.x=p.x+dir[i][0];
w.y=p.y+dir[i][1];
w.step=p.step+1;
if(w.x>=0&&w.x<n&&w.y>=0&&w.y<m&&map[w.x][w.y]!='*'&&mark[w.x][w.y]==0)
{
mark[w.x][w.y]=1;
q.push(w);
}
}
}
return 1000001;
}
void dfs(int weizhi,int step,int jewel)
{
if(step<0) return;
if(jieshu==1) return;
if(jewel==cancollect&&step>=0&&weizhi==zhubao+1)
{
maxjewels=jewel;
flag=1;
jieshu=1;
return;
}
if(weizhi==zhubao+1&&step>=0)
{
flag=1;
if(jewel>maxjewels)
maxjewels=jewel;
return;
}
for(int i=0;i<zhubao+2;i++)
{
if(visit[i]==0)
{
visit[i]=1;
dfs(i,step-distan[weizhi][i],jewel+jewels[i][2]);
visit[i]=0;
}
}
return;
}
int main()
{
cin>>u;
youjige=u;
dijige=1;
while(u--)
{
memset(jewels,0,sizeof(jewels));
cin>>m>>n>>t>>zhubao;
for(int i=0;i<zhubao;i++)
cin>>jewels[i][2];
memset(distan,1000001,sizeof(distan));
memset(mark,0,sizeof(mark));
memset(visit,0,sizeof(visit));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>map[i][j];
if(map[i][j]=='@')
{
sx=i;
sy=j;
}
if(map[i][j]=='<')
{
ex=i;
ey=j;
}
if(map[i][j]>='A'&&map[i][j]<='J')
{
jewels[map[i][j]-'A'][0]=i;
jewels[map[i][j]-'A'][1]=j;
}
}
}
cancollect=0;
for(int i=0;i<zhubao;i++)
{
distan[zhubao][i]=bfs(sx,sy,jewels[i][0],jewels[i][1]);
memset(mark,0,sizeof(mark));
distan[zhubao+1][i]=bfs(ex,ey,jewels[i][0],jewels[i][1]);
memset(mark,0,sizeof(mark));
distan[i][zhubao]=distan[zhubao][i];
distan[i][zhubao+1]=distan[zhubao+1][i];
if(distan[zhubao][i]!=1000001)
cancollect+=jewels[i][2];
}
distan[zhubao][zhubao+1]=bfs(sx,sy,ex,ey);
memset(mark,0,sizeof(mark));
distan[zhubao+1][zhubao]=distan[zhubao][zhubao+1];
for(int i=0;i<zhubao;i++)
for(int j=0;j<zhubao;j++)
{
if(i<j)
{
distan[i][j]=bfs(jewels[i][0],jewels[i][1],jewels[j][0],jewels[j][1]);
memset(mark,0,sizeof(mark));
}
else
distan[i][j]=distan[j][i];
}
visit[zhubao]=1;
maxjewels=0;
flag=0;
jieshu=0;
dfs(zhubao,t,0);
cout<<"Case "<<dijige<<':'<<endl;
if(flag==1)
cout<<"The best score is "<<maxjewels<<'.'<<endl;
else
cout<<"Impossible"<<endl;
if(dijige<youjige)
cout<<endl;
dijige++;
}
return 0;
}

47
HDOJ/1045_autoAC.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <stdio.h>
char maze[6][6];
int num,result;
bool placeable(int row,int col)
{
int i;
i=col-1;
while(i>=0&&maze[row][i]!='X')
if(maze[row][i--]=='*') return false;
i=row-1;
while(i>=0&&maze[i][col]!='X')
if(maze[i--][col]=='*') return false;
return true;
}
void dfs(int cnt,int max)
{
int row,col;
if(cnt==num*num)
{
max>result?result=max:1;
return;
}
else
{
row=cnt/num;
col=cnt%num;
if(maze[row][col]=='.'&&placeable(row,col))
{
maze[row][col]='*';
dfs(cnt+1,max+1);
maze[row][col]='.';
}
dfs(cnt+1,max);
}
}
int main()
{
while(scanf("%d",&num)!=EOF&&num)
{
for(int i=0;i<num;i++)
scanf("%s",maze[i]);
result=0;
dfs(0,0);
printf("%d\n",result);
}
return 0;
}

23
HDOJ/1046_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 1; i < n + 1; ++i)
{
printf("Scenario #%d:\n", i);
int s, t;
scanf("%d%d",&s,&t);
double sum;
sum = s*t;
if ((s*t)%2)
printf("%.2f\n", sum+sqrt(2)-1);
else printf("%.2f\n", (double)sum);
printf("\n");
}
return 0;
}

41
HDOJ/1047_autoAC.cpp Normal file
View File

@ -0,0 +1,41 @@
#include<iostream>
#include<cstring>
#include<string>
#define maxn 300
using namespace std;
int numx[maxn],numy[maxn],n;
string str,tmp;
string Add(string x,string y){
string res="";
memset(numx,0,sizeof(numx));
memset(numy,0,sizeof(numy));
int lenx=x.size(),leny=y.size();
int maxlen=lenx>leny ? lenx:leny;
for(int i=0;i<lenx;i++)numx[lenx-i-1]=x[i]-'0';
for(int i=0;i<leny;i++)numy[leny-i-1]=y[i]-'0';
for(int i=0;i<=maxlen;i++){
numx[i]+=numy[i];
if(numx[i]>9){
numx[i+1]+=numx[i]/10;
numx[i]%=10;
}
}
int i=maxlen+2;
for(;i>0&&!numx[i];)i--;
for(;i>=0;i--)res+=numx[i]+'0';
return res;
}
int main()
{
while(cin>>n){
while(n--){
string sum="0";
while(cin>>str&&str!="0"){
sum=Add(sum,str);
}
cout<<sum<<endl;
if(n)cout<<endl;
}
}
return 0;
}

34
HDOJ/1048_autoAC.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <iostream>
#include <string>
using namespace std;
const int LEN = 210;
char engChars[30] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
char aLine[LEN];
void decipher()
{
for (int i = 0;i < strlen(aLine);i ++)
{
if (isalpha(aLine[i]))
{
int offset = (aLine[i] - 'A' + 26 - 5) % 26;
aLine[i] = engChars[offset];
}
}
}
int main ()
{
while (gets(aLine))
{
if (strcmp(aLine,"ENDOFINPUT") == 0)
break;
while (1)
{
gets(aLine);
if (strcmp(aLine,"END") == 0)
break;
decipher();
printf("%s\n",aLine);
}
}
return 0;
}

7
HDOJ/1049_autoAC.cpp Normal file
View File

@ -0,0 +1,7 @@
#include<stdio.h>
int main(){
int n,u,d,t;
while(scanf("%d%d%d",&n,&u,&d)!=-1&&n)
printf("%d\n",(n-u)%(u-d)?(2*((n-u)/(u-d)+1)+1):(2*((n-u)/(u-d))+1));
return 0;
}

30
HDOJ/1050_autoAC.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <iostream>
#include <algorithm>
using namespace std;
int f[201];
int main()
{
int t, n, i, j, s, e;
cin >> t;
while( t-- ){
memset( f, 0, sizeof(f) );
cin >> n;
for( i=0; i<n; i++ ){
cin >> s >> e;
s = (s+1)/2;
e = (e+1)/2;
if( s > e ){
int temp = s;
s = e;
e = temp;
}
for( j=s; j<=e; j++)
f[j]++;
}
int consume = 0;
for( i=1; i<=200; i++ )
consume = max( consume, f[i] );
cout << consume*10 << endl;
}
return 0;
}