From 5ccba6fd68a701c5efe9d88dc47983f0b0ca308a Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 13 Aug 2016 17:16:08 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine --- HDOJ/1200_autoAC.cpp | 35 +++++++++++ HDOJ/1201_autoAC.cpp | 32 ++++++++++ HDOJ/1202_autoAC.cpp | 41 +++++++++++++ HDOJ/1203_autoAC.cpp | 29 +++++++++ HDOJ/1204_autoAC.cpp | 24 ++++++++ HDOJ/1205_autoAC.cpp | 25 ++++++++ HDOJ/1207_autoAC.cpp | 77 ++++++++++++++++++++++++ HDOJ/1208_autoAC.cpp | 34 +++++++++++ HDOJ/1209_autoAC.cpp | 47 +++++++++++++++ HDOJ/1210_autoAC.cpp | 20 +++++++ HDOJ/1211_autoAC.cpp | 37 ++++++++++++ HDOJ/1212_autoAC.cpp | 18 ++++++ HDOJ/1213_autoAC.cpp | 37 ++++++++++++ HDOJ/1214_autoAC.cpp | 12 ++++ HDOJ/1215_autoAC.cpp | 26 ++++++++ HDOJ/1216_autoAC.cpp | 33 ++++++++++ HDOJ/1217_autoAC.cpp | 77 ++++++++++++++++++++++++ HDOJ/1218_autoAC.cpp | 53 ++++++++++++++++ HDOJ/1219_autoAC.cpp | 17 ++++++ HDOJ/1220_autoAC.cpp | 8 +++ HDOJ/1221_autoAC.cpp | 28 +++++++++ HDOJ/1222_autoAC.cpp | 20 +++++++ HDOJ/1223_autoAC.cpp | 88 +++++++++++++++++++++++++++ HDOJ/1224_autoAC.cpp | 60 +++++++++++++++++++ HDOJ/1225_autoAC.cpp | 107 +++++++++++++++++++++++++++++++++ HDOJ/1226_autoAC.cpp | 73 ++++++++++++++++++++++ HDOJ/1227_autoAC.cpp | 38 ++++++++++++ HDOJ/1228_autoAC.cpp | 61 +++++++++++++++++++ HDOJ/1229_autoAC.cpp | 16 +++++ HDOJ/1230_autoAC.cpp | 95 +++++++++++++++++++++++++++++ HDOJ/1231_autoAC.cpp | 36 +++++++++++ HDOJ/1232_autoAC.cpp | 38 ++++++++++++ HDOJ/1233_autoAC.cpp | 63 +++++++++++++++++++ HDOJ/1234_autoAC.cpp | 50 ++++++++++++++++ HDOJ/1235_autoAC.cpp | 24 ++++++++ HDOJ/1236_autoAC.cpp | 40 +++++++++++++ HDOJ/1237_autoAC.cpp | 37 ++++++++++++ HDOJ/1239_autoAC.cpp | 48 +++++++++++++++ HDOJ/1240_autoAC.cpp | 76 +++++++++++++++++++++++ HDOJ/1241_autoAC.cpp | 45 ++++++++++++++ HDOJ/1242_autoAC.cpp | 103 +++++++++++++++++++++++++++++++ HDOJ/1243_autoAC.cpp | 40 +++++++++++++ HDOJ/1244_autoAC.cpp | 53 ++++++++++++++++ HDOJ/1245_autoAC.cpp | 94 +++++++++++++++++++++++++++++ HDOJ/1246_autoAC.cpp | 21 +++++++ HDOJ/1247_autoAC.cpp | 60 +++++++++++++++++++ HDOJ/1248_autoAC.cpp | 26 ++++++++ HDOJ/1249_autoAC.cpp | 13 ++++ HDOJ/1250_autoAC.cpp | 44 ++++++++++++++ HDOJ/1251_autoAC.cpp | 27 +++++++++ HDOJ/1252_autoAC.cpp | 90 ++++++++++++++++++++++++++++ HDOJ/1253_autoAC.cpp | 65 ++++++++++++++++++++ HDOJ/1254_autoAC.cpp | 106 ++++++++++++++++++++++++++++++++ HDOJ/1255_autoAC.cpp | 91 ++++++++++++++++++++++++++++ HDOJ/1256_autoAC.cpp | 41 +++++++++++++ HDOJ/1257_autoAC.cpp | 29 +++++++++ HDOJ/1258_autoAC.cpp | 68 +++++++++++++++++++++ HDOJ/1259_autoAC.cpp | 21 +++++++ HDOJ/1260_autoAC.cpp | 46 ++++++++++++++ HDOJ/1261_autoAC.cpp | 46 ++++++++++++++ HDOJ/1262_autoAC.cpp | 30 ++++++++++ HDOJ/1263_autoAC.cpp | 52 ++++++++++++++++ HDOJ/1264_autoAC.cpp | 49 +++++++++++++++ HDOJ/1265_autoAC.cpp | 18 ++++++ HDOJ/1266_autoAC.cpp | 36 +++++++++++ HDOJ/1267_autoAC.cpp | 30 ++++++++++ HDOJ/1268_autoAC.cpp | 52 ++++++++++++++++ HDOJ/1269_autoAC.cpp | 57 ++++++++++++++++++ HDOJ/1270_autoAC.cpp | 58 ++++++++++++++++++ HDOJ/1271_autoAC.cpp | 43 +++++++++++++ HDOJ/1272_autoAC.cpp | 74 +++++++++++++++++++++++ HDOJ/1273_autoAC.cpp | 9 +++ HDOJ/1274_autoAC.cpp | 100 +++++++++++++++++++++++++++++++ HDOJ/1275_autoAC.cpp | 35 +++++++++++ HDOJ/1276_autoAC.cpp | 61 +++++++++++++++++++ HDOJ/1277_autoAC.cpp | 76 +++++++++++++++++++++++ HDOJ/1278_autoAC.cpp | 64 ++++++++++++++++++++ HDOJ/1279_autoAC.cpp | 28 +++++++++ HDOJ/1280_autoAC.cpp | 36 +++++++++++ HDOJ/1281_autoAC.cpp | 84 ++++++++++++++++++++++++++ HDOJ/1282_autoAC.cpp | 34 +++++++++++ HDOJ/1283_autoAC.cpp | 27 +++++++++ HDOJ/1284_autoAC.cpp | 15 +++++ HDOJ/1285_autoAC.cpp | 60 +++++++++++++++++++ HDOJ/1286_autoAC.cpp | 26 ++++++++ HDOJ/1287_autoAC.cpp | 43 +++++++++++++ HDOJ/1288_autoAC.cpp | 50 ++++++++++++++++ HDOJ/1289_autoAC.cpp | 14 +++++ HDOJ/1290_autoAC.cpp | 11 ++++ HDOJ/1292_autoAC.cpp | 37 ++++++++++++ HDOJ/1293_autoAC.cpp | 44 ++++++++++++++ HDOJ/1294_autoAC.cpp | 65 ++++++++++++++++++++ HDOJ/1295_autoAC.cpp | 11 ++++ HDOJ/1296_autoAC.cpp | 68 +++++++++++++++++++++ HDOJ/1297_autoAC.cpp | 39 ++++++++++++ HDOJ/1298_autoAC.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/1299_autoAC.cpp | 51 ++++++++++++++++ 97 files changed, 4536 insertions(+) create mode 100644 HDOJ/1200_autoAC.cpp create mode 100644 HDOJ/1201_autoAC.cpp create mode 100644 HDOJ/1202_autoAC.cpp create mode 100644 HDOJ/1203_autoAC.cpp create mode 100644 HDOJ/1204_autoAC.cpp create mode 100644 HDOJ/1205_autoAC.cpp create mode 100644 HDOJ/1207_autoAC.cpp create mode 100644 HDOJ/1208_autoAC.cpp create mode 100644 HDOJ/1209_autoAC.cpp create mode 100644 HDOJ/1210_autoAC.cpp create mode 100644 HDOJ/1211_autoAC.cpp create mode 100644 HDOJ/1212_autoAC.cpp create mode 100644 HDOJ/1213_autoAC.cpp create mode 100644 HDOJ/1214_autoAC.cpp create mode 100644 HDOJ/1215_autoAC.cpp create mode 100644 HDOJ/1216_autoAC.cpp create mode 100644 HDOJ/1217_autoAC.cpp create mode 100644 HDOJ/1218_autoAC.cpp create mode 100644 HDOJ/1219_autoAC.cpp create mode 100644 HDOJ/1220_autoAC.cpp create mode 100644 HDOJ/1221_autoAC.cpp create mode 100644 HDOJ/1222_autoAC.cpp create mode 100644 HDOJ/1223_autoAC.cpp create mode 100644 HDOJ/1224_autoAC.cpp create mode 100644 HDOJ/1225_autoAC.cpp create mode 100644 HDOJ/1226_autoAC.cpp create mode 100644 HDOJ/1227_autoAC.cpp create mode 100644 HDOJ/1228_autoAC.cpp create mode 100644 HDOJ/1229_autoAC.cpp create mode 100644 HDOJ/1230_autoAC.cpp create mode 100644 HDOJ/1231_autoAC.cpp create mode 100644 HDOJ/1232_autoAC.cpp create mode 100644 HDOJ/1233_autoAC.cpp create mode 100644 HDOJ/1234_autoAC.cpp create mode 100644 HDOJ/1235_autoAC.cpp create mode 100644 HDOJ/1236_autoAC.cpp create mode 100644 HDOJ/1237_autoAC.cpp create mode 100644 HDOJ/1239_autoAC.cpp create mode 100644 HDOJ/1240_autoAC.cpp create mode 100644 HDOJ/1241_autoAC.cpp create mode 100644 HDOJ/1242_autoAC.cpp create mode 100644 HDOJ/1243_autoAC.cpp create mode 100644 HDOJ/1244_autoAC.cpp create mode 100644 HDOJ/1245_autoAC.cpp create mode 100644 HDOJ/1246_autoAC.cpp create mode 100644 HDOJ/1247_autoAC.cpp create mode 100644 HDOJ/1248_autoAC.cpp create mode 100644 HDOJ/1249_autoAC.cpp create mode 100644 HDOJ/1250_autoAC.cpp create mode 100644 HDOJ/1251_autoAC.cpp create mode 100644 HDOJ/1252_autoAC.cpp create mode 100644 HDOJ/1253_autoAC.cpp create mode 100644 HDOJ/1254_autoAC.cpp create mode 100644 HDOJ/1255_autoAC.cpp create mode 100644 HDOJ/1256_autoAC.cpp create mode 100644 HDOJ/1257_autoAC.cpp create mode 100644 HDOJ/1258_autoAC.cpp create mode 100644 HDOJ/1259_autoAC.cpp create mode 100644 HDOJ/1260_autoAC.cpp create mode 100644 HDOJ/1261_autoAC.cpp create mode 100644 HDOJ/1262_autoAC.cpp create mode 100644 HDOJ/1263_autoAC.cpp create mode 100644 HDOJ/1264_autoAC.cpp create mode 100644 HDOJ/1265_autoAC.cpp create mode 100644 HDOJ/1266_autoAC.cpp create mode 100644 HDOJ/1267_autoAC.cpp create mode 100644 HDOJ/1268_autoAC.cpp create mode 100644 HDOJ/1269_autoAC.cpp create mode 100644 HDOJ/1270_autoAC.cpp create mode 100644 HDOJ/1271_autoAC.cpp create mode 100644 HDOJ/1272_autoAC.cpp create mode 100644 HDOJ/1273_autoAC.cpp create mode 100644 HDOJ/1274_autoAC.cpp create mode 100644 HDOJ/1275_autoAC.cpp create mode 100644 HDOJ/1276_autoAC.cpp create mode 100644 HDOJ/1277_autoAC.cpp create mode 100644 HDOJ/1278_autoAC.cpp create mode 100644 HDOJ/1279_autoAC.cpp create mode 100644 HDOJ/1280_autoAC.cpp create mode 100644 HDOJ/1281_autoAC.cpp create mode 100644 HDOJ/1282_autoAC.cpp create mode 100644 HDOJ/1283_autoAC.cpp create mode 100644 HDOJ/1284_autoAC.cpp create mode 100644 HDOJ/1285_autoAC.cpp create mode 100644 HDOJ/1286_autoAC.cpp create mode 100644 HDOJ/1287_autoAC.cpp create mode 100644 HDOJ/1288_autoAC.cpp create mode 100644 HDOJ/1289_autoAC.cpp create mode 100644 HDOJ/1290_autoAC.cpp create mode 100644 HDOJ/1292_autoAC.cpp create mode 100644 HDOJ/1293_autoAC.cpp create mode 100644 HDOJ/1294_autoAC.cpp create mode 100644 HDOJ/1295_autoAC.cpp create mode 100644 HDOJ/1296_autoAC.cpp create mode 100644 HDOJ/1297_autoAC.cpp create mode 100644 HDOJ/1298_autoAC.cpp create mode 100644 HDOJ/1299_autoAC.cpp diff --git a/HDOJ/1200_autoAC.cpp b/HDOJ/1200_autoAC.cpp new file mode 100644 index 0000000..f320179 --- /dev/null +++ b/HDOJ/1200_autoAC.cpp @@ -0,0 +1,35 @@ +#include +#include +int main() +{ + char s[1000],a[100][100]; + int i,j,k,l,m,n,t,f,g,len; + while(scanf("%d",&n)!=EOF&&n) + { t=-1; + getchar(); + gets(s);len=strlen(s); + for(i=0,j=-1;s[i]!='\0';i++) + { + if(i%n==0) + { t++;j++;k=0;} + if(t%2==0) + { + a[j][k++]=s[i]; + } + if(t%2==1) + { + f=i+n-1; + for(g=f;g>=i;g--) + a[j][k++]=s[g]; + i=i+n-1; + } + } + for(i=0;i +int leap(int year) +{ + if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) { + return 1; + } + return 0; +} +int main() +{ + int T; + scanf("%d", &T); + int year, month, day; + while (T--) { + scanf("%d-%d-%d", &year, &month, &day); + int sum = 365 * 18; + for (int i = 1; i < 18; i++) { + sum += leap(i + year); + } + if (month <= 2) { + sum += leap(year); + } else { + sum += leap(year + 18); + } + if (month == 2 && day == 29) { + printf("-1\n"); + } else { + printf("%d\n", sum); + } + } + return 0; +} diff --git a/HDOJ/1202_autoAC.cpp b/HDOJ/1202_autoAC.cpp new file mode 100644 index 0000000..d747a76 --- /dev/null +++ b/HDOJ/1202_autoAC.cpp @@ -0,0 +1,41 @@ +#include +#include +int point(double ); +using namespace std; +int main() +{ + int n; + while(cin>>n) + { + double sum=0,s,p,c=0; + while(n--) + { + cin>>s>>p; + if(p==-1) + continue; + else + { + sum+=s; + c+=s*point(p); + } + } + if(c==0) + cout<<"-1\n"; + else + cout<=90) + return 4; + else if(g>=80) + return 3; + else if(g>=70) + return 2; + else if(g>=60) + return 1; + else + return 0; +} diff --git a/HDOJ/1203_autoAC.cpp b/HDOJ/1203_autoAC.cpp new file mode 100644 index 0000000..22c6a8f --- /dev/null +++ b/HDOJ/1203_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +using namespace std; +int a[10002]; +double b[10002]; +double p[10002]; +int n,m; +void dp() +{ + memset(p,0,sizeof(p)); + for(int i=1;i<=m;++i) + { + for(int j=n;j>=a[i];--j) + p[j]=max(p[j],1-(1-p[j-a[i]])*(1-b[i])); + } +} +int main() +{ + while(cin>>n>>m&&(m+n)) + { + for(int i=1;i<=m;++i) + cin>>a[i]>>b[i]; + dp(); + printf("%.1f%%\n",p[n]*100); + } + return 0; +} diff --git a/HDOJ/1204_autoAC.cpp b/HDOJ/1204_autoAC.cpp new file mode 100644 index 0000000..b316fe7 --- /dev/null +++ b/HDOJ/1204_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +using namespace std; +int main() +{ + int N,M; + double p,q,rate,k; + while(cin>>N>>M>>p>>q) + { + if(N==0){cout<<"0.00"< +#define x 1000000 +#define max(a,b) a>b?a:b +int i,n,T,Max; +int a[x]; +int main() +{ + scanf("%d",&T); + while(T--) + { + __int64 sum=0; + scanf("%d",&n); + Max=0; + for(i=0;i=Max) printf("Yes\n"); + else printf("No\n"); + } + return 0; +} diff --git a/HDOJ/1207_autoAC.cpp b/HDOJ/1207_autoAC.cpp new file mode 100644 index 0000000..5b2eb94 --- /dev/null +++ b/HDOJ/1207_autoAC.cpp @@ -0,0 +1,77 @@ +#include +#include +using namespace std; +int a[65]; +int main() +{ + a[1]=1; + a[2]=3; + a[3]=5; + a[4]=9; + a[5]=13; + a[6]=17; + a[7]=25; + a[8]=33; + a[9]=41; + a[10]=49; + a[11]=65; + a[12]=81; + a[13]=97; + a[14]=113; + a[15]=129; + a[16]=161; + a[17]=193; + a[18]=225; + a[19]=257; + a[20]=289; + a[21]=321; + a[22]=385; + a[23]=449; + a[24]=513; + a[25]=577; + a[26]=641; + a[27]=705; + a[28]=769; + a[29]=897; + a[30]=1025; + a[31]=1153; + a[32]=1281; + a[33]=1409; + a[34]=1537; + a[35]=1665; + a[36]=1793; + a[37]=2049; + a[38]=2305; + a[39]=2561; + a[40]=2817; + a[41]=3073; + a[42]=3329; + a[43]=3585; + a[44]=3841; + a[45]=4097; + a[46]=4609; + a[47]=5121; + a[48]=5633; + a[49]=6145; + a[50]=6657; + a[51]=7169; + a[52]=7681; + a[53]=8193; + a[54]=8705; + a[55]=9217; + a[56]=10241; + a[57]=11265; + a[58]=12289; + a[59]=13313; + a[60]=14337; + a[61]=15361; + a[62]=16385; + a[63]=17409; + a[64]=18433; + int n; + while(cin>>n) + { + cout< +#include +int main () +{ + __int64 dp[50][50]; + int map[50][50]; + int i,j,n; + char c; + while(~scanf("%d",&n)&&n!=-1) + { + getchar(); + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + scanf("%c",&c); + map[i][j]=c-48; + } + getchar(); + } + memset(dp,0,sizeof(dp)); + dp[1][1]=1; + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + { + if(!map[i][j]) + continue; + dp[i+map[i][j]][j]+=dp[i][j]; + dp[i][j+map[i][j]]+=dp[i][j]; + } + printf("%I64d\n",dp[n][n]); + } + return 0; +} diff --git a/HDOJ/1209_autoAC.cpp b/HDOJ/1209_autoAC.cpp new file mode 100644 index 0000000..69a47a6 --- /dev/null +++ b/HDOJ/1209_autoAC.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct node +{ + int x,y; + double z; +}; +node a[10]; +bool cmp(node a,node b) +{ + if(a.z==b.z) + { + if(a.x==b.x)return a.y=12)x%=12; + z=fabs(1.0*x*30+1.0*y/2-1.0*6*y); + a[i].z=min(360-z,z); + } + sort(a,a+5,cmp); + printf("%02d:%02d\n",a[2].x,a[2].y); + } + } + return 0; +} diff --git a/HDOJ/1210_autoAC.cpp b/HDOJ/1210_autoAC.cpp new file mode 100644 index 0000000..7a1f916 --- /dev/null +++ b/HDOJ/1210_autoAC.cpp @@ -0,0 +1,20 @@ +#include +int main() +{ + int m,x,ans; + while(~scanf("%d",&m)) + { + x=1; + ans = 0; + do + { + if(x<=m) + x = 2*x; + else + x = 2*(x-m)-1; + ans++; + } + while(x!=1); + printf("%d\n",ans); + } +} diff --git a/HDOJ/1211_autoAC.cpp b/HDOJ/1211_autoAC.cpp new file mode 100644 index 0000000..932c58f --- /dev/null +++ b/HDOJ/1211_autoAC.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + __int64 n; +__int64 power(int a,int d) +{ + int i; + __int64 res=1; + for(i=1;i<=d;i++) + res=(res*a)%n; + return res; +} +int main() +{ + int d,i,j,p,q,e,l,a; + while(~scanf("%d%d%d%d",&p,&q,&e,&l)) + { + n=(p-1)*(q-1); + for(i=1;;i++) + if((i*e)%n==1) + break; + d=i; + n=p*q; + for(i=0;i +#include +int main() +{ + int n,i,t; + char a[1010]; + while(scanf("%s%d",&a,&n)!=EOF) + { + t=0; + for(i=0;i +#include +int a[1003]; +void ice(int x,int y) +{ + a[x]=y; +} +int find(int x) +{ + if(x!=a[x]) + a[x]=find(a[x]); + return a[x]; +} +int main() +{ + int t,n,m,i,j,x,y; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&m); + j=0; + for(i=1;i<=n;i++) + a[i]=i; + for(i=1;i<=m;i++) + { + scanf("%d%d",&x,&y); + x=find(x); + y=find(y); + ice(x,y); + } + for(i=1;i<=n;i++) + if(a[i]==i) + j++; + printf("%d\n",j); + } + return 0; +} diff --git a/HDOJ/1214_autoAC.cpp b/HDOJ/1214_autoAC.cpp new file mode 100644 index 0000000..66ec1e8 --- /dev/null +++ b/HDOJ/1214_autoAC.cpp @@ -0,0 +1,12 @@ +#include +int main() +{ + int n,a; + while(~scanf("%d",&n)) + { + a=n/2; + n-=a; + printf("%d\n",a*(a-1)/2+n*(n-1)/2); + } + return 0; +} diff --git a/HDOJ/1215_autoAC.cpp b/HDOJ/1215_autoAC.cpp new file mode 100644 index 0000000..170ec0a --- /dev/null +++ b/HDOJ/1215_autoAC.cpp @@ -0,0 +1,26 @@ +#include +int main() +{ + int n,i,a,j,sum,c; + while(scanf("%d",&n)!=EOF) + { + for(i=1;i<=n;i++) + { + sum=0; + scanf("%d",&a); + c=a; + for(j=2;j +#include +#define M 34000 +int n,num[M],ss[3001],t=0; +int main() +{ + int i,j,k; + memset(num,0,sizeof(num)); + for(i=2;i +#include +#define max 100+10 +double map[max][max]; +int curr,t=1; +void floyd() +{ + int k,i,j; + int exist=0; + for(k=1;k<=curr;k++) + { + for(i=1;i<=curr;i++) + { + for(j=1;j<=curr;j++) + { + if(map[i][j]1) + { + exist=1; + break; + } + } + if(exist) + printf("Case %d: Yes\n",t++); + else + printf("Case %d: No\n",t++); +} +int main() +{ + int m,i,j,x,y; + double rate; + char a[110],b[110],s[110][110]; + while(scanf("%d",&curr)&&(curr!=0)) + { + for(i=1;i<=curr;i++) + { + for(j=1;j<=curr;j++) + { + map[i][j]=0; + } + } + for(i=1;i<=curr;i++) + { + scanf("%s",s[i]); + } + scanf("%d",&m); + while(m--) + { + scanf("%s %lf %s",a,&rate,b); + for(i=1;i<=curr;i++) + { + if(strcmp(s[i],a)==0) + { + x=i; + break; + } + } + for(i=1;i<=curr;i++) + { + if(strcmp(s[i],b)==0) + { + y=i; + break; + } + } + map[x][y]=rate; + } + floyd(); + } + return 0; +} diff --git a/HDOJ/1218_autoAC.cpp b/HDOJ/1218_autoAC.cpp new file mode 100644 index 0000000..8029529 --- /dev/null +++ b/HDOJ/1218_autoAC.cpp @@ -0,0 +1,53 @@ +#include +#include +int main() +{ + int i,j,R,C; + int a[10][10],b[10][10]; + char c,str[10]; + for(i=0;i<10;i++) + { + for(j=0;j<10;j++) + { + a[i][j]=0; + b[i][j]=0; + } + } + while(1) + { + scanf("%s",str); + if(strcmp(str,"ENDOFINPUT")==0) + break; + if(strcmp(str,"START")==0) + { + scanf("%d%d",&R,&C); + getchar(); + for(i=0;i +#include +int main () +{ + int s,i,b[26]; + char a[100001]; + while(gets(a)!=NULL) + { + memset(b,0,sizeof(b)); + for(i=0;a[i]!='\0';i++) + b[a[i]-'a']++; + for(i=0;i<26;i++) + printf("%c:%d\n",'a'+i,b[i]); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1220_autoAC.cpp b/HDOJ/1220_autoAC.cpp new file mode 100644 index 0000000..db20b71 --- /dev/null +++ b/HDOJ/1220_autoAC.cpp @@ -0,0 +1,8 @@ +#include +int main(){ + int n; + while(~scanf("%d",&n)){ + printf("%d\n",n*n*(n-1)/2*(n*n*n-2)+n*n*n*(n*n-5)/2+2*n*n); + } + return 0; +} diff --git a/HDOJ/1221_autoAC.cpp b/HDOJ/1221_autoAC.cpp new file mode 100644 index 0000000..b7576a4 --- /dev/null +++ b/HDOJ/1221_autoAC.cpp @@ -0,0 +1,28 @@ +#include +#include +using namespace std; +double a,b,r; +double xj(double xy,double x,double y,double aa,double bb) +{ + double m,n=y+1; + m=r*r-(xy-aa)*(xy-aa); + if(m>0) n=sqrt(m)+bb; + if(m<0||n>y||nx2?x2:x1;b1=x1+x2-a1; + c1=y1>y2?y2:y1;d1=y1+y2-c1; + if(xj(a1,c1,d1,a,b)||xj(b1,c1,d1,a,b)||xj(c1,a1,b1,b,a)||xj(d1,a1,b1,b,a)) + printf("YES\n"); + else + printf("NO\n"); +} +return 0; +} diff --git a/HDOJ/1222_autoAC.cpp b/HDOJ/1222_autoAC.cpp new file mode 100644 index 0000000..18973ef --- /dev/null +++ b/HDOJ/1222_autoAC.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include +using namespace std; +__int64 gcd(__int64 a,__int64 b){ + if(a>T; + while(T--){ + cin>>m>>n; + if(gcd(m,n)==1)cout<<"NO\n"; + else cout<<"YES\n"; + } + return 0; +} diff --git a/HDOJ/1223_autoAC.cpp b/HDOJ/1223_autoAC.cpp new file mode 100644 index 0000000..9424ab9 --- /dev/null +++ b/HDOJ/1223_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +using namespace std; +struct LL +{ + int num[50]; + int len; +}; +LL count[51][51]; +LL total[51]; +LL operator+(const LL& a, const LL& b) +{ + LL c; + int Len = a.len>b.len?a.len:b.len; + int jin = 0; + for(int i=0;i=0;i--) + { + out << setfill('0') << setw(6) << a.num[i]; + } + return out; +} +int main() +{ + count[1][0].num[0] = 1; + count[1][0].len = 1; + total[1].num[0] = 1; + total[1].len = 1; + for(int i=2;i<51;i++) + { + total[i] = count[i][0] = count[i-1][0] * i; + for(int j=1;j> P; + while(P--) + { + int k; + cin >> k; + cout << total[k] << endl; + } +} diff --git a/HDOJ/1224_autoAC.cpp b/HDOJ/1224_autoAC.cpp new file mode 100644 index 0000000..ea970fa --- /dev/null +++ b/HDOJ/1224_autoAC.cpp @@ -0,0 +1,60 @@ +#include +#include +using namespace std; +const int maxn=102; +int d[maxn]; +bool map[maxn][maxn]; +int w[maxn]; +int pre[maxn]; +void print(int x) +{ + if(pre[x]!=0) + print(pre[x]); + printf("%d->",x); +} +int main() +{ + int t,n,m,x,y,l,i,j; + scanf("%d",&t); + for(l=1;l<=t;l++) + { + scanf("%d",&n); + for(i=1;i<=n;i++) scanf("%d",&d[i]); + d[n+1]=0; + for(i=1;i<=n+1;i++) + { + w[i]=0; + pre[i]=0; + for(j=i;j<=n+1;j++) + { + map[i][j]=false; + } + } + scanf("%d",&m); + for(i=1;i<=m;i++) + { + scanf("%d%d",&x,&y); + map[x][y]=true; + } + for(j=1;j<=n+1;j++) + { + int max=0; + int k=0; + for(i=1;i +#include +typedef struct +{ + char name[30]; + int score; + int kick; + int lost; +}TEAM; +int is_exist(int len,TEAM *p,const char *s) +{ + int i; + for(i = 0 ; i < len ; ++i) + { + if(!strcmp(p[i].name,s)) + return 1; + } + return 0; +} +int find(TEAM *p,int len,const char *s) +{ + int i; + for(i = 0 ; i < len ; ++i) + { + if(!strcmp(p[i].name,s)) + return i; + } + return -1; +} +void swap(TEAM *p1,TEAM *p2) +{ + TEAM t = *p1; + *p1 = *p2; + *p2 = t; +} +void sort(TEAM *p,const int LEN) +{ + int i,j; + for(i = 0 ; i < LEN ; ++i) + { + for(j = i + 1 ; j < LEN ; ++j) + { + if(p[i].score < p[j].score) + swap(&p[i],&p[j]); + else if(p[i].score == p[j].score) + { + if(p[i].kick - p[i].lost < p[j].kick - p[j].lost) + swap(&p[i],&p[j]); + else if(p[i].kick - p[i].lost == p[j].kick - p[j].lost) + { + if(p[i].kick < p[j].kick) + swap(&p[i],&p[j]); + else if(p[i].kick == p[j].kick) + { + if(strcmp(p[i].name,p[j].name) > 0) + swap(&p[i],&p[j]); + } + } + } + } + } +} +int main(int argc, char *argv[]) +{ + int T,a,b; + char t1[30],t2[30],vs[5],fen[10]; + TEAM team[5010]; + while(scanf("%d",&T) != EOF) + { + memset(team,0,sizeof(team)); + int t = T * (T - 1); + int ix_team = 0; + while(t--) + { + scanf("%s%s%s%s",t1,vs,t2,fen); + sscanf(fen,"%d:%d",&a,&b); + if(ix_team < T) + { + if(0 == is_exist(ix_team,team,t1)) + strcpy(team[ix_team++].name,t1); + if(0 == is_exist(ix_team,team,t2)) + strcpy(team[ix_team++].name,t2); + } + int ix1 = find(team,ix_team,t1); + int ix2 = find(team,ix_team,t2); + int score; + if(a > b) score = 3; + else if(a == b) score = 1; + else score = 0; + team[ix1].kick += a; + team[ix1].lost += b; + team[ix1].score += score; + if(b > a) score = 3; + else if(b == a) score = 1; + else score = 0; + team[ix2].kick += b; + team[ix2].lost += a; + team[ix2].score += score; + } + sort(team,T); + int i; + for(i = 0 ; i < T ; ++i) + printf("%s %d\n",team[i].name,team[i].score); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1226_autoAC.cpp b/HDOJ/1226_autoAC.cpp new file mode 100644 index 0000000..64849bb --- /dev/null +++ b/HDOJ/1226_autoAC.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#define MAXN 5000 +#define MAXM 17 +#define MAXC 17 +using namespace std; +int num[MAXM]; +bool status[MAXN]; +int basis, sys, n; +struct Node{ + int mod; + int dig; + int pre; + int step; +}Queue[MAXN], init = { 0, 0, -1 }; +int cmp(const void *a, const void *b){ + return *(int *)a - *(int *)b; +} +void echo(int x){ + if (Queue[x].pre == -1) return; + else echo(Queue[x].pre); + if (Queue[x].dig <= 9) + printf("%d", Queue[x].dig); + else + putchar(Queue[x].dig + 'A' - 10); +} +bool bfs(){ + Node curr, next; + int front = 0, rear = 1, res; + Queue[0] = init; + memset(status, 0, sizeof(status)); + while (front != rear){ + curr = Queue[front]; + for (int i = 0; i < n; i++){ + res = (curr.mod * sys + num[i]) % basis; + if (status[res] || (curr.pre == -1 && num[i] == 0) || curr.step >= 500) continue; + status[res] = 1; + Queue[rear].mod = res; + Queue[rear].dig = num[i]; + Queue[rear].pre = front; + Queue[rear].step = curr.step + 1; + if (res == 0) { echo(rear); putchar('\n'); return true; } + rear++; + } + front++; + } + return false; +} +int main(){ + int t; + char tmp[3]; + scanf("%d", &t); + while (t--){ + scanf("%d %d %d", &basis, &sys, &n); + for (int i = 0; i < n; i++){ + scanf("%s", tmp); + if (tmp[0] <= '9' && tmp[0] >= '0') num[i] = tmp[0] - '0'; + else if (tmp[0] <= 'F' && tmp[0] >= 'A') num[i] = tmp[0] - 'A' + 10; + } + qsort(num, n, sizeof(int), cmp); + if (basis == 0){ + if (num[0] == 0) + printf("0\n"); + else + printf("give me the bomb please\n"); + continue; + } + if (!bfs()) + printf("give me the bomb please\n"); + } + return 0; +} diff --git a/HDOJ/1227_autoAC.cpp b/HDOJ/1227_autoAC.cpp new file mode 100644 index 0000000..ea276bc --- /dev/null +++ b/HDOJ/1227_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#define inf 0x7fffffff +int abbs(int a) { return a<0 ? -a : a ; } +int food[205], dp[35][205], dis[205][205]; +int main() +{ + int n, m, i, j, k, mid, minn, p=1; + while(scanf("%d%d", &n, &m) != EOF ) + { + if( n==0 && m==0 ) break; + for(i=1; i<=n; i++) + scanf("%d",&food[i]); + for(i=1; i<=n; i++) + { + for(j=i; j<=n; j++) + { + dis[i][j] = 0; mid = (i+j)/2; + for(k=i; k<=j; k++ ) + dis[i][j] += abbs( food[k] - food[mid] ) ; + } + } + for( i=1; i<=n; i++ ) + { + dp[1][i] = dis[1][i]; + } + for(i=2; i<=m; i++ ) + { + for(j=i; j<=n; j++ ) + { + dp[i][j] = inf ; + for(k=i-1; k dp[i-1][k] + dis[k+1][j] ) + dp[i][j] = dp[i-1][k] + dis[k+1][j] ; + } + } + printf("Chain %d\nTotal distance sum = %d\n\n" , p++, dp[m][n] ); + } +} diff --git a/HDOJ/1228_autoAC.cpp b/HDOJ/1228_autoAC.cpp new file mode 100644 index 0000000..736d29a --- /dev/null +++ b/HDOJ/1228_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +int cmletter(char *s) +{ + int op; + if(strcmp(s,"zero")==0) op=0; + if(strcmp(s,"one")==0)op=1; + if(strcmp(s,"two")==0) op=2; + if(strcmp(s,"three")==0) op=3; + if(strcmp(s,"four")==0) op=4; + if(strcmp(s,"five")==0) op=5; + if(strcmp(s,"six")==0) op=6; + if(strcmp(s,"seven")==0) op=7; + if(strcmp(s,"eight")==0) op=8; + if(strcmp(s,"nine")==0) op=9; + return op; +} +int dig(char *t,char *u) +{ + int len1,s,r; + len1 = strlen(u); + if(len1>0) + r = 10*cmletter(t)+cmletter(u); + else + r = cmletter(t); + return r; +} +int main() +{ + int i,j,k,tg,len,a,b; + char s[1000],t[16],u[16]; + while(gets(s)) + { + len = strlen(s); + tg = 0; + for(i=0,j=0,k=0;i +int main() +{ + int a,b,k; + while(scanf("%d%d%d",&a,&b,&k)!=EOF&&a&&b) + { + int m=1; + while(k--) + m*=10; + if(a%m==b%m) + printf("-1\n"); + else + printf("%d\n",a+b); + } + return 0; +} diff --git a/HDOJ/1230_autoAC.cpp b/HDOJ/1230_autoAC.cpp new file mode 100644 index 0000000..533ec13 --- /dev/null +++ b/HDOJ/1230_autoAC.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define lson ((root<<1)+1) +#define rson ((root<<1)+2) +#define MID ((l+r)>>1) +typedef long long ll; +typedef pair P; +const int maxn=150; +const int base=1000; +const int inf=999999; +int isp[maxn]; +int p[maxn]; +void mark() +{ + int i,j; + int len=0; + isp[0]=isp[1]=1; + for(i=2;i=0;i--)if(sum[i]!=0)break; + j=i; + printf("%d",sum[j]); + for(i=j-1;i>=0;i--) + printf(",%d",sum[i]); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1231_autoAC.cpp b/HDOJ/1231_autoAC.cpp new file mode 100644 index 0000000..79b7ee1 --- /dev/null +++ b/HDOJ/1231_autoAC.cpp @@ -0,0 +1,36 @@ +#include +int a[100000]; +int main() +{ + int n; + while(~scanf("%d",&n)&&n) + { + for(int i=0;imaxsum) + { + maxsum=thissum; + start=temp; + stop=a[i]; + } + if(thissum<0) + { + thissum=0; + temp=a[i+1]; + } + } + if(maxsum<0) + printf("0 %d %d\n",a[0],a[n-1]); + else + printf("%d %d %d\n",maxsum,start,stop); + } + return 0; +} diff --git a/HDOJ/1232_autoAC.cpp b/HDOJ/1232_autoAC.cpp new file mode 100644 index 0000000..62a73ef --- /dev/null +++ b/HDOJ/1232_autoAC.cpp @@ -0,0 +1,38 @@ +#include +int p[1222]; +int i; +int find(int x) +{ + if(x!=p[x]) + p[x]=find(p[x]); + return p[x]; +} +int hebing(int x,int y) +{ + return p[x]=y; +} +int main() +{ + int n,m,x,y,x1,y1; + while(~scanf("%d%d",&n,&m)&&n) + { + for(i=1;i<=1222;i++) + p[i]=i; + for(i=1;i<=m;i++) + { + scanf("%d%d",&x,&y); + x1=find(x); + y1=find(y); + if(x1!=y1) + hebing(x1,y1); + } + int ans=0; + for(i=1;i<=n;i++) + { + if(p[i]==i) + ans++; + } + printf("%d\n",ans-1); + } + return 0; +} diff --git a/HDOJ/1233_autoAC.cpp b/HDOJ/1233_autoAC.cpp new file mode 100644 index 0000000..64c8ed7 --- /dev/null +++ b/HDOJ/1233_autoAC.cpp @@ -0,0 +1,63 @@ +#include +#include +#define max 50*99+10 +using namespace std; +int set[110]; +struct line +{ + int dis; + int start; + int end; +}num[max]; +bool cmp(line a,line b) +{ + return a.dis +#include +struct node +{ + char id[100]; + char qd[100]; + char ql[100]; +}; +struct node s[1000]; +int main() +{ + int n,i,j,k,m,x1,x2; + char c[100]; + while(scanf("%d",&n)!=EOF&&n) + { + while(n--) + { x1=0;x2=0; + scanf("%d",&m); + getchar(); + for(i=0;i1) + { strcpy(c,s[0].qd); + for(i=1;i0) + { + strcpy(c,s[i].qd);x1=i; + } + } + strcpy(c,s[0].ql); + for(i=1;i +int main () +{ + int N; + int i; + while(scanf("%d", &N)!=EOF) + { + if(N==0) + break; + int num[1200], T, p=0; + for(int i=0; i +#include +#include +using namespace std; +struct stu{ + string na; + double sco; +}s[1010]; +bool cmp(stu a,stu b){ + if(a.sco==b.sco) + return a.nab.sco; +} +int main(){ + int n,i,j,m,x,ans; + double g,a[20]; + while(scanf("%d",&n),n){ + scanf("%d%lf",&m,&g); + for(i=1;i<=m;i++) + scanf("%lf",&a[i]); + ans=0; + for(i=0;i>s[i].na; + scanf("%d",&m); + s[i].sco=0; + for(j=0;j=g) + ans++; + } + printf("%d\n",ans); + sort(s,s+n,cmp); + for(i=0;i +#include +#include +using namespace std; +int main() +{ + double num[205]; + int i; + double s; + char f; + double sum; + while(cin>>s) + { + memset(num,'\0',sizeof(num)); + num[0]=s; + i=0; + f=getchar(); + if(f=='\n'&&s==0)break; + while(1) + { + cin>>f>>s; + if(f=='*')num[i]*=s; + else if(f=='/')num[i]/=s; + else if(f=='+')num[++i]=s; + else + { + num[++i]=-s; + } + if(getchar()=='\n')break; + } + sum=0; + for(i;i>=0;i--) + sum+=num[i]; + printf("%.2lf\n",sum); + } + return 0; +} diff --git a/HDOJ/1239_autoAC.cpp b/HDOJ/1239_autoAC.cpp new file mode 100644 index 0000000..d195d6a --- /dev/null +++ b/HDOJ/1239_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +bool prime[10001]; +void IsPrime(){ + prime[0]=prime[1]=0;prime[2]=1; + for(int i=3;i<=10000;i++) + prime[i]=i%2==0?0:1; + int t=(int)sqrt(10000*1.0); + for(int i=3;i<=t;i++) + if(prime[i]) + for(int j=i*i;j<10000;j+=2*i) + prime[j]=0; +} +int main() +{ + IsPrime(); + int pri[10010]; + int num = 0; + for(int i = 0; i < 10000; i++) + { + if(prime[i]) + pri[num++] = i; + } + int m, a, b; + while(scanf("%d%d%d", &m, &a, &b)!=EOF && m && a && b) + { + int maxx = 0, ii, jj; + for(int i = num-1; i >= 0; i--) + { + for(int j = i; j <= num-1; j++) + { + if(pri[j] > m || pri[i]*pri[j]>m || 1.0*pri[i]/pri[j]<1.0*a/b) + continue; + else + { + if(maxx < pri[i]*pri[j]) + { + maxx = pri[i]*pri[j]; + ii = pri[i]; + jj = pri[j]; + } + } + } + } + printf("%d %d\n", ii, jj); + } + return 0; +} diff --git a/HDOJ/1240_autoAC.cpp b/HDOJ/1240_autoAC.cpp new file mode 100644 index 0000000..8b2e5ae --- /dev/null +++ b/HDOJ/1240_autoAC.cpp @@ -0,0 +1,76 @@ +#include +#include +using namespace std; +char map[10][10][10]; +int startx,starty,startz,endx,endy,endz; +int n; +struct node +{ + int x,y,z,step; + friend bool operator <(node a,node b) + { + return a.step>b.step; + } +}; +void bfs(int x1,int y1,int z1,int x2,int y2,int z2) +{ + int k; + int move[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0}; + node now,next; + priority_queueq; + now.x=x1; + now.y=y1; + now.z=z1; + now.step=0; + map[now.x][now.y][now.z]='X'; + q.push(now); + while(!q.empty()) + { + next=q.top(); + q.pop(); + if(next.x==x2&&next.y==y2&&next.z==z2) + { + printf("%d %d\n",n,next.step); + return ; + } + for(k=0;k<6;k++) + { + now.x=next.x+move[k][0]; + now.y=next.y+move[k][1]; + now.z=next.z+move[k][2]; + if(now.x>=0&&now.x=0&&now.y=0&&now.z +#include +char map[110][110]; +int move[8][2]={1,0,-1,0,0,1,0,-1,1,1,-1,-1,1,-1,-1,1}; +int h,w; +void dfs(int x,int y) +{ + int next_x,next_y,i; + map[x][y]='*'; + for(i=0;i<8;i++) + { + next_x=x+move[i][0]; + next_y=y+move[i][1]; + if(next_x>=0&&next_x=0&&next_y +#include +#include +#include +#include +#define N 300 +using namespace std; +typedef struct node +{ + int x,y; + int time; + friend bool operator<(node n1,node n2) + { + return n2.time=m||y<0||y>=n||map[y][x]==-1) + return 1; + return 0; +} +int bfs() +{ + priority_queueQ; + while(!Q.empty()) + Q.pop(); + node fir,nex; + fir.x=x1; + fir.y=y1; + fir.time=0; + map[y1][x1]=-1; + Q.push(fir); + while(!Q.empty()) + { + fir=Q.top(); + Q.pop(); + if(fir.x==x2&&fir.y==y2) + { + return fir.time; + } + for(int i=0;i<4;i++) + { + nex.x=fir.x+dir[i][0]; + nex.y=fir.y+dir[i][1]; + if(judge(nex.x,nex.y)) + continue; + nex.time=fir.time+map[nex.y][nex.x]+1; + map[nex.y][nex.x]=-1; + Q.push(nex); + } + } + return -1; + } +int main() +{ + char c[N][N]; + while(~scanf("%d%d",&n,&m)) + { + for(int i=0;i +#include +#include +#include +using namespace std; +int ha[30],dp[2100][2100]; +int main() +{ + int n,i,j,carry,len1,len2,k,sji; + char s1[50],s2[2010],s3[2010]; + while(~scanf("%d",&n)) + { + scanf("%s",s1); + for(i=0;i +#include +int dp[1005][1005]; +int main () +{ + int fw[1005][2],l[1005],num[1005]; + int i,j,k,s,n,m; + while(~scanf("%d",&n)&&n) + { + scanf("%d",&m); + for(s=0,i=1;i<=m;i++) + { + scanf("%d",&l[i]); + fw[i][0]=s+1; + s+=l[i]; + } + for(s=0,i=m;i>=1;i--) + { + fw[i][1]=n-s; + s+=l[i]; + } + for(i=1;i<=n;i++) + scanf("%d",&num[i]); + memset(dp,0,sizeof(dp)); + for(i=1;i<=m;i++) + { + s=0; + for(j=fw[i][0];j<=fw[i][1];j++) + { + if(j-fw[i][0]+1<=l[i]) + { + s+=num[j]; + if(j-fw[i][0]+1==l[i]) + { + if(dp[i][j] +#include +#include +using namespace std; +const int MAXN=110; +const double MAXNUM=1e8; +int n,step[MAXN]; +double x[MAXN],y[MAXN]; +double d,dis[MAXN],map[MAXN][MAXN]; +bool mark[MAXN]; +double dist(int i,int j) +{ + double X=(x[i]-x[j])*(x[i]-x[j]); + double Y=(y[i]-y[j])*(y[i]-y[j]); + return sqrt(X+Y); +} +void SPFA() +{ + int i; + queue q; + for(i=1;i<=n+1;i++) + { + dis[i]=MAXNUM; + mark[i]=0; + } + step[0]=0; + dis[0]=0.0; + q.push(0); + mark[0]=1; + while(!q.empty()) + { + int s=q.front(); + q.pop(); + mark[s]=0; + for(i=1;i<=n+1;i++) + { + if(map[s][i]<=d&&map[s][i]+dis[s]step[s]+1) + { + step[i]=step[s]+1; + if(!mark[i]) + q.push(i); + } + } + } + } +} +int main() +{ + while(scanf("%d%lf",&n,&d)==2) + { + int i,j; + x[0]=y[0]=0; + for(i=1;i<=n;i++) + scanf("%lf%lf",x+i,y+i); + if(d>=42.50) + { + puts("42.50 1"); + continue; + } + for(i=1;i<=n;i++) + { + map[i][i]=MAXNUM; + for(j=i+1;j<=n;j++) + map[i][j]=map[j][i]=dist(i,j); + } + for(i=1;i<=n;i++) + { + map[i][0]=0.0; + map[0][i]=sqrt(x[i]*x[i]+y[i]*y[i])-7.5; + } + for(i=1;i<=n;i++) + { + map[n+1][i]=0.0; + if(50.00-fabs(x[i])>50.00-fabs(y[i])) + map[i][n+1]=50.00-fabs(y[i]); + else map[i][n+1]=50.00-fabs(x[i]); + } + map[0][n+1]=MAXNUM; + SPFA(); + if(dis[n+1]==MAXNUM) + puts("can't be saved"); + else printf("%.2lf %d\n",dis[n+1],step[n+1]); + } + return 0; +} diff --git a/HDOJ/1246_autoAC.cpp b/HDOJ/1246_autoAC.cpp new file mode 100644 index 0000000..149428d --- /dev/null +++ b/HDOJ/1246_autoAC.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +using namespace std; +int main() +{ + int i,a[310]={1,1},n,j; + for(i=3;i<310;i+=2) + { + for(j=310;j>=0;j--) + { + if(i+j<=310) + a[i+j]+=a[j]; + } + } + while(cin>>n) + { + cout< +#include +using namespace std; +char a[50010][123]; +struct node{ + bool p; + node *next[26]; + node(){ + memset(next,NULL,sizeof(next)); + p=0; + } +}*head; +void insert(char *c){ + int i=0; + node *p=head; + while(c[i]){ + if(p->next[c[i]-'a']==NULL) + p->next[c[i]-'a']=new node; + p=p->next[c[i]-'a']; + i++; + } + p->p=true; +} +bool search(char *c){ + node *p=head,*s; + int i,j,l=strlen(c),o; + char k; + for(i=0;inext[k]){ + p=p->next[k]; + if(p->p==true){ + s=head;o=1; + for(j=i+1;jnext[k]) + s=s->next[k]; + else{ + o=0; + break; + } + } + if(o){ + if(s->p) + return 1; + } + } + } + } + return 0; +} +int main(){ + int i,j,n=0; + head=new node; + while(~scanf("%s",a[n++])) + insert(a[n-1]); + for(i=0;i +using namespace std; +int main() +{ + int t; + cin>>t; + while(t--) + { + int temp; + cin>>temp; + int m1=temp/150; + int m2=temp/200; + int m3=temp/350; + int sum=temp; + for(int i=0;i<=m1;++i) + for(int j=0;j<=m2;++j) + for(int k=0;k<=m3;++k) + { + int sum1=temp-150*i-200*j-350*k; + if(sum1=0) + sum=sum1; + } + cout< +int main() +{ + int n,s=2,i,m; + scanf("%d",&n); + while(n--) + { + scanf("%d",&m); + s+=6*(m-1); + printf("%d\n",s); + } + return 0; +} diff --git a/HDOJ/1250_autoAC.cpp b/HDOJ/1250_autoAC.cpp new file mode 100644 index 0000000..fec9108 --- /dev/null +++ b/HDOJ/1250_autoAC.cpp @@ -0,0 +1,44 @@ +#include +#include +using namespace std; +short x[5][2008]; +int main() +{ + int n,i,j; + while(cin>>n) + { + if(n<=4) + { + cout<<1<=10) + { + x[i%5][j+1]+=x[i%5][j]/10; + x[i%5][j]%=10; + } + } + } + i=2005; + while(x[n%5][i]==0) + --i; + while(i>=0) + { + cout< +#include +char str[28][11111][11]; +int main() +{ + char s[11],tem[11]; + int i=0,j,num[28]; + int count; + int len; + memset(num,0,sizeof(num)); + while(gets(tem)&&strcmp(tem,"")!=0) + { + int r=tem[0]-96; strcpy(str[r][num[r]++] , tem); + } + while(scanf("%s",s)!=EOF) + { + count=0;int r=s[0]-96; + len=strlen(s); + for(j=0;j +#include +#include +#include +#include +using namespace std; +int n,ok,p1,p2,p3; +int ans[51][51][51]; +char map[51][51]; +struct Hike{ + char a,b,c; +}; +void bfs() +{ + int i,a,b,c; + queueQ; + Hike tmp; + ans[p1][p2][p3] = 0; + tmp.a = p1; + tmp.b = p2; + tmp.c = p3; + Q.push(tmp); + while(!Q.empty()) + { + tmp = Q.front(); Q.pop(); + a = tmp.a; b = tmp.b; c = tmp.c; + if((a == b) && (a == c)) + { + ok = a; break; + } + int current = ans[a][b][c]; + current ++; + char *color ; + char bcColor = map[b][c]; + color = map[a]+1; + for(i=1;i<=n;i++,color++) + { + if(i != a && *color == bcColor && ans[i][b][c] > current) + { + ans[i][b][c] = current; + tmp.a = i; tmp.b = b; tmp.c = c; + Q.push(tmp); + } + } + char acColor = map[a][c]; + color = map[b] + 1; + for(i=1;i<=n;i++,color++) + { + if(i != b && *color == acColor && ans[a][i][c] > current) + { + ans[a][i][c] = current; + tmp.a = a; tmp.b = i; tmp.c = c; + Q.push(tmp); + } + } + char abColor = map[a][b]; + color = map[c] + 1; + for(i=1;i<=n;i++,color++) + { + if(i != c && *color == abColor && ans[a][b][i] > current) + { + ans[a][b][i] = current; + tmp.a = a; tmp.b = b; tmp.c = i; + Q.push(tmp); + } + } + } +} +int main() +{ + int i,j; + char str[110]; + while(scanf("%d",&n)!=EOF && n) + { + scanf("%d%d%d\n",&p1,&p2,&p3); + for(i=1;i<=n;i++) + { + gets(str); + for(j=0;j +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int A, B, C, T; +struct point { + int x, y, z; + int t; + point(int x=0, int y=0, int z=0, int t=0): x(x), y(y), z(z), t(t) {} +}; +int direct[][3] = {{1,0,0}, {-1,0,0}, {0,0,1}, {0,0,-1}, {0,1,0}, {0,-1,0}}; +int Map[55][55][55]; +int BFS() { + queue que; + que.push(point(0,0,0,0)); + while(que.size()) { + point p = que.front(); + que.pop(); + if(p.t > T) + continue; + if(p.x == A-1 && p.y == B-1 && p.z == C-1) + return p.t; + for(int k=0; k<6; ++k) { + int nx = p.x + direct[k][0]; + int ny = p.y + direct[k][1]; + int nz = p.z + direct[k][2]; + if(nx >=0 && nx=0 && ny=0 && nz +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 0x7fffffff +#define eps 1e-6 +using namespace std; +int g[8][8]; +int xx[]={1,-1,0,0}; +int yy[]={0,0,-1,1}; +int n,m; +struct node +{ + int x,y,lv; +}; +node box,man,over; +bool vis[8][8]; +bool ok; +void dfs(int x1,int y1,int x2,int y2) +{ + if(ok)return; + if(x1==x2&&y1==y2) + { + ok=1; + return; + } + int x,y; + for(int k=0;k<4;k++) + { + x=x1+xx[k]; + y=y1+yy[k]; + if(x>=n||x<0||y>=m||y<0||g[x][y]==1||vis[x][y]) + continue; + vis[x][y]=1; + dfs(x,y,x2,y2); + } +} +int bfs() +{ + bool way[8][8][8][8]; + queueq; + queuehuman; + memset(way,0,sizeof(way)); + q.push(box); + human.push(man); + way[box.x][box.y][man.x][man.y]=1; + node tmp,now,ma; + while(!q.empty()) + { + tmp=q.front();q.pop(); + ma=human.front();human.pop(); + if(tmp.x==over.x&&tmp.y==over.y)return tmp.lv; + for(int k=0;k<4;k++) + { + int x=tmp.x+xx[k]; + int y=tmp.y+yy[k]; + if(x>=n||x<0||y>=m||y<0||g[x][y]==1||way[x][y][tmp.x][tmp.y]) + continue; + int rex=tmp.x-xx[k]; + int rey=tmp.y-yy[k]; + if(rex>=n||rex<0||rey>=m||rey<0||g[rex][rey]==1) + continue; + memset(vis,0,sizeof(vis)); + ok=0; + vis[tmp.x][tmp.y]=1; + dfs(ma.x,ma.y,rex,rey); + if(!ok) + continue; + now.x=x,now.y=y,now.lv=tmp.lv+1; + way[x][y][tmp.x][tmp.y]=1; + q.push(now); + human.push(tmp); + } + } + return -1; +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&m); + for(int i=0;i +#include +#include +using namespace std; +const int MAXN=1003; +double y[2*MAXN]; +struct Line +{ + double x; + double up,down; + int mark; + bool operator <(const Line a)const + { + return x=up||T[k].up<=down) + return 0; + if(T[k].isLeaf) + { + double s=0; + if(T[k].cover>1) + { + double xx=T[k].x; + s=(x-xx)*(T[k].up-T[k].down); + } + T[k].x=x; + T[k].cover+=mark; + return s; + } + double s1=insert(2*k+1,x,down,up,mark); + double s2=insert(2*k+2,x,down,up,mark); + return s1+s2; +} +int main() +{ + int T,N; + double area,x1,x2,y1,y2; + scanf("%d",&T); + while(T--) + { + area=0; + scanf("%d",&N); + for(int i=0,num=-1;i +int main() +{ + int T,n,a,b,i,j,g=0; + char _char; + scanf("%d",&T); + while(T--) + { + if(g!=0)printf("\n"); + g=1; + getchar(); + _char=getchar(); + scanf("%d",&n); + a=(n/6)+1 ; + b=(n-3)/2 ; + for(i=1;i<=n;i++) + { + for(j=1 ; j<=2*a+n-3-b ; j++) + { + if(i==1||i==(2+b)||i==n) + { + if(j==a-b+n-2) + { + break; + } + if(ja&&j +#include +int a[1000008],b[1000008]; +int main() +{ + int n,i,k,j; + while(scanf("%d",&n)==1) + { + k=0; + scanf("%d",&a[0]); + b[k]=a[0]; + for(i=1;ia[i]) + { + b[j]=a[i]; + break; + } + if(j>k) + { + b[++k]=a[i]; + } + } + printf("%d\n",k+1); + } + return 0; +} diff --git a/HDOJ/1258_autoAC.cpp b/HDOJ/1258_autoAC.cpp new file mode 100644 index 0000000..9f4b0a7 --- /dev/null +++ b/HDOJ/1258_autoAC.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +using namespace std; +int g[14][14]; +int visited[14]; +int vec[14]; +int t,n; +int path[14]; +int rear; +int flag; +void DFS(int start,int sum) +{ + int j; + visited[start]=1; + path[rear]=vec[start]; + if(sum>t)return ; + if(sum==t) + { + flag=1; + for(j=0;j>t>>n&&!(0==t&&0==n)) + { + for(i=1;i<=n;i++) + { + cin>>w; + vec[i]=w; + for(j=1;j<=n;j++) + g[i][j]=w; + } + i=1; + cout<<"Sums of "< +int main() +{ + int n,i,t1,t2; + scanf("%d",&n); + while(n--) + { + int sum=2; + int m; + scanf("%d",&m); + for(i=1;i<=m;i++) + { + scanf("%d%d",&t1,&t2); + if(t2==sum) + sum=t1; + else if(t1==sum) + sum=t2; + } + printf("%d\n",sum); + } +} diff --git a/HDOJ/1260_autoAC.cpp b/HDOJ/1260_autoAC.cpp new file mode 100644 index 0000000..9869273 --- /dev/null +++ b/HDOJ/1260_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +int minn(int x,int y) +{ + return x +#include +using namespace std; +int a[500]; +void change(int n,int m) +{ + int c; + c=0; + for(int j=0;j<500;j++) + { + c=a[j]*n+c; + a[j]=c%10; + c=c/10; + } + c=0; + for(int j=499;j>=0;j--) + { + c=a[j]+c*10; + a[j]=c/m; + c=c%m; + } + return; +} +int main() +{ + int n,s,k; + int b[26]; + while(cin>>n&&n) + { + s=0; + memset(a,0,sizeof(a)); + a[0]=1; + for(int i=0;i>b[i]; + for(int j=1;j<=b[i];j++) + change(s+j,j); + s+=b[i]; + } + for(k=499;k>=0;k--)if(a[k]!=0) + break; + for(int i=k;i>=0;i--) + cout< +#include +#include +#include +#include +using namespace std; +#define M 10005 +char a[M]={1,1,0}; +void prime() +{ + int i,j; + for(i=2;i>n) + { + int i=n/2; + while(a[i]+a[n-i])i--; + cout< +#include +#include +#include +using namespace std; +struct node +{ + string friut,place; + int num; +}f[109]; +bool cmp(node p,node q) +{ + if(p.place!=q.place) + return p.place>f[i].friut>>f[i].place>>f[i].num; + f[n+1].place="zzzzzzzzzzzz"; + sort(f+1,f+1+n,cmp); + int last=1; + for(i=1;i<=n;i++) + { + if(f[i].place!=f[i+1].place) + { + cout< +#include +#define SWAP(a,b){int t=a;a=b;b=t;} +int hash[102][102]; +void HashTable(int x1,int y1,int x2,int y2) +{ + for(int i = x1;i < x2;i++) + for(int j = y1;j < y2;j++) + hash[i][j] = 1; +} +int CountHash(int minx,int miny,int maxx,int maxy) +{ + int cnt = 0; + for(int i = minx;i < maxx;i++) + for(int j = miny;j < maxy;j++)if(hash[i][j]) + { + cnt++; + } + return cnt; +} +int main() +{ + int x1,x2,y1,y2,minx,miny,maxx,maxy; + while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)) + { + memset(hash,0,sizeof(hash)); + if(x1+x2+y1+y2==-8)break; + if(x1+x2+y1+y2==-4){puts("0");continue;} + if(x1>x2)SWAP(x1,x2); + if(y1>y2)SWAP(y1,y2); + minx = x1; miny = y1; + maxx = x2; maxy = y2; + HashTable(x1,y1,x2,y2); + while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2),(x1+x2+y1+y2!=-4&&x1+x2+y1+y2!=-8)) + { + if(x1>x2)SWAP(x1,x2); + if(y1>y2)SWAP(y1,y2); + if(minx>x1)minx = x1; + if(miny>y1)miny = y1; + if(maxx +#include +#include +#include +using namespace std; +int main() +{ + char s[20]; + float d; + long x,n; + scanf("%d",&n); + while(n--){ + scanf("%f",&d); + memcpy(&x,&d,4); + printf("%X\n",x); + } + return 0; +} diff --git a/HDOJ/1266_autoAC.cpp b/HDOJ/1266_autoAC.cpp new file mode 100644 index 0000000..460aadc --- /dev/null +++ b/HDOJ/1266_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +int main() +{ + int n; + while(cin>>n) + { + string temp; + while(n--) + { + cin>>temp; + auto b=temp.begin(); + if(*b=='-') + { + cout<<'-'; + temp.erase(b); + } + int c=0; + auto d=temp.crbegin(); + for(;d!=temp.crend();++d) + { + if(*d=='0') + c++; + else + break; + } + for(d;d!=temp.crend();++d) + cout<<*d; + for(int i=0;i!=c;++i) + cout<<'0'; + cout< +#include +__int64 d[1010][1010]; +int fun() +{ + int i,j; + memset(d,0,sizeof(d)); + for(i=1; i<=20; i++) + { + d[i][1]=i; + } + for(i=2; i<=20; i++) + { + for(j=2; j<=20; j++) + { + if(i>=j) + d[i][j] = d[i][j-1]+d[i-1][j]; + } + } +} +int main() +{ + int m,n; + fun(); + while(scanf("%d %d",&m,&n)!=EOF) + { + printf("%I64d\n",d[m][n]); + } + return 0; +} diff --git a/HDOJ/1268_autoAC.cpp b/HDOJ/1268_autoAC.cpp new file mode 100644 index 0000000..68f75c4 --- /dev/null +++ b/HDOJ/1268_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#define i64 __int64 +int Max(int a,int b){return a>b?a:b;} +int Min(int a,int b){return a +#include +int pre[2][100010]; +int n,m; +int find(int a,int i) +{ + int r=a; + while(r!=pre[i][r]) + { + r=pre[i][r]; + } + return r; +} +void fun(int a,int b) +{ + if(a!=n) + { + int fa=find(a,0),fb=find(b,0); + if(fa!=fb) + pre[0][a]=b; + } + if(b!=n) + { + int fa=find(a,1),fb=find(b,1); + if(fa!=fb) + pre[1][b]=a; + } +} +int main() +{ + while(scanf("%d%d",&n,&m)!=EOF,n||m) + { + int i,w=1; + for(i=0;i<=n;i++) + { + pre[0][i]=pre[1][i]=i; + } + while(m--) + { + int a,b; + scanf("%d%d",&a,&b); + fun(a,b); + } + for(i=1;i<=n;i++) + { + if(find(i,0)!=n||find(i,1)!=n) + { + w=0; + break; + } + } + if(w) + printf("Yes\n"); + else + printf("No\n"); + } +} diff --git a/HDOJ/1270_autoAC.cpp b/HDOJ/1270_autoAC.cpp new file mode 100644 index 0000000..f95aa20 --- /dev/null +++ b/HDOJ/1270_autoAC.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#define MAXN 11000 +int n, sum[MAXN], num[MAXN],tn[MAXN]; +void init() +{ + int i; + for (i = 1; i * 2 <= n * (n - 1); ++i) + scanf("%d", &sum[i]); +} +void work() +{ + int i,j,k; + for (num[1] = 1; num[1] * 2 <= sum[1]; ++num[1]) + { + j=2; + memset(tn, 0, sizeof(tn)); + for(i=1;i*2<=n*(n-1);i++) + { + tn[sum[i]]++; + } + for(i=1;i*2<=n*(n-1);i++) + { + if(tn[sum[i]]>0) + { + num[j]=sum[i]-num[1]; + for(k=1;kn) + break; + } + if(j<=n) + return ; + for(i=1;i +#include +#include +using namespace std; +int main() +{ + int n,i,j,k,a,b,c; + int ans[1000],len; + while(~scanf("%d",&n),n) + { + len = 0; + for(i = 1; i<=n; i*=10) + { + c = (n/i)/11; + b = (n/i)%11; + if(b+c && b<10) + { + a = (n-b*i-11*c*i)/2; + if(n == 2*a+b*i+11*c*i) + ans[len++] = a+b*i+c*i*10; + } + b--; + if(b+c && b>=0) + { + a = (n-b*i-11*c*i)/2; + if(n == 2*a+b*i+11*c*i) + ans[len++] = a+b*i+c*i*10; + } + } + if(len) + { + sort(ans,ans+len); + printf("%d",ans[0]); + for(i = 1; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define maxn 100010 +#define ull unsigned long long +#define ll long long +#define reP(i,n) for(i=1;i<=n;i++) +#define rep(i,n) for(i=0;ib; +} +int fa[maxn]; +int ans,cnt; +int mark[maxn]; +void init(){ + for(int i=0;i<=maxn;i++) + fa[i]=-1; + ans=0;cnt=0; + cle(mark); +} +int findfa(int x){ + while(fa[x]>=0) + x=fa[x]; + return x; +} +void Union(int x,int y){ + int fa_x=findfa(x); + int fa_y=findfa(y); + if(fa_x!=fa_y) + fa[fa_x]=fa_y; + else{ + ans++; + } + mark[x]=mark[y]=1; +} +int x,y; +int main() +{ + init(); + while(cin>>x>>y){ + if(x==-1&&y==-1)break; + if(x==0&&y==0){ + for(int i=1;i<=maxn;i++){ + if((mark[i])&&(fa[i]==-1)) + cnt++; + } + if(ans>0||cnt>1)printf("No\n"); + else printf("Yes\n"); + init(); + continue; + } + Union(x,y); + } + return 0; +} diff --git a/HDOJ/1273_autoAC.cpp b/HDOJ/1273_autoAC.cpp new file mode 100644 index 0000000..cc7be95 --- /dev/null +++ b/HDOJ/1273_autoAC.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; +int main() +{ + int n; + while(cin>>n&&n) + cout<<(n-1)/2< +#include +#include +#include +using namespace std; +struct Node{ + int k1,k2; +}; +Node find(string s){ + Node k; + int i,k1,k2; + for(i=s.size()-1;i>=0;i--){ + if(s[i]=='('){ + k1=i; break; + } + } + if(i==-1) k.k1=0; + else k.k1=k1; + for(i=0;ik1){ + k2=i; break; + } + } + if(i==s.size()) k.k2=0; + else k.k2=k2; + return k; +} +int main() +{ + int t; + cin>>t; + while(t--){ + string s; + cin>>s; + Node k=find(s); + if(k.k1+k.k2==0){ + string s2; + for(int i=0;i +#include +double l,v1,v2,v; +int n; +double f(double t1,double t2) +{ + if(t2-t1<=1e-6) + return t1; + double time=(t1+t2)/2; + if(floor((time*v/l+1)/2.0)+floor((time*(v1+v2)/l+1)/2.0)>=n) + return f(t1,time); + else + return f(time,t2); +} +int main() +{ + int t; + double time,x,dist; + scanf("%d",&t); + while(t--) + { + scanf("%lf%lf%lf%d",&l,&v1,&v2,&n); + if(v1>v2) + v=v1-v2; + else + v=v2-v1; + time=f(0,100000); + x=time*v1; + while(x>0) + x=x-l; + dist=(-x) +#include +#include +#include +using namespace std; +int p[5005]; +int main() +{ + int m,n,t,k,i; + scanf("%d",&t); + while(t--) + { + scanf("%d",&m); + for(i=1;i<=5001;i++) + { + p[i]=1; + } + n=m; + while(n>3) + { + k=0;n=0; + for(i=1;i<=m;i++) + { + if(p[i]) + { + k=k+1; + if(k%2==0) + p[i]=0; + n=n+p[i]; + } + } + k=0; + if(n<=3) + break; + else + n=0; + for(i=1;i<=m;i++) + { + if(p[i]) + { + k=k+1; + if(k%3==0) + p[i]=0; + } + n=n+p[i]; + } + } + for(i=1;i<=m;i++) + { + if(p[i]) + { + if(i==1) + printf("%d",i); + else + printf(" %d",i); + } + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1277_autoAC.cpp b/HDOJ/1277_autoAC.cpp new file mode 100644 index 0000000..637c998 --- /dev/null +++ b/HDOJ/1277_autoAC.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +using namespace std; +struct Tree +{ + int end,n,l[10]; + void init() + { + memset(l,-1,sizeof(l)); + end=n=0; + } +}tr[700000]; +int n,m,id; +char s[61000],tt[10000],ss[10005][67]; +bool ok[11000]; +void add(char*s,int No) +{ + int t=0; + for(int i=0;s[i];i++) + { + int now=s[i]-'0'; + if(tr[t].l[now]==-1) + { + tr[id].init(); + tr[t].l[now]=id++; + } + t=tr[t].l[now]; + } + tr[t].end=No; +} +void check(char*s) +{ + int t=0; + for(int i=0;s[i];i++) + { + int now=s[i]-'0'; + if(tr[t].end&&ok[tr[t].end]==0) + { + printf(" [Key No. %d]",tr[t].end); + ok[tr[t].end]=1; + } + if(tr[t].l[now]==-1) return; + t=tr[t].l[now]; + } +} +void init() +{ + scanf("%d%d",&n,&m); + int l=0; + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +char map[220][220]; +int main(){ + int n,m; + while(~scanf("%d%d",&m,&n)){ + memset(map,0,sizeof(map)); + int *m1,*m2,*n1,*n2,num; + m1=(int*)malloc(sizeof(int)*m); + m2=(int*)malloc(sizeof(int)*m); + n1=(int*)malloc(sizeof(int)*n); + n2=(int*)malloc(sizeof(int)*n); + int i,j,k; + for(i=0;i +int main() +{ + int N; + int a; + int l; + scanf("%d",&N); + while(N--){ + scanf("%d",&a); + l = 0; + while(a>1){ + if(a%2){ + if(l == 1) + printf(" "); + l = 1; + printf("%d",a); + a = a*3+1; + } + if(a % 2 == 0){ + a = a/2; + } + } + if(l == 0) + printf("No number can be output !"); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1280_autoAC.cpp b/HDOJ/1280_autoAC.cpp new file mode 100644 index 0000000..ad91e07 --- /dev/null +++ b/HDOJ/1280_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +#include + int a[5005]; + int b[5000005]; +int main() +{ + int i,j,n,m,l,count; + while(scanf("%d%d",&n,&m)!=EOF) + { + l=count=0; + memset(a,0,sizeof(a)); + memset(b,0,sizeof(b)); + for(i=1;i<=n;i++) + scanf("%d",&a[i]); + sort(a+1,a+1+n); + for(i=n;i>=1;i--) + for(j=i-1;j>=0;j--) + { + count++; + b[l++]=a[i]+a[j]; + if(count==n*(n-1)/2) + break; + } + sort(b,b+l); + for(i=l-1;m>0;m--,i--) + { + if(m!=1) + printf("%d ",b[i]); + else + printf("%d\n",b[i]); + } + } + return 0; +} diff --git a/HDOJ/1281_autoAC.cpp b/HDOJ/1281_autoAC.cpp new file mode 100644 index 0000000..12cd87d --- /dev/null +++ b/HDOJ/1281_autoAC.cpp @@ -0,0 +1,84 @@ +#include +#include +int mark_DFS[10005]; +int mark_gx[10005]; +int mark_gx2[10005]; +int mark_kk[10005]; +int tou[10005]; +int tot; +typedef struct + { + int date; + int next; + }dian; + dian cun[10005]; +void add(int a,int b) + { + tot++; + cun[tot].date=b; + cun[tot].next=tou[a]; + tou[a]=tot; + } +int DFS(int x) + { + for(int i=tou[x];i;i=cun[i].next) + { + int too; + too=cun[i].date; + if(mark_DFS[too]||mark_kk[too]==x) continue; + mark_DFS[too]=1; + if(mark_gx[too]==-1||DFS(mark_gx[too])) + { + mark_gx[too]=x; + return 1; + } + } + return 0; + } +int main() +{ + int n,a,b,T=1; + while(scanf("%d%d%d",&a,&b,&n)!=EOF) + { + int x,y; + tot=1; + for(int i=0;i<10005;i++) + { + cun[i].next=0; + tou[i]=0; + } + for(int i=1;i<=n;i++) + { + scanf("%d%d",&x,&y); + add(x,y); + } + memset(mark_gx,255,sizeof(mark_gx)); + memset(mark_kk,255,sizeof(mark_kk)); + memset(mark_gx2,255,sizeof(mark_gx2)); + int sum=0; + for(int i=0;i<=a;i++) + { + memset(mark_DFS,0,sizeof(mark_DFS)); + sum+=DFS(i); + } + int max=sum; + int num=0; + for(int i=1;i<=a;i++) { mark_gx2[i]=mark_gx[i];} + for(int j=1;j<=a;j++) + if(mark_gx2[j]!=-1) + { + memset(mark_kk,255,sizeof(mark_kk)); + mark_kk[j]=mark_gx2[j]; + sum=0; + memset(mark_gx,255,sizeof(mark_gx)); + for(int i=0;i<=a;i++) + { + memset(mark_DFS,0,sizeof(mark_DFS)); + sum+=DFS(i); + } + if(sum +#include +int rev(int ); +using namespace std; +int main() +{ + int n; + while(cin>>n) + { + vector v; + while(n!=rev(n)) + { + v.push_back(n); + n+=rev(n); + } + v.push_back(n); + cout<"; + cout< +#include +using namespace std; +int main() +{ + int m1,m2; + string str; + while(cin>>m1>>m2>>str) + { + int r1,r2,r3; + r1=r2=r3=0; + for(int i=0;i!=str.size();++i) + { + switch(str[i]) + { + case 'A': r1=m1;break; + case 'B': r2=m2;break; + case 'C': m1=r3;break; + case 'D': m2=r3;break; + case 'E': r3=r1+r2;break; + case 'F': r3=r1-r2;break; + } + } + cout< +int main() +{ + int n,x2,t,i; + while(~scanf("%d",&n)) + { + t=1; + x2=n/2; + t+=x2; + for(i=0;i<=x2;i++) + t+=(n-i*2)/3; + printf("%d\n",t); + } + return 0; +} diff --git a/HDOJ/1285_autoAC.cpp b/HDOJ/1285_autoAC.cpp new file mode 100644 index 0000000..9cd7b89 --- /dev/null +++ b/HDOJ/1285_autoAC.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +int a[501][501]; +int b[501],w[501]; +int n,m,i,j,s,t; +using namespace std; +int main() +{ + while(scanf("%d%d",&n,&m)!=EOF) + { + memset(a,0,sizeof(a)); + memset(b,0,sizeof(b)); + memset(w,0,sizeof(w)); + for(i=1;i<=m;i++) + { + cin>>s>>t; + if(!a[s][t]) + { + a[s][t]++; + b[t]++; + } + } + int numb=0; + while(1) + { + j=1; + if(b[j]!=0) + { + while(1) + { + j++; + if(b[j]==0) + break; + if(j>n) + break; + } + } + b[j]=-1; + w[numb]=j; + numb++; + for(i=1;i<=n;i++) + { + if(a[j][i]>0) + { + b[i]--; + a[j][i]=-1; + } + } + if(numb>n) + break; + } + for(i=0;i +using namespace std; +const int maxn=32790; +int euler[maxn+2]; +void make() +{ + euler[1]=0; + for(int i=2;i<=maxn;++i) + euler[i]=i; + for(int i=2;i<=maxn;++i) + if(euler[i]==i) + for(int j=i;j<=maxn;j+=i) + euler[j]=euler[j]/i*(i-1); +} +int main() +{ + make(); + int n,t,sum; + cin>>t; + while(t--) + { + cin>>n; + cout< +using namespace std; +char str[10005]; +int wen[10005]; +int main() +{ + int n; + char s; + while(cin>>n) + { + int top=0; + for(int j=0;j>wen[j]; + } + for(char c='A';c<='Z';c++) + { + for(int i=0;i='A'&&s<='Z') + { + str[top++]=s; + } + else + { + top=0; + break; + } + } + if(top==n) + { + break; + } + } + for(int k=0;k +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INIT(x,y) memset(x,y,sizeof(x)) +#define INF 0x7fffffff +#define FAIL {puts("Hat cannot buy tea.");continue;} +using namespace std; +int n, t1, t2, t3, a1, a2, a3; +int main() +{ + ios::sync_with_stdio(false); + while (cin >> n >> t1 >> t2 >> t3) + { + if (!n && !t1 && !t2 && !t3) break; + if (t1 + 5 * t2 + 10 * t3 < n) FAIL + if ((t1 == 0) && (t2 == 0) && (n % 10)) FAIL + if ((t1 == 0) && (n % 5)) FAIL + a1 = a2 = a3 = 0; + if (t2) + { + if (t1 < n % 5) FAIL + a1 = n % 5 + min(n - n % 5, (t1 - n % 5) / 5 * 5); + n -= a1; + a2 = (n % 10 == 5) ? 1 : 0; + a2 += min((n - 5 * a2) / 10 * 2, (t2 - a2) / 2 * 2); + n -= a2 * 5; + } + else + { + if (t1 < n % 10) FAIL + a1 = n % 10 + min(n - n % 10, (t1 - n % 10) / 10 * 10); + a2 = 0; + n -= a1; + } + a3 = min(n / 10, t3); + cout << a1 << " YiJiao, " << a2 << " WuJiao, and " << a3 << " ShiJiao" << endl; + } +} diff --git a/HDOJ/1289_autoAC.cpp b/HDOJ/1289_autoAC.cpp new file mode 100644 index 0000000..d6c9857 --- /dev/null +++ b/HDOJ/1289_autoAC.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + using namespace std; +int main() { + float x; + while (cin >> x) { + int cnt = 0; + while (fabs(x) >= 2.0) x /= 2.0, cnt++; + while (fabs(x) < 1.0) x *= 2.0, cnt--; + printf("%d %.6f\n", cnt, x); + } + return 0; + } diff --git a/HDOJ/1290_autoAC.cpp b/HDOJ/1290_autoAC.cpp new file mode 100644 index 0000000..423717f --- /dev/null +++ b/HDOJ/1290_autoAC.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; +int n; +int main() +{ + while(scanf("%d",&n) != EOF) + { + cout<<(n*n*n + 5*n + 6)/6< +#include +#include +#include +#include +#include +using namespace std; +__int64 a[30][30]; +int main() +{ + int i,j; + int t,n; + __int64 sum; + memset(a,0,sizeof(a)); + a[1][1]=1; + for(i=2;i<26;i++) + { + for(j=1;j<=i;j++) + { + a[i][j]=a[i-1][j-1]+a[i-1][j]*j; + } + } + while(~scanf("%d",&t)) + { + while(t--) + { + scanf("%d",&n); + sum=0; + for(i=1;i<=n;i++) + { + sum+=a[n][i]; + } + printf("%I64d\n",sum); + } + } + return 0; +} diff --git a/HDOJ/1293_autoAC.cpp b/HDOJ/1293_autoAC.cpp new file mode 100644 index 0000000..56e3c08 --- /dev/null +++ b/HDOJ/1293_autoAC.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; +string Da(string a,string b) +{ + string ans; + int carry; + int i,j,k; + int add1,add2,sum; + i=a.size()-1; + j=b.size()-1; + k=i>j?i:j; + if(i>j) + ans=a; + else + ans=b; + for(carry=0;k>=0;i--,j--,k--) + { + add1=i<0?0:a[i]-'0'; + add2=j<0?0:b[j]-'0'; + sum=add2+add1+carry>=10?add1+add2+carry-10:add1+add2+carry; + carry=add1+add2+carry>=10?1:0; + ans[k]=sum+'0'; + } + k=ans.size(); + if(carry) + ans.insert(0,"1"); + return ans; +} +int main() +{ + int n,i; + string a[1005]; + a[0]="1"; + a[1]="3"; + for(i=2;i<=1000;i++) + { + a[i]=Da(Da(a[i-1],a[i-1]),a[i-2]); + } + while(cin>>n) + { + cout< +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const double pi=acos(-1.0); +int n; +LL dp[40][40]; +LL calc(LL n,int m) +{ + LL ans=1; + LL tmp=n+m-1; + for(int i=1;i<=m;i++) + { + ans*=tmp; + ans/=i; + tmp--; + } + return ans; +} +LL dfs(int n,int mx) +{ + if(n=0;j--) + { + ans2+=dfs(n-i*mx,j); + } + ans+=ans1*ans2; + } + return ans; +} +int main() +{ + memset(dp,-1,sizeof dp); + while(scanf("%d",&n)==1) + { + LL ans=0; + for(int i=n-1;i>=0;i--) + { + ans+=dfs(n-1,i); + } + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/1295_autoAC.cpp b/HDOJ/1295_autoAC.cpp new file mode 100644 index 0000000..7f35c54 --- /dev/null +++ b/HDOJ/1295_autoAC.cpp @@ -0,0 +1,11 @@ +#include +using namespace std ; +int main() +{ + int n ; + while(cin >> n) + { + cout << n << endl ; + } + return 0 ; +} diff --git a/HDOJ/1296_autoAC.cpp b/HDOJ/1296_autoAC.cpp new file mode 100644 index 0000000..f1e05cb --- /dev/null +++ b/HDOJ/1296_autoAC.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + int n; + char a[1005]; + while(scanf("%d",&n)!=EOF) + { + scanf("%s",a); + int date=0,poww=0,wei=1,sum=0,cheng=1,flag=0; + for(int i=strlen(a)-1;i>=0;i--) + { + if(a[i]>='0'&&a[i]<='9') + { + date+=(a[i]-'0')*wei; + wei*=10; + poww=0; + } + else if(a[i]=='^') + { + poww=wei=1; + } + else if(a[i]=='X'&&poww) + { + cheng*=pow(n*1.0,date*1.0); + poww=date=0; + wei=1; + } + else if(a[i]=='X') + { + cheng*=n; + poww=0; + wei=1; + } + else if(a[i]=='-') + { + if(date==0) + sum-=cheng; + else sum-=cheng*date; + date=poww=0; + wei=cheng=1; + } + else if(a[i]=='+') + { + if(date==0) + sum+=cheng; + else sum+=date*cheng; + date=poww=0; + wei=cheng=1; + } + if(i==0) + { + if(a[i]=='+'||a[i]=='-') continue; + else flag=1; + } + } + if(flag) + { + if(date==0) + sum+=cheng; + else sum+=date*cheng; + } + printf("%d\n",sum); + } +} diff --git a/HDOJ/1297_autoAC.cpp b/HDOJ/1297_autoAC.cpp new file mode 100644 index 0000000..5a7c7d0 --- /dev/null +++ b/HDOJ/1297_autoAC.cpp @@ -0,0 +1,39 @@ +#include +int a[1001][101]; +int i,j; +void add(int n) +{ + int k=0; + for(j=1;j<101;j++) + { + k+=a[n-1][j]+a[n-2][j]+a[n-4][j]; + a[n][j]=k%10000; + k/=10000; + } + while(k) + { + a[n][j++]=k%10000; + k/=10000; + } +} +int main() +{ + int n; + int j=100; + a[1][1]=1; + a[2][1]=2; + a[3][1]=4; + a[4][1]=7; + for(i=5;i<1001;i++) + add(i); + while(scanf("%d",&n)!=EOF) + { + for(i=100;i>0;i--) + if(a[n][i]!=0)break; + printf("%d",a[n][i]); + for(i=i-1;i>0;i--) + printf("%04d",a[n][i]); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1298_autoAC.cpp b/HDOJ/1298_autoAC.cpp new file mode 100644 index 0000000..1226e95 --- /dev/null +++ b/HDOJ/1298_autoAC.cpp @@ -0,0 +1,140 @@ +#include +#include +#include +#include +using namespace std; +struct node +{ + int count; + struct node*next[26]; + int temp; +}; +struct node*newnode() +{ + int i; + struct node *r; + r=new struct node; + for(i=0;i<26;i++) + r->next[i]=NULL; + r->count=0; + r->temp=0; + return r; +} +void build(struct node *root,string str,int v) +{ + struct node*r,*s; + int i; + r=root; + for(i=0;inext[str[i]-'a']==NULL) + { + s=newnode(); + s->count=v; + r->next[str[i]-'a']=s; + r=s; + } + else + { + r=r->next[str[i]-'a']; + r->count+=v; + } + } + r->temp=1; +} +char tel[8][5]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; +struct pa +{ + char c; + int sum; +}; +int cmp(struct pa a,struct pa b) +{ + if(a.sum==b.sum) + return a.cb.sum; +} +char ans[105]=""; +char temp[105]=""; +int flag; +char sum[105]; +void search(struct node*root,string str,int v) +{ + int i; + struct node *r; + r=root; + if(v==str.length()) + { + if(r->count>flag) + { + flag=r->count; + sum[v]='\0'; + strcpy(ans,sum); + } + return ; + } + int t=0; + struct pa a[4]; + int L=strlen(tel[str[v]-'2']); + int k=0; + for(i=0;inext[tel[str[v]-'2'][i]-'a']!=NULL) + { + a[k].sum=r->next[tel[str[v]-'2'][i]-'a']->count; + a[k].c=tel[str[v]-'2'][i]; + k++; + } + } + sort(a,a+k,cmp); + for(i=0;inext[a[i].c-'a'],str,v+1); + } + return ; +} +int main() +{ + int T; + cin>>T; + for(int w=1;w<=T;w++) + { + printf("Scenario #%d:\n",w); + int N; + char p[105]; + struct node*root; + root=newnode(); + cin>>N; + while(N--) + { + int v; + scanf("%s%d",p,&v); + build(root,p,v); + } + int M;int L; + cin>>M; + int tag=0; + while(M--) + { + scanf("%s",p); + L=strlen(p); + char q[105]; + int i; + for(i=1;i +#include +#include +using namespace std; +int is_prime[100000]; +int prime[50000]; +void prepare() +{ + memset(is_prime,1,sizeof(is_prime)); + for(int i=2;i<1000;i++) + { + if(is_prime[i]) + for(int j=i;i*j<100000;j++) + is_prime[i*j]=0; + } + int s=1; + for(int i=2;i<100000;i++) + if(is_prime[i]) + prime[s++]=i; +} +int main() +{ + int t; + scanf("%d",&t); + prepare(); + int n; + int temp=0; + while(t--) + { + scanf("%d",&n); + int s=1,ans=1;; + while(prime[s]*prime[s]<=n) + { + if(n%prime[s]==0) + { + int coun=0; + while(n%prime[s]==0) + { + coun++; + n=n/prime[s]; + } + ans*=(coun*2+1); + } + s++; + } + if(n!=1) + ans*=3; + printf("Scenario #%d:\n%d\n\n",++temp,(ans+1)/2); + } + return 0; +}