From 2b2ae8c977a84b7e163684f3c3985ba5ddd53668 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Mon, 22 Aug 2016 00:13:12 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine 2300-2399 --- HDOJ/2300_autoAC.cpp | 111 ++++++++++++++++++++++ HDOJ/2303_autoAC.cpp | 57 +++++++++++ HDOJ/2304_autoAC.cpp | 23 +++++ HDOJ/2305_autoAC.cpp | 158 +++++++++++++++++++++++++++++++ HDOJ/2308_autoAC.cpp | 42 +++++++++ HDOJ/2309_autoAC.cpp | 22 +++++ HDOJ/2310_autoAC.cpp | 59 ++++++++++++ HDOJ/2312_autoAC.cpp | 81 ++++++++++++++++ HDOJ/2317_autoAC.cpp | 15 +++ HDOJ/2319_autoAC.cpp | 32 +++++++ HDOJ/2321_autoAC.cpp | 154 ++++++++++++++++++++++++++++++ HDOJ/2323_autoAC.cpp | 24 +++++ HDOJ/2327_autoAC.cpp | 219 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/2328_autoAC.cpp | 79 ++++++++++++++++ HDOJ/2332_autoAC.cpp | 115 +++++++++++++++++++++++ HDOJ/2333_autoAC.cpp | 113 ++++++++++++++++++++++ HDOJ/2334_autoAC.cpp | 136 +++++++++++++++++++++++++++ HDOJ/2335_autoAC.cpp | 54 +++++++++++ HDOJ/2337_autoAC.cpp | 142 ++++++++++++++++++++++++++++ HDOJ/2339_autoAC.cpp | 74 +++++++++++++++ HDOJ/2340_autoAC.cpp | 118 +++++++++++++++++++++++ HDOJ/2341_autoAC.cpp | 46 +++++++++ HDOJ/2351_autoAC.cpp | 125 ++++++++++++++++++++++++ HDOJ/2352_autoAC.cpp | 26 +++++ HDOJ/2354_autoAC.cpp | 57 +++++++++++ HDOJ/2363_autoAC.cpp | 104 ++++++++++++++++++++ HDOJ/2364_autoAC.cpp | 75 +++++++++++++++ HDOJ/2366_autoAC.cpp | 47 ++++++++++ HDOJ/2368_autoAC.cpp | 23 +++++ HDOJ/2369_autoAC.cpp | 43 +++++++++ HDOJ/2370_autoAC.cpp | 37 ++++++++ HDOJ/2371_autoAC.cpp | 59 ++++++++++++ HDOJ/2372_autoAC.cpp | 40 ++++++++ HDOJ/2374_autoAC.cpp | 43 +++++++++ HDOJ/2375_autoAC.cpp | 80 ++++++++++++++++ HDOJ/2376_autoAC.cpp | 59 ++++++++++++ HDOJ/2377_autoAC.cpp | 104 ++++++++++++++++++++ HDOJ/2378_autoAC.cpp | 31 ++++++ HDOJ/2379_autoAC.cpp | 44 +++++++++ HDOJ/2381_autoAC.cpp | 80 ++++++++++++++++ HDOJ/2382_autoAC.cpp | 63 +++++++++++++ HDOJ/2383_autoAC.cpp | 201 +++++++++++++++++++++++++++++++++++++++ HDOJ/2384_autoAC.cpp | 152 ++++++++++++++++++++++++++++++ HDOJ/2385_autoAC.cpp | 60 ++++++++++++ HDOJ/2387_autoAC.cpp | 86 +++++++++++++++++ HDOJ/2388_autoAC.cpp | 86 +++++++++++++++++ HDOJ/2389_autoAC.cpp | 106 +++++++++++++++++++++ HDOJ/2390_autoAC.cpp | 60 ++++++++++++ HDOJ/2391_autoAC.cpp | 40 ++++++++ HDOJ/2393_autoAC.cpp | 15 +++ HDOJ/2394_autoAC.cpp | 81 ++++++++++++++++ HDOJ/2395_autoAC.cpp | 66 +++++++++++++ HDOJ/2396_autoAC.cpp | 38 ++++++++ HDOJ/2398_autoAC.cpp | 16 ++++ HDOJ/2399_autoAC.cpp | 50 ++++++++++ 55 files changed, 4071 insertions(+) create mode 100644 HDOJ/2300_autoAC.cpp create mode 100644 HDOJ/2303_autoAC.cpp create mode 100644 HDOJ/2304_autoAC.cpp create mode 100644 HDOJ/2305_autoAC.cpp create mode 100644 HDOJ/2308_autoAC.cpp create mode 100644 HDOJ/2309_autoAC.cpp create mode 100644 HDOJ/2310_autoAC.cpp create mode 100644 HDOJ/2312_autoAC.cpp create mode 100644 HDOJ/2317_autoAC.cpp create mode 100644 HDOJ/2319_autoAC.cpp create mode 100644 HDOJ/2321_autoAC.cpp create mode 100644 HDOJ/2323_autoAC.cpp create mode 100644 HDOJ/2327_autoAC.cpp create mode 100644 HDOJ/2328_autoAC.cpp create mode 100644 HDOJ/2332_autoAC.cpp create mode 100644 HDOJ/2333_autoAC.cpp create mode 100644 HDOJ/2334_autoAC.cpp create mode 100644 HDOJ/2335_autoAC.cpp create mode 100644 HDOJ/2337_autoAC.cpp create mode 100644 HDOJ/2339_autoAC.cpp create mode 100644 HDOJ/2340_autoAC.cpp create mode 100644 HDOJ/2341_autoAC.cpp create mode 100644 HDOJ/2351_autoAC.cpp create mode 100644 HDOJ/2352_autoAC.cpp create mode 100644 HDOJ/2354_autoAC.cpp create mode 100644 HDOJ/2363_autoAC.cpp create mode 100644 HDOJ/2364_autoAC.cpp create mode 100644 HDOJ/2366_autoAC.cpp create mode 100644 HDOJ/2368_autoAC.cpp create mode 100644 HDOJ/2369_autoAC.cpp create mode 100644 HDOJ/2370_autoAC.cpp create mode 100644 HDOJ/2371_autoAC.cpp create mode 100644 HDOJ/2372_autoAC.cpp create mode 100644 HDOJ/2374_autoAC.cpp create mode 100644 HDOJ/2375_autoAC.cpp create mode 100644 HDOJ/2376_autoAC.cpp create mode 100644 HDOJ/2377_autoAC.cpp create mode 100644 HDOJ/2378_autoAC.cpp create mode 100644 HDOJ/2379_autoAC.cpp create mode 100644 HDOJ/2381_autoAC.cpp create mode 100644 HDOJ/2382_autoAC.cpp create mode 100644 HDOJ/2383_autoAC.cpp create mode 100644 HDOJ/2384_autoAC.cpp create mode 100644 HDOJ/2385_autoAC.cpp create mode 100644 HDOJ/2387_autoAC.cpp create mode 100644 HDOJ/2388_autoAC.cpp create mode 100644 HDOJ/2389_autoAC.cpp create mode 100644 HDOJ/2390_autoAC.cpp create mode 100644 HDOJ/2391_autoAC.cpp create mode 100644 HDOJ/2393_autoAC.cpp create mode 100644 HDOJ/2394_autoAC.cpp create mode 100644 HDOJ/2395_autoAC.cpp create mode 100644 HDOJ/2396_autoAC.cpp create mode 100644 HDOJ/2398_autoAC.cpp create mode 100644 HDOJ/2399_autoAC.cpp diff --git a/HDOJ/2300_autoAC.cpp b/HDOJ/2300_autoAC.cpp new file mode 100644 index 0000000..29e7c57 --- /dev/null +++ b/HDOJ/2300_autoAC.cpp @@ -0,0 +1,111 @@ +#include +#include +using namespace std; +int a[110][110]; +struct Student +{ + int x; + int y; + int m; +}r[110]; +int main() +{ + int t,x,y,num,cmd; + int i,j; + char str[110]; + int wu1[110],wu2[110],sji; + while(~scanf("%d",&t)) + { + while(t--) + { + memset(a,0,sizeof(a)); + scanf("%d %d",&x,&y); + scanf("%d %d",&num,&cmd); + for(i=0;iy)goto leap1; + a[r[wu1[i]-1].x][r[wu1[i]-1].y]=wu1[i]; + break; + case 1: + for(j=r[wu1[i]-1].x;j>=r[wu1[i]-1].x-wu2[i];j--) + { + if(j<1)goto leap1; + if(a[j][r[wu1[i]-1].y]!=0) + { + sji=a[j][r[wu1[i]-1].y]; + goto leap3; + } + } + r[wu1[i]-1].x-=wu2[i]; + a[r[wu1[i]-1].x][r[wu1[i]-1].y]=wu1[i]; + break; + case 2: + for(j=r[wu1[i]-1].y;j>=r[wu1[i]-1].y-wu2[i];j--) + { + if(j<1)goto leap1; + if(a[r[wu1[i]-1].x][j]!=0) + { + sji=a[r[wu1[i]-1].x][j]; + goto leap3; + } + } + r[wu1[i]-1].y-=wu2[i]; + a[r[wu1[i]-1].x][r[wu1[i]-1].y]=wu1[i]; + break; + case 3: + for(j=r[wu1[i]-1].x+1;j<=r[wu1[i]-1].x+wu2[i];j++) + { + if(a[j][r[wu1[i]-1].y]!=0) + { + sji=a[j][r[wu1[i]-1].y]; + goto leap3; + } + } + r[wu1[i]-1].x+=wu2[i]; + if(r[wu1[i]-1].x>x)goto leap1; + a[r[wu1[i]-1].x][r[wu1[i]-1].y]=wu1[i]; + break; + } + } + } + printf("OK\n");continue; +leap1:{printf("Robot %d crashes into the wall\n",wu1[i]);continue;} +leap3:printf("Robot %d crashes into robot %d\n",wu1[i],sji); + } + } + return 0; +} diff --git a/HDOJ/2303_autoAC.cpp b/HDOJ/2303_autoAC.cpp new file mode 100644 index 0000000..22e556d --- /dev/null +++ b/HDOJ/2303_autoAC.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +int p[1000000] ; +char pr[1000000] ; +int len, pnum, num[14] ; +void prime( ) +{ + int i, j ; + for( i=2; i<1000000; ++i ){ + pr[i] = 1 ; + } + for( i=2,pnum=0; i<1000000; ++i ){ + if( pr[i] ){ + p[pnum++] = i ; + for( j=i+i; j<1000000; j+=i ) + pr[j] = 0 ; + } + } +} +int mod( int n ) +{ + __int64 m=0 ; + int i ; + for( i=len-1; i>=0; --i ){ + m = ( m*100000000+num[i] ) % n ; + } + return m ; +} +int main() +{ + char a[111] ; + int i, j, div, flag ; + prime( ) ; + while( scanf("%s%d", a, &div ) && div && a[0]!='0' ){ + len = strlen( a ) ; + for( i=0; i<14; ++i ) + num[i] = 0 ; + for( i=0; i +const int MAX=11; +int s[MAX]; +using namespace std; +int main() +{ + int n,m,i,sum; + while(cin>>n) + { + while(n--) + { + cin>>m; + sum=0; + for(i=0;i>s[i]; + sum+=s[i]; + } + cout< +#include +using namespace std; +#define maxn 50010 +int n, m; +struct point +{ + int year, r; +}pt[maxn]; +struct Tree +{ + int Max; + int l, r; +}T[maxn*4]; +int MMax(int a, int b) +{ + return a > b ? a : b; +} +void Build(int p, int l, int r) +{ + T[p].l = l; + T[p].r = r; + if(l == r) + { + T[p].Max = pt[l].r; + return ; + } + int mid = (l + r) >> 1; + Build(p<<1, l, mid); + Build(p<<1|1, mid+1, r); + T[p].Max = max(T[p<<1].Max, T[p<<1|1].Max); +} +int Query(int p, int l, int r) +{ + if(r < T[p].l || l > T[p].r) + return 0; + if(l <= T[p].l && T[p].r <= r) + return T[p].Max; + return max(Query(p<<1, l, r), Query(p<<1|1, l, r)); +} +int Binary(int val, int l, int r) +{ + int ans = 0; + while(l <= r) { + int m = (l + r) >> 1; + if(pt[m].year <= val) + { + l = m + 1; + ans = m; + }else + r = m - 1; + } + return ans; +} +int Coces[maxn]; +int main() +{ + int i; + int t = 0; + while(scanf("%d", &n) != EOF) + { + if(t++ && n) + { + puts(""); + } + for(i = 1; i <= n; i++) + { + scanf("%d %d", &pt[i].year, &pt[i].r); + if(i == 1) + { + Coces[i] = 1; + } + else + { + if(pt[i].year - pt[i-1].year == 1) + Coces[i] = Coces[i-1]; + else + Coces[i] = Coces[i-1] + 1; + } + } + if(n) + Build(1, 1, n); + scanf("%d", &m); + int bufM = m; + while(bufM--) + { + int Y, X; + int ans; + scanf("%d %d", &Y, &X); + int fY = Binary(Y, 1, n); + int fX = Binary(X, 1, n); + if(pt[fY].year == Y && pt[fX].year == X) + { + int Yr = Query(1, fY, fY); + int Zr = Query(1, fY+1, fX-1); + int Xr = Query(1, fX, fX); + if(Coces[fY] == Coces[fX]) + { + if(Yr >= Xr && Zr < Xr) + { + ans = 0; + } + else + ans = 2; + } + else + { + if(Yr >= Xr && Zr < Xr) + { + ans = 1; + } + else + ans = 2; + } + } + else if(pt[fX].year == X) + { + if(Y + 1 == X) + { + ans = 1; + }else + { + int Zr = Query(1, fY+1, fX-1); + int Xr = Query(1, fX, fX); + if(Zr < Xr) + ans = 1; + else + ans = 2; + } + } + else if(pt[fY].year == Y) + { + int Yr = Query(1, fY, fY); + int Zr = Query(1, fY+1, fX); + if(Yr > Zr) + { + ans = 1; + }else + ans = 2; + } + else + { + ans = 1; + } + if(!ans) + puts("true"); + else if(ans == 1) + puts("maybe"); + else + puts("false"); + } + if(!n && !m) + { + break; + } + } + return 0; +} diff --git a/HDOJ/2308_autoAC.cpp b/HDOJ/2308_autoAC.cpp new file mode 100644 index 0000000..dd4ce00 --- /dev/null +++ b/HDOJ/2308_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +using namespace std; +#define maxn 30 +double a[maxn]; +int main() +{ + int n; + while(scanf("%d",&n)!=EOF) + { + if(n==0) + { + break; + } + int i; + memset(a,0,sizeof(a)); + for(i=1;i<=n;i++) + { + scanf("%lf",&a[i]); + } + sort(a+1,a+n+1); + double sum=0.0; + int flag=0; + for(i=1;i<=n;i++) + { + if(sum>=a[i]) + { + flag=1; + printf("YES\n"); + break; + } + sum+=a[i]; + } + if(flag==0) + { + printf("NO\n"); + } + } + return 0; +} diff --git a/HDOJ/2309_autoAC.cpp b/HDOJ/2309_autoAC.cpp new file mode 100644 index 0000000..8ae521e --- /dev/null +++ b/HDOJ/2309_autoAC.cpp @@ -0,0 +1,22 @@ +#include +#include +int main() +{ + int n,sum,x,max,min; + while(scanf("%d",&n)!=EOF&&n!=0) + { + sum=0; + max=0,min=1000; + for(int i=0;imax)max=x; + if(x +#include +#include +#include +using namespace std; +struct data +{ + int p,t; + bool lg; + data(){} + data(int _p,int _t,bool _lg){p=_p;t=_t;lg=_lg;} +}; +vector po[10005]; +int main() +{ + int n,m; + while(scanf("%d%d",&n,&m),n||m) + { + for(int i=1;i<=m;i++) + po[i].clear(); + int r,q,t,nn,mm,s; + scanf("%d",&r); + for(int i=0;iy) + { + if(cnt>0) + ans+=y-lx; + break; + } + else if(po[mm][j].t>=x) + { + if(cnt>0) + ans+=po[mm][j].t-lx; + lx=po[mm][j].t; + } + if(po[mm][j].lg) + cnt++; + else + cnt--; + } + printf("%d\n",ans); + } + } + return 0; +} diff --git a/HDOJ/2312_autoAC.cpp b/HDOJ/2312_autoAC.cpp new file mode 100644 index 0000000..a0dab62 --- /dev/null +++ b/HDOJ/2312_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +typedef pair PII; +typedef pair PPP; +typedef pair PPPI; +#define FI first +#define SE second +#define PRIQ priority_queue +const int R = 66; +const int C = 33; +char mat[R][C]; +bool vis[R][C][R][C]; +int n, m; +inline int dis(int a, int b, int c, int d) { return abs(a - c) + abs(b - d);} +inline bool inmat(int a, int b) { return 0 <= a && a < n && 0 <= b && b < m;} +int work() { + PRIQ Q; + int nx, ny, cx, cy; + memset(vis, 0, sizeof(vis)); + while (!Q.empty()) Q.pop(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (mat[i][j] != 'S') continue; + for (int dx = -2; dx <= 2; dx++) { + nx = i + dx; + for (int dy = 1; dy <= 3; dy++) { + ny = j + dy; + if (inmat(nx, ny) && dis(i, j, nx, ny) <= 3 && mat[nx][ny] != 'X' && !vis[i][j][nx][ny]) { + if (isdigit(mat[nx][ny])) Q.push(PPPI((int) '0' - mat[nx][ny], PPP(PII(i, j), PII(nx, ny)))); + else Q.push(PPPI(0, PPP(PII(i, j), PII(nx, ny)))); + vis[i][j][nx][ny] = true; + } + ny = j - dy; + if (inmat(nx, ny) && dis(nx, ny, i, j) <= 3 && mat[nx][ny] != 'X' && !vis[nx][ny][i][j]) { + if (isdigit(mat[nx][ny])) Q.push(PPPI((int) '0' - mat[nx][ny], PPP(PII(nx, ny), PII(i, j)))); + else Q.push(PPPI(0, PPP(PII(nx, ny), PII(i, j)))); + vis[nx][ny][i][j] = true; + } + } + } + } + } + while (!Q.empty()) { + PPPI cur = Q.top(); + Q.pop(); + int v = cur.FI, a = cur.SE.FI.FI, b = cur.SE.FI.SE, c = cur.SE.SE.FI, d = cur.SE.SE.SE; + if (mat[a][b] == 'T' || mat[c][d] == 'T') return -v; + for (int dx = -2; dx <= 2; dx++) { + nx = a + dx; + cx = c + dx; + for (int dy = 1; dy <= 3; dy++) { + ny = b + dy; + if (inmat(nx, ny) && dis(a, b, nx, ny) <= 3 && mat[nx][ny] != 'X' && !vis[a][b][nx][ny]) { + if (isdigit(mat[nx][ny])) Q.push(PPPI((int) '0' - mat[nx][ny] + v, PPP(PII(a, b), PII(nx, ny)))); + else Q.push(PPPI(v, PPP(PII(a, b), PII(nx, ny)))); + vis[a][b][nx][ny] = true; + } + cy = d - dy; + if (inmat(cx, cy) && dis(cx, cy, c, d) <= 3 && mat[cx][cy] != 'X' && !vis[cx][cy][c][d]) { + if (isdigit(mat[cx][cy])) Q.push(PPPI((int) '0' - mat[cx][cy] + v, PPP(PII(cx, cy), PII(c, d)))); + else Q.push(PPPI(v, PPP(PII(cx, cy), PII(c, d)))); + vis[cx][cy][c][d] = true; + } + } + } + } + return -1; +} +int main() { + while (cin >> m >> n && (n || m)) { + char buf[3]; + for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> buf, mat[i][j] = buf[0]; + cout << work() << endl; + } + return 0; +} diff --git a/HDOJ/2317_autoAC.cpp b/HDOJ/2317_autoAC.cpp new file mode 100644 index 0000000..9ace729 --- /dev/null +++ b/HDOJ/2317_autoAC.cpp @@ -0,0 +1,15 @@ +#include +int main() +{ + int a,r,e,c,sum,s; + scanf("%d",&a); + while(a--) + { + s=0; sum=0; + scanf("%d%d%d",&r,&e,&c); + s=e-c; + if(s>r) printf("advertise\n"); + else if(s==r) printf("does not matter\n"); + else if(s +#include +using namespace std; +int main() +{ + int t,n,i,a[14],b[14],m,k; + scanf("%d",&t); + while (t--) + { + queue q; + scanf("%d",&n); + for(i=0;i +#include +#include +#include +#include +#define NUM 1100 +#define N 33 +#define M 11 +using namespace std; +int dp[N][N][M],Max[N][N][M]; +int sum[N][N][N][N][M]; +struct num +{ + int x,y,t; +}a[NUM]; +bool cmp(num p1,num p2) +{ + return p1.xd*d) + { + continue; + } + for(int i=1;i<=m;i++) + { + int x = a[i].x; + int y = a[i].y; + int t = a[i].t; + if(x>x2) + { + break; + } + if(x1==x2&&y1==y2&&x==x1&&y==y1) + { + sum[x1][y1][x2][y2][t]++; + continue; + }else if(x1==x2&&y1==y2) + { + continue; + } + if(x==x1&&x==x2&&y>=y1&&y<=y2) + { + sum[x1][y1][x2][y2][t]++; + sum[x2][y2][x1][y1][t]++; + continue; + } + double k = (double)(y2-y1)/(double)(x2-x1); + double D = (double)(y2) - k *(double)(x2); + if(fabs(k*(double)(x)+D-(double)(y))<=1e-7&&x>=x1&&x<=x2) + { + sum[x1][y1][x2][y2][t]++; + sum[x2][y2][x1][y1][t]++; + } + } + } + } + } + } + memset(dp,0,sizeof(dp)); + memset(Max,0,sizeof(Max)); + for(int t=1;t<=10;t++) + { + for(int x1 =0;x1<=n-1;x1++) + { + for(int y1=0;y1<=n-1;y1++) + { + for(int x2=0;x2<=n-1;x2++) + { + for(int y2=0;y2<=n-1;y2++) + { + //dp[x1][y1][x2][y2][t]; + if(((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))>d*d) + { + continue; + } + int mmax=0; + for(int kb=1;kb<=t-1;kb++) + { + mmax=max(mmax,dp[x1][y1][kb]); + } + Max[x2][y2][t]=max(Max[x2][y2][t],mmax+sum[x1][y1][x2][y2][t]); + } + } + } + } + for(int x2=0;x2<=n-1;x2++) + { + for(int y2=0;y2<=n-1;y2++) + { + dp[x2][y2][t] = Max[x2][y2][t]; + } + } + } + int res = 0; + for(int i=0;i<=n-1;i++) + { + for(int j=0;j<=n-1;j++) + { + for(int t=1;t<=10;t++) + { + res = max(res,dp[i][j][t]); + } + } + } + printf("%d\n",res); + } + return 0; +} diff --git a/HDOJ/2323_autoAC.cpp b/HDOJ/2323_autoAC.cpp new file mode 100644 index 0000000..b80bd85 --- /dev/null +++ b/HDOJ/2323_autoAC.cpp @@ -0,0 +1,24 @@ +#include +int way[15][17][17]; +int list[15]; +int main() +{ + int k,n,i,j,t; + way[0][8][8]=1; + for(k=1;k<=14;k++) + { + for(i=0;i<17;i++) + for(j=1;j<17;j++) + way[k][i][j]=way[k-1][i-1][j]+way[k-1][i][j+1] + +way[k-1][i+1][j]+way[k-1][i+1][j+1] + +way[k-1][i][j-1]+way[k-1][i-1][j-1]; + list[k]=way[k][8][8]; + } + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + printf("%d\n",list[n]); + } + return 0; +} diff --git a/HDOJ/2327_autoAC.cpp b/HDOJ/2327_autoAC.cpp new file mode 100644 index 0000000..bd04163 --- /dev/null +++ b/HDOJ/2327_autoAC.cpp @@ -0,0 +1,219 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define MAXN 100005 +#define MAXM 211111 +#define eps 1e-8 +#define INF 50000001 +using namespace std; +inline int dblcmp(double d) +{ + if(fabs(d) < eps) return 0; + return d > eps ? 1 : -1; +} +struct point +{ + double x, y; + point(){} + point(double _x, double _y): x(_x), y(_y) {} + void input() + { + scanf("%lf%lf", &x, &y); + } + bool operator ==(point a)const + { + return dblcmp(a.x - x) == 0 && dblcmp(a.y - y) == 0; + } + point sub(point p) + { + return point(x - p.x, y - p.y); + } + double dot(point p) + { + return x * p.x + y * p.y; + } + double det(point p) + { + return x * p.y - y * p.x; + } + double distance(point p) + { + return hypot(x - p.x, y - p.y); + } +}p[33]; +struct line +{ + point a, b; + line(){} + line(point _a, point _b){ a = _a; b = _b;} + void input() + { + a.input(); + b.input(); + } + int segcrossseg(line v) + { + int d1 = dblcmp(b.sub(a).det(v.a.sub(a))); + int d2 = dblcmp(b.sub(a).det(v.b.sub(a))); + int d3 = dblcmp(v.b.sub(v.a).det(a.sub(v.a))); + int d4 = dblcmp(v.b.sub(v.a).det(b.sub(v.a))); + if ((d1 ^ d2) == -2 && (d3 ^ d4) == -2)return 2; + return (d1 == 0 && dblcmp(v.a.sub(a).dot(v.a.sub(b))) <= 0|| + d2 == 0 && dblcmp(v.b.sub(a).dot(v.b.sub(b))) <= 0|| + d3 == 0 && dblcmp(a.sub(v.a).dot(a.sub(v.b))) <= 0|| + d4 == 0 && dblcmp(b.sub(v.a).dot(b.sub(v.b))) <= 0); + } + int linecrossseg(line v)//v is seg + { + int d1 = dblcmp(b.sub(a).det(v.a.sub(a))); + int d2 = dblcmp(b.sub(a).det(v.b.sub(a))); + if ((d1 ^ d2) == -2) return 2; + return (d1 == 0 || d2 == 0); + } + point crosspoint(line v) + { + double a1 = v.b.sub(v.a).det(a.sub(v.a)); + double a2 = v.b.sub(v.a).det(b.sub(v.a)); + return point((a.x * a2 - b.x * a1) / (a2 - a1), (a.y * a2 - b.y * a1) / (a2 - a1)); + } +}; +struct node +{ + string name; + vectorseg; +}; +char sa[55], sb[55]; +vectorg; +vectorans[55]; +bool cmp(node x, node y) +{ + return x.name < y.name; +} +bool ok(int k1, int k2) +{ + int sz1 = g[k1].seg.size(); + int sz2 = g[k2].seg.size(); + for(int i = 0; i < sz1; i++) + for(int j = 0; j < sz2; j++) + if(g[k1].seg[i].segcrossseg(g[k2].seg[j])) return true; + return false; +} +void solve() +{ + for(int i = 0; i < 50; i++) ans[i].clear(); + sort(g.begin(), g.end(), cmp); + int sz = g.size(); + for(int i = 0; i < sz; i++) + { + for(int j = 0; j < sz; j++) + { + if(i == j) continue; + if(ok(i, j)) ans[i].push_back(g[j].name); + } + } + for(int i = 0; i < sz; i++) + { + if(ans[i].size() == 0) printf("%s has no intersections\n", g[i].name.c_str()); + else + { + if(ans[i].size() == 1) + { + printf("%s intersects with %s\n", g[i].name.c_str(), ans[i][0].c_str()); + } + else if(ans[i].size() == 2) + { + printf("%s intersects with %s and %s\n", g[i].name.c_str(), ans[i][0].c_str(), ans[i][1].c_str()); + } + else + { + printf("%s intersects with ", g[i].name.c_str()); + for(int j = 0; j < ans[i].size() - 1; j++) printf("%s, ", ans[i][j].c_str()); + printf("and %s\n", ans[i][ans[i].size() - 1].c_str()); + } + } + } + g.clear(); + printf("\n"); +} +int main() +{ + double xa, ya, xb, yb; + while(scanf("%s", sa) != EOF) + { + if(strcmp(sa, "-") == 0) + { + solve(); + continue; + } + if(strcmp(sa, ".") == 0) break; + node tmp; + tmp.name = sa; + scanf("%s", sb); + if(sb[0] == 's') + { + point a, c; + scanf(" (%lf,%lf)", &a.x, &a.y); + scanf(" (%lf,%lf)", &c.x, &c.y); + point b, d; + double x, y, mx, my; + mx = (a.x + c.x)/2.0, my = (a.y + c.y) / 2.0; + x = a.x - mx; y = a.y - my; + b.x = -y + mx; b.y = x + my; + x = c.x - mx; y = c.y - my; + d.x = - y + mx; d.y = x + my; + tmp.seg.push_back(line(a, b)); + tmp.seg.push_back(line(b, c)); + tmp.seg.push_back(line(a, d)); + tmp.seg.push_back(line(c, d)); + } + else if(sb[0] == 'l') + { + point a, b; + scanf(" (%lf,%lf)", &a.x, &a.y); + scanf(" (%lf,%lf)", &b.x, &b.y); + tmp.seg.push_back(line(a, b)); + } + else if(sb[0] == 't') + { + point a, b, c; + scanf(" (%lf,%lf)", &a.x, &a.y); + scanf(" (%lf,%lf)", &b.x, &b.y); + scanf(" (%lf,%lf)", &c.x, &c.y); + tmp.seg.push_back(line(a, b)); + tmp.seg.push_back(line(a, c)); + tmp.seg.push_back(line(b, c)); + } + else if(sb[0] == 'r') + { + point a, b, c, d; + scanf(" (%lf,%lf)", &a.x, &a.y); + scanf(" (%lf,%lf)", &b.x, &b.y); + scanf(" (%lf,%lf)", &c.x, &c.y); + double dx = b.x - a.x; + d.x = c.x - dx; + double dy = b.y - a.y; + d.y = c.y - dy; + tmp.seg.push_back(line(a, b)); + tmp.seg.push_back(line(b, c)); + tmp.seg.push_back(line(a, d)); + tmp.seg.push_back(line(c, d)); + } + else + { + int t; + scanf("%d", &t); + for(int i = 0; i < t; i++) scanf(" (%lf,%lf)", &p[i].x, &p[i].y); + for(int i = 0; i < t; i++) tmp.seg.push_back(line(p[i], p[(i + 1) % t])); + } + g.push_back(tmp); + } + return 0; +} diff --git a/HDOJ/2328_autoAC.cpp b/HDOJ/2328_autoAC.cpp new file mode 100644 index 0000000..64c6888 --- /dev/null +++ b/HDOJ/2328_autoAC.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include +using namespace std; +#define MAXN 4010 +#define N 210 +int n; +int nex[MAXN]; +char words[MAXN][N]; +/*qsort*/ +int cmp(const void *str1 , const void *str2){ + return strlen((char *)str1)-strlen((char *)str2); +} +/*姹next*/ +void getNext(char *str){ + int len = strlen(str); + nex[0] = nex[1] = 0; + for(int i = 1 ; i < len ; i++){ + int j = nex[i]; + while(j && str[i] != str[j]) + j = nex[j]; + nex[i+1] = str[i] == str[j] ? j+1 : 0; + } +} +/*归芥*/ +bool find(char *text , char *str){ + int n = strlen(text); + int m = strlen(str); + int j = 0; + for(int i = 0 ; i < n ; i++){ + while(j && text[i] != str[j]) + j = nex[j]; + if(str[j] == text[i]) + j++; + if(j == m) + return true; + } + return false; +} +int main(){ + int max; + char ans[MAXN]; + while(scanf("%d%*c" , &n) && n){ + for(int i = 0 ; i < n ; i++) + scanf("%s" , words[i]); + qsort(words , n , sizeof(words[0]) , cmp); + int pos; + char tmp[N]; + int len = strlen(words[0]); + max = 0; + for(int i = 0 ; i < len ; i++){ + memset(tmp , '\0' , sizeof(tmp)); + pos = 0; + for(int j = i ; j < len ; j++){ + tmp[pos++] = words[0][j]; + getNext(tmp); + int vis = 1; + for(int k = 1 ; k < n ; k++){ + if(!find(words[k] , tmp)){ + vis = 0; + break; + } + } + if(vis && max < pos){ + max = pos; + memcpy(ans , tmp , sizeof(tmp)); + } + else if(vis && max == pos && strcmp(ans , tmp) > 0) + memcpy(ans , tmp , sizeof(tmp)); + } + } + if(max) + printf("%s\n" , ans); + else + printf("IDENTITY LOST\n"); + } + return 0; +} diff --git a/HDOJ/2332_autoAC.cpp b/HDOJ/2332_autoAC.cpp new file mode 100644 index 0000000..52f3889 --- /dev/null +++ b/HDOJ/2332_autoAC.cpp @@ -0,0 +1,115 @@ +#include +#include +const int MAXCUBE = 1048576 ; +int d ; +int n[21] ; +int mv[21] ; +char space[MAXCUBE] ; +int q[MAXCUBE] ; +int stp[MAXCUBE] ; +int front , rear ; +bool vst[MAXCUBE] ; +int p ; +int s , m , t , curs; +void visit(int pt){ + if ( !(pt >= 0 && pt < mv[d]) ) { + return ; + } + if ( vst[pt] || space[pt] ) return ; + vst[pt] = true ; + stp[pt] = curs ; + q[rear] = pt ; + rear ++ ; +} +int bfs(int from , int to ){ + int curp , newp ; + int i ; + memset(vst , false , sizeof(vst)) ; + front = 0 ; + rear = 1 ; + q[0] = from ; + stp[from] = 0 ; + vst[from] = true ; + while ( front < rear ){ + curp = q[front ++] ; + curs = stp[curp] + 1; + if ( curp == to ) { + front -- ; + break ; + } + for ( i = 0 ; i < d ; i ++ ){ + if ( ( ( curp ) / mv[i] ) % n[i] != n[i] - 1 ){ + newp = curp + mv[i] ; + visit(newp); + } + if ( ( ( curp ) / mv[i] ) % n[i] != 0 ){ + newp = curp - mv[i] ; + visit(newp); + } + } + } + if ( front == rear ) return - 1; + else return stp[curp] ; +} +char nextchar(){ + char ch ; + do{ + ch = getchar() ; + }while ( ch != '#' && ch != '.' && ch != 'S' && ch != 'M' && ch != 'T' ) ; + if ( ch == 'S' ) s = p ; + if ( ch == 'M' ) m = p ; + if ( ch == 'T' ) t = p ; + if ( ch == '#' ) return 1 ; + else return 0 ; +} +void readmap(int layer){ + int i; + if ( layer == 0 ){ + space[p ++ ] = nextchar() ; + return ; + } + for ( i = 0 ; i < n[layer - 1] ; i ++ ) readmap( layer - 1 ) ; +} +int main(){ + int i ; + int ans ; + while (1){ + scanf("%d",&d); + if ( d == 0 ) break ; + for ( i = 0 ; i < d ; i ++ ){ + scanf("%d",n + i ) ; + } + mv[0] = 1 ; + for ( i = 1 ; i <= d ; i ++ ){ + mv[i] = n[i - 1] * mv[i - 1] ; + } + p = 0 ; + readmap(d) ; + ans = 0 ; + space[m] = 1 ; + i = bfs(t,s) ; + if ( i == -1 ){ + ans = -1 ; + }else{ + space[m] = 0 ; + ans += i ; + i = bfs(s,m) ; + if ( i == -1 ){ + ans = -1 ; + }else{ + ans += i ; + i = bfs(m,t) ; + if ( i == -1 ){ + ans = -1 ; + }else{ + ans += i ; + } + } + } + if ( ans == -1 )puts("No solution. Poor Theseus!"); + else{ + printf("Theseus needs %d steps.\n",ans); + } + } + return 0 ; +} diff --git a/HDOJ/2333_autoAC.cpp b/HDOJ/2333_autoAC.cpp new file mode 100644 index 0000000..57b876a --- /dev/null +++ b/HDOJ/2333_autoAC.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#define leps 1e-6 +using namespace std; +const int maxn=1000+7; +const int maxc=1e9+7; +int n,b,t,id; +struct component +{ + int price; + int quality; +}; +vectorv[maxn]; +void clear() +{ + for(int i=0;i m; + char s[maxn],name[maxn]; + int p,q; + component com; + for(int i=1;i<=n;i++) + { + scanf("%s %s %d %d",s,name,&p,&q); + minn=min(minn,q); + maxx=max(maxx,q); + if(m[s]) + { + com.price=p; + com.quality=q; + v[m[s]].push_back(com); + } + else + { + m[s]=id++; + com.price=p; + com.quality=q; + v[m[s]].push_back(com); + } + } +} +int min_value(int i,int x) +{ + int len=v[i].size(); + int temp=maxc; + for(int j=0;j=x) + { + temp=min(temp,v[i][j].price); + } + } + if(temp==maxc)return -1; + return temp; +} +bool ok(int x) +{ + long long ans=0; + for(int i=1;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define maxn 5000 +#define MAXN 2005 +#define MAXM 20000005 +#define INF 100000000 +#define oo 1000000007 +using namespace std; +struct Dinic +{ + struct node + { + int x,y,c,next; + }line[MAXM]; + int Lnum,_next[MAXN],dis[MAXN],dp[MAXN]; + bool inqueue[MAXN]; + void initial(int n) + { + for (int i=0;i<=n;i++) _next[i]=-1; + Lnum=-1; + } + void addline(int x,int y,int c) + { + line[++Lnum].next=_next[x],_next[x]=Lnum; + line[Lnum].x=x,line[Lnum].y=y,line[Lnum].c=c; + line[++Lnum].next=_next[y],_next[y]=Lnum; + line[Lnum].x=y,line[Lnum].y=x,line[Lnum].c=0; + } + bool BFS(int s,int e) + { + queue Q; + while (!Q.empty()) Q.pop(); + memset(dis,0,sizeof(dis)); + dis[s]=1,Q.push(s); + while (!Q.empty()) + { + int h,k; + h=Q.front(),Q.pop(); + if (h==e) return dis[e]; + for (k=_next[h];k!=-1;k=line[k].next) + if (line[k].c && !dis[line[k].y]) + dis[line[k].y]=dis[h]+1,Q.push(line[k].y); + } + return false; + } + int dfs(int x,int flow,int e) + { + if (x==e) return flow; + int temp,cost=0; + for (int k=_next[x];k!=-1;k=line[k].next) + if (line[k].c && dis[line[k].y]==dis[x]+1) + { + temp=dfs(line[k].y,min(flow-cost,line[k].c),e); + if (temp) + { + line[k].c-=temp,line[k^1].c+=temp; + cost+=temp; + if (flow==cost) return cost; + }else dis[line[k].y]=-1; + } + return cost; + } + int MaxFlow(int s,int e) + { + int MaxFlow=0; + while (BFS(s,e)) MaxFlow+=dfs(s,oo,e); + return MaxFlow; + } +}T; +struct Point +{ + int x,y,n,m; +}; +Point p[maxn]; +int dist(int s,int t,double dd) +{ + return (p[s].x-p[t].x)*(p[s].x-p[t].x)+(p[s].y-p[t].y)*(p[s].y-p[t].y)<=dd; +} +int vist[maxn][maxn]; +bool judge(int e,int n,int sum) +{ + int i,j,s=n*2+5; + T.initial(n*2+5); + for (i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define maxn 5000 +#define MAXN 2005 +#define MAXM 20000005 +#define INF 100000000000000 +#define oo 1000000007 +using namespace std; +typedef long long LL; +int main() +{ + int t; + while(scanf("%d",&t)!=EOF) + { + while(t--) + { + LL n,x,y; + LL min_n=INF; + scanf("%I64d",&n); + n=(n+4)/5; + LL tem=(LL)sqrt(double(n)); + for(LL i=1; i<=tem; i++) + { + LL j=(n+(i-1))/i; + LL xx=i*40+(i+1)*4; + LL yy=j*8+(j+1)*2; + if(xx*yyabs(xx-yy)) + { + x=xx; + y=yy; + } + } + } + printf("%I64d X %I64d = %I64d\n",max(x,y),min(x,y),min_n); + } + } + return 0; +} diff --git a/HDOJ/2337_autoAC.cpp b/HDOJ/2337_autoAC.cpp new file mode 100644 index 0000000..dd45739 --- /dev/null +++ b/HDOJ/2337_autoAC.cpp @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +using namespace std; +const int N = 1001; +const int M = 1000004; +const int NM = 10001; +struct node +{ + int x,y,step; +}que[M],ss,now; +int n,m,nm,sx,sy,ex,ey,maxans,minans,minlen; +int pt[NM][2]; +bool flag[N][N]; +int dist[N][N]; +int dir[4][2] = {{-1,0},{0,-1},{0,1},{1,0}}; +int dis(int a,int b,int c,int d) +{ + return (abs(a - c) + abs(b - d)); +} +void Bfs(int id) +{ + ss.x = pt[id][0]; + ss.y = pt[id][1]; + ss.step = 0; + int i,head,tail; + head = tail = 0; + que[tail ++] = ss; + memset(flag,false,sizeof(flag)); + flag[ss.x][ss.y] = true; + while(head != tail) + { + now = que[head ++]; + if(head == M) + head = 0; + if(now.step > maxans) + return; + dist[now.x][now.y] = min(dist[now.x][now.y],now.step); + ss = now; + ss.step ++; + for(i = 0;i < 4;i ++) + { + ss.x = now.x + dir[i][0]; + ss.y = now.y + dir[i][1]; + if(ss.x >= 0 && ss.y >= 0 && ss.x < n && ss.y < m && !flag[ss.x][ss.y]) + { + flag[ss.x][ss.y] = true; + que[tail ++] = ss; + if(tail == M) + tail = 0; + } + } + } +} +void init() +{ + scanf("%d%d%d",&nm,&n,&m); + scanf("%d%d%d%d",&sx,&sy,&ex,&ey); + maxans = 0x3f3f3f3f; + memset(dist,0x3f,sizeof(dist)); + for(int i = 0;i < nm;i ++) + scanf("%d%d",&pt[i][0],&pt[i][1]),maxans = min(maxans,dis(sx,sy,pt[i][0],pt[i][1])); + for(int i = 0;i < nm;i ++) + Bfs(i); +} +bool isok(int x,int y,int cmp) +{ + if(x < 0 || y < 0 || x >= n || y >= m) + return false; + else + { + return dist[x][y] >= cmp; + } +} +bool bfs(int lim) +{ + ss.x = sx; + ss.y = sy; + ss.step = 0; + memset(flag,false,sizeof(flag)); + flag[sx][sy] = true; + int head,tail,i; + head = tail = 0; + que[tail ++] = ss; + while(head != tail) + { + now = que[head ++]; + if(head == M) + head = 0; + ss = now; + ss.step ++; + for(i = 0;i < 4;i ++) + { + ss.x = now.x + dir[i][0]; + ss.y = now.y + dir[i][1]; + if(isok(ss.x,ss.y,lim) && !flag[ss.x][ss.y]) + { + if(ss.x == ex && ss.y == ey) + { + minlen = ss.step; + return true; + } + flag[ss.x][ss.y] = true; + que[tail ++] = ss; + if(tail == M) + tail = 0; + } + } + } + return false; +} +void fun() +{ + init(); + int l,r,mid; + l = 0;r = maxans; + minans = maxans;minlen = dis(ex,ey,sx,sy); + while(l <= r) + { + mid = (l + r)>>1; + if(bfs(mid)) + { + minans = mid; + l = mid + 1; + } + else + r = mid - 1; + } + printf("%d %d\n",minans,minlen); +} +int main() +{ + int t; + scanf("%d",&t); + while(t --) + { + fun(); + } + return 0; +} diff --git a/HDOJ/2339_autoAC.cpp b/HDOJ/2339_autoAC.cpp new file mode 100644 index 0000000..9109f3b --- /dev/null +++ b/HDOJ/2339_autoAC.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +using namespace std; +const int maxn = 505; +int G[maxn][maxn]; +int vis[maxn][maxn]; +int n, m, d; +const int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}}; +struct Node { + int x, y, v; +}node[maxn * maxn], q[maxn * maxn]; +int cmp (const Node &a, const Node &b) { + return a.v > b.v; +} +int BFS (int k) { + int front , rear; + int cnt = 1; + front = 0; + rear = 1; + q[front] = node[k]; + vis[node[k].x][node[k].y] = node[k].v; + bool flag = 1; + while (front < rear) { + for (int i = 0; i < 4; i++) { + int newx = q[front].x + dir[i][0]; + int newy = q[front].y + dir[i][1]; + if (newx < 0 || newx >= n || newy < 0 || newy >= m) + continue; + if (G[newx][newy] > node[k].v) { + flag = 0; + continue; + } + if (vis[newx][newy] == node[k].v || node[k].v - G[newx][newy] >= d) + continue; + vis[newx][newy] = node[k].v; + if (G[newx][newy] == node[k].v) + cnt++; + else + G[newx][newy] = node[k].v; + q[rear].x = newx; + q[rear++].y = newy; + } + front++; + } + if (flag) + return cnt; + return 0; +} +int main () { + int T; + scanf ("%d", &T); + while (T--) { + scanf ("%d%d%d", &n, &m, &d); + int cnt = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + scanf ("%d", &G[i][j]); + node[cnt].x = i; + node[cnt].y = j; + node[cnt++].v = G[i][j]; + } + sort (node, node + cnt, cmp); + memset (vis, -1, sizeof (vis)); + int ans = 0; + for (int i = 0; i < cnt; i++) { + if (vis[node[i].x][node[i].y] == -1) { + ans += BFS(i); + } + } + printf ("%d\n", ans); + } + return 0; +} diff --git a/HDOJ/2340_autoAC.cpp b/HDOJ/2340_autoAC.cpp new file mode 100644 index 0000000..9653967 --- /dev/null +++ b/HDOJ/2340_autoAC.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define maxn 1005 +#define MAXN 100005 +#define mod 1000000000 +#define INF 0x3f3f3f3f +#define pi acos(-1.0) +#define eps 1e-6 +typedef long long ll; +using namespace std; +int n,m,ans,cnt,tot,flag; +char s[maxn],res[10005][105]; +string S,cur,now; +struct Node +{ + int len,id; + char endc; + string s; +} tt; +vector vn[26]; +int vis[1005]; +bool isok(int pos,int i) +{ + int j,t=S[pos]-'a',len=vn[t][i].len; + if(len==-1) return 1; + if(pos+len+1>=tot) return 0; + if(vn[t][i].endc!=S[pos+len+1]) return 0; + string ss=S.substr(pos+1,len); + sort(ss.begin(),ss.end()); + if(ss==vn[t][i].s) return 1; + return 0; +} +void solve() +{ + int i,j,t; + vectorvs[1005]; + memset(vis,0,sizeof(vis)); + vis[0]=1; + for(i=0; i +#include +#include +#include +using namespace std; +struct park +{ + int x, y; +}; +int main() +{ + int i, j, n, m, T, k, t; + scanf("%d", &T); + while(T--) + { + scanf("%d%d", &n, &m); + park p[2505]; + int turn[55]; + memset(turn, 0, sizeof(turn)); + int num=0; + for(i=1; i<=n; i++) + { + turn[i]=1; + for(j=1; j<=m; j++) + { + scanf("%d", &k); + if(k==-1) + continue; + num++; + p[k].x=i, p[k].y=j; + } + } + int total=0; + int mid; + for(i=1; i<=num; i++) + { + if(p[i].y>turn[p[i].x]) + mid=p[i].y-turn[p[i].x]; + else + mid=turn[p[i].x]-p[i].y; + total+=20*(p[i].x-1)+5*(min(mid, m-mid)); + turn[p[i].x]=p[i].y; + } + printf("%d\n", total); + } +} diff --git a/HDOJ/2351_autoAC.cpp b/HDOJ/2351_autoAC.cpp new file mode 100644 index 0000000..19aa594 --- /dev/null +++ b/HDOJ/2351_autoAC.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define LL long long +#define ULL unsigned long long +#define SZ(x) (int)x.size() +#define Lowbit(x) ((x) & (-x)) +#define MP(a, b) make_pair(a, b) +#define MS(arr, num) memset(arr, num, sizeof(arr)) +#define PB push_back +#define X first +#define Y second +#define MID(a, b) (a + ((b - a) >> 1)) +#define LC rt << 1, l, mid +#define RC rt << 1|1, mid + 1, r +#define LRT rt << 1 +#define RRT rt << 1|1 +const double PI = acos(-1.0); +const int INF = 0x3f3f3f3f; +const double eps = 1e-8; +const int MAXN = 110; +const int MOD = 1e9 + 7; +const int dir[][2] = { {-1, 0}, {0, -1}, { 1, 0 }, { 0, 1 } }; +int cases = 0; +typedef pair pii; +struct NUM +{ + int sum, multiple, num, square, cube, quad; +}arr[MAXN]; +void Handle(NUM &num) +{ + int tmp = num.num, curNum = num.num; + int sum = 0, multiple = 1; + while (tmp) + { + sum += tmp % 10; + multiple *= tmp % 10; + tmp /= 10; + } + num.sum = sum; num.multiple = multiple; + num.square = curNum <= 1000 ? curNum*curNum : -1; + num.quad = curNum <= 100 ? curNum*curNum*curNum*curNum : -1; + num.cube = curNum <= 100 ? curNum*curNum*curNum : -1; +} +set cube, square, quad; +int ansCnt; +void Init() +{ + for (int i = 1; i <= 1000; i++) + { + square.insert(i*i); + if (i <= 100) cube.insert(i*i*i), quad.insert(i*i*i*i); + } +} +bool isPrime(int num) +{ + if (num == 1) return false; + if (num == 2) return true; + for (int i = 2; i <= (int)sqrt(num+0.5); i++) + if (num % i == 0) return false; + return true; +} +int n, cnt[MAXN]; +void Solve(const int &cur) +{ + cnt[cur] = 0; + int curNum = arr[cur].num; + const NUM &num = arr[cur]; + for (int i = 0; i < n; i++) + { + if (i == cur) continue; + NUM &k = arr[i]; + if (k.num % curNum == 0) cnt[cur]++; + if (curNum % k.num == 0) cnt[cur]++; + if (k.square == curNum) cnt[cur]++; + if (k.cube == curNum) cnt[cur]++; + if (k.quad == curNum) cnt[cur]++; + if (curNum % k.sum == 0) cnt[cur]++; + if (k.multiple != 0 && curNum % k.multiple == 0) cnt[cur]++; + } + if (square.count(curNum)) cnt[cur]++; + if (cube.count(curNum)) cnt[cur]++; + if (quad.count(curNum)) cnt[cur]++; + if (curNum % num.sum == 0) cnt[cur]++; + if (num.multiple != 0 && curNum % num.multiple == 0) cnt[cur]++; + if (isPrime(curNum)) cnt[cur]++; + ansCnt = max(ansCnt, cnt[cur]); +} +int main() +{ + Init(); + int T; + scanf("%d", &T); + while (T--) + { + ansCnt = -1; + scanf("%d", &n); + for (int i = 0; i < n; i++) + { + scanf("%d", &arr[i].num); + Handle(arr[i]); + } + for (int i = 0; i < n; i++) Solve(i); + vector ans; + for (int i = 0; i < n; i++) + if (ansCnt == cnt[i]) ans.PB(arr[i].num); + sort(ans.begin(), ans.end()); + printf("DATA SET #%d\n", ++cases); + for (int i = 0; i < SZ(ans); i++) printf("%d\n", ans[i]); + } + return 0; +} diff --git a/HDOJ/2352_autoAC.cpp b/HDOJ/2352_autoAC.cpp new file mode 100644 index 0000000..1067e5c --- /dev/null +++ b/HDOJ/2352_autoAC.cpp @@ -0,0 +1,26 @@ +#include +#include +int main() +{ + int a[10000],i,n,sum,len; + char s[1000]; + a['I']=1;a['V']=5;a['X']=10;a['L']=50;a['C']=100;a['D']=500;a['M']=1000; + scanf("%d",&n); + getchar(); + while(n--) + { + gets(s); + len=strlen(s); + sum=0; + for(i=0;i<=len-2;i++) + { + if(a[s[i]]>=a[s[i+1]]) + sum=sum+a[s[i]]; + else + sum=sum-a[s[i]]; + } + sum=sum+a[s[len-1]]; + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/2354_autoAC.cpp b/HDOJ/2354_autoAC.cpp new file mode 100644 index 0000000..8c75b77 --- /dev/null +++ b/HDOJ/2354_autoAC.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +using namespace std; +#define inf 1<<30 +struct Node{ + int x,y,step; + bool operator < (const Node &p) const { + return p.stepQ; + Node p,q; + for(int i=1;i<=m;i++){ + p.x=1,p.y=i,p.step=1; + Q.push(p); + } + while(!Q.empty()){ + p=Q.top(); + Q.pop(); + if(p.x==n)return p.step; + for(int i=0;i<4;i++){ + q.x=p.x+dir[i][0]; + q.y=p.y+dir[i][1]; + q.step=p.step; + if(q.x<1||q.x>n||q.y<1||q.y>m)continue; + if(map[q.x][q.y]!=map[p.x][p.y])q.step++; + if(Step[q.x][q.y]>q.step){ + Step[q.x][q.y]=q.step; + Q.push(q); + } + } + } + return 1; +} +int main(){ + int _case; + scanf("%d",&_case); + while(_case--){ + scanf("%d%d",&n,&m); + for(int i=1;i<=n;i++) + scanf("%s",map[i]+1); + int ans=bfs(); + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/2363_autoAC.cpp b/HDOJ/2363_autoAC.cpp new file mode 100644 index 0000000..dc3aa29 --- /dev/null +++ b/HDOJ/2363_autoAC.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include +int n; +struct A +{ + int dis; + int high; + int flag; + int hash; +}E[111]; +int map[111][111]; +int cmp(const void *a,const void *b) +{ + return *(int *)a-*(int *)b; +} +int MIN(int a,int b) +{ + return a>b?b:a; +} +int DIJ() +{ + int i,k; + k=1; + while(k) + { + E[k].flag=0; + for(i=1;i<=n;i++) + { + if(k==i || !E[i].hash) continue; + if(map[k][i]==1111111111) continue; + if(E[k].dis+map[k][i]t2) {t=t1;t1=t2;t2=t;} + for(i=0;i=0;i--) if(temp[i]==t2) {b=i;break;} + dir=1111111111; + len=1111111111; + for(i=a;i>=0;i--) + { + for(l=b;l=dir) continue; + for(j=1;j<=n;j++) + { + E[j].dis=1111111111; + E[j].flag=1; + if(temp[i]<=E[j].high && E[j].high<=temp[l]) E[j].hash=1; + else E[j].hash=0; + } + E[1].dis=0; + len=DIJ(); + if(len!=1111111111) + { + if(abs(temp[i]-temp[l]) +#include +#include +using namespace std; +int n,m,dir[5][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1}}; +char map[81][81]; +bool vis[81][81][5]; +struct node +{ + int x,y,t,cnt; + node(int _x=0,int _y=0,int _t=0,int _cnt=0):x(_x),y(_y),t(_t),cnt(_cnt){} + friend bool operator <(const node &a,const node &b) + { + return a.cnt>b.cnt; + } +}; +node f; +priority_queue Q; +int bfs() +{ + Q.push(f); + while(!Q.empty()) + { + node temp=Q.top(); + Q.pop(); + if(temp.x==0||temp.x==n-1||temp.y==0||temp.y==m-1) + return temp.cnt; + for(int k=1;k<5;k++) + { + int i=temp.x+dir[k][0]; + int j=temp.y+dir[k][1]; + if(!vis[i][j][k]&&map[i][j]!='#') + { + if(temp.t%2==k%2) + { + if(k==temp.t) + { + if(k%2==0&&map[temp.x+1][temp.y]=='#'&&map[temp.x-1][temp.y]=='#') + {vis[i][j][k]=1; Q.push(node(i,j,k,temp.cnt+1));} + if(k%2==1&&map[temp.x][temp.y+1]=='#'&&map[temp.x][temp.y-1]=='#') + {vis[i][j][k]=1; Q.push(node(i,j,k,temp.cnt+1));} + } + } + else {vis[i][j][k]=1;Q.push(node(i,j,k,temp.cnt+1));} + } + } + } + return -1; +} +int main() +{ + int cas,si,sj; + cin>>cas; + while(cas--) + { + while(!Q.empty()) + Q.pop(); + cin>>n>>m; + for(int i=0;i>map[i][j]; + if(map[i][j]=='@') + { + si=i;sj=j; + } + } + } + memset(vis,0,sizeof(vis)); + f.x=si;f.y=sj;f.t=-1;f.cnt=0; + cout< +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const int MAXN = 100010; +int T, n, d, x, y; +map > mymap; +LL solve() { + LL ans = 0; + for(map >::iterator it = mymap.begin(); it != mymap.end(); ++it) { + sort(it->second.begin(), it->second.end()); + for(int i = 0, j = 0, n = it->second.size(); i < n; ++i) { + while(j < n && it->second[i] + d > it->second[j]) ++j; + ans += j - i - 1; + } + } + int d2 = d * d; + for(map >::iterator it = mymap.begin(); it != mymap.end(); ++it) { + for(vector::iterator p = it->second.begin(); p != it->second.end(); ++p) { + for(int i = 1, t = d; i < d; ++i) { + while(i * i + t * t >= d2) --t; + map >::iterator nx = mymap.find(it->first + i); + if(nx != mymap.end()) { + ans += (upper_bound(nx->second.begin(), nx->second.end(), *p + t) - nx->second.begin()) - + (lower_bound(nx->second.begin(), nx->second.end(), *p - t) - nx->second.begin()); + } + } + } + } + return ans; +} +int main() { + scanf("%d", &T); + while(T--) { + mymap.clear(); + scanf("%d%d", &n, &d); + for(int i = 0; i < n; ++i) { + scanf("%d%d", &x, &y); + mymap[x].push_back(y); + } + printf("%I64d\n", solve()); + } +} diff --git a/HDOJ/2368_autoAC.cpp b/HDOJ/2368_autoAC.cpp new file mode 100644 index 0000000..c1a1a46 --- /dev/null +++ b/HDOJ/2368_autoAC.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +using namespace std; +int main() +{ + __int64 t=0; + __int64 r,w,l; + while(cin>>r) + { + if(r==0) break; + cin>>w>>l; + t++; + __int64 length_1,length_2; + length_1=w*w+l*l; + length_2=4*r*r; + if(length_1<=length_2) + printf("Pizza %I64d fits on the table.\n",t); + else + printf("Pizza %I64d does not fit on the table.\n",t); + } + return 0; +} diff --git a/HDOJ/2369_autoAC.cpp b/HDOJ/2369_autoAC.cpp new file mode 100644 index 0000000..34ca43d --- /dev/null +++ b/HDOJ/2369_autoAC.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; +long N,Ans; +long Hash[300]; +char St[1111111]; +void Solve(void); +int main() +{ + while(cin>>N) + { + if(!N) + break ; + getchar() ; + Solve() ; + } + return 0 ; +} +void Solve(void) +{ + long i=0,j=0,Now,end; + gets(St); + memset(Hash,0,sizeof(Hash)); + end=strlen(St); + for(Ans=0,Now=0;iN) + { + Hash[St[j]]--; + if(Hash[St[j]]==0) + Now--; + j++; + } + } + if(i-j+1>Ans) + Ans=i-j+1; + } + cout< +#include +#include +using namespace std ; +int fib[30] ,vis[30]; +void chart() +{ + fib[1] = 1 ; + fib[2] = 2 ; + for(int i = 3 ; i < 30 ; i++) + fib[i] = fib[i-1]+fib[i-2] ; +} +int main() +{ + int n ,m; + scanf("%d",&n) ; + chart() ; + while(n--) + { + scanf("%d",&m) ; + memset(vis,0,sizeof(vis)) ; + for(int i = 29 ; i >= 1 ; i--) + { + if(m <= 0) break ; + if(fib[i] <= m) + { + m -= fib[i] ; + vis[i] = 1 ; + } + } + int ans = 0 ; + for(int i = 2 ; i < 30 ; i++) + ans += vis[i]*fib[i-1] ; + printf("%d\n",ans) ; + } + return 0 ; +} diff --git a/HDOJ/2371_autoAC.cpp b/HDOJ/2371_autoAC.cpp new file mode 100644 index 0000000..3dbfcf3 --- /dev/null +++ b/HDOJ/2371_autoAC.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +using namespace std; +const int MAX=80+10; +int array[MAX][MAX],sum[MAX][MAX]; +char s[MAX]; +int n,m,a; +void MatrixMult(int a[MAX][MAX],int b[MAX][MAX]){ + int c[MAX][MAX]={0}; + for(int i=0;i>=1; + } +} +int main(){ + while(cin>>n>>m,n+m){ + memset(array,0,sizeof array); + for(int i=0;i>a; + array[a-1][i]=1; + } + getchar(); + gets(s); + MatrixPow(m); + for(int i=0;i +int main() +{ + while(1) + { + __int64 dp[105][105]={0};__int64 l; + int n,m,i,j,k,a[105]; + scanf("%d %d",&n,&m); + if(n==0&&m==0) + return 0; + for(i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + for(i=1;i<=n;i++) + { + dp[i][1]=1; + } + for(i=2;i<=n;i++) + { + for(j=2;j<=m;j++) + { + for(k=1;ka[k]) + { + dp[i][j]+=dp[k][j-1]; + } + } + } + } + l=0; + for(i=m;i<=n;i++) + { + l+=dp[i][m]; + } + printf("%I64d\n",l); + } + return 0; +} diff --git a/HDOJ/2374_autoAC.cpp b/HDOJ/2374_autoAC.cpp new file mode 100644 index 0000000..8145e1a --- /dev/null +++ b/HDOJ/2374_autoAC.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define M 505 +__int64 a[M],sum[M]; +int main() +{ + __int64 n,i,j,k,t; + while(~scanf("%I64d",&n)) + { + if(n==0) + break; + for(i=1;i<=n;i++) + { + scanf("%I64d",&a[i]); + } + memset(sum,0,sizeof(sum)); + for(i=n;i>=1;i--) + { + sum[i]=sum[i+1]+a[i]; + } + j=0; + for(i=n;i>=1;i--) + { + t=0; + for(k=n;k>i;k--) + { + t+=sum[k]; + } + t+=a[i]; + sum[k]=t; + j+=t; + } + printf("%I64d\n",j); + } + return 0; +} diff --git a/HDOJ/2375_autoAC.cpp b/HDOJ/2375_autoAC.cpp new file mode 100644 index 0000000..8b4723a --- /dev/null +++ b/HDOJ/2375_autoAC.cpp @@ -0,0 +1,80 @@ +#include +#include +using namespace std; +template +void out(T x, int n){ for (int i = 0; i < n; ++i) cout << x[i] << ' '; cout << endl; } +template +void out(T x, int n, int m){ for (int i = 0; i < n; ++i) out(x[i], m); cout << endl; } +#define OUT(x) (cout << #x << " = " << x << endl) +#define FOR(i, a, b) for(int i = (int)a; i < (int)b; ++i) +#define REP(i, b) FOR(i, 0, b) +#define FORD(i, a, b) for(int i = (int)a; i >= (int)b; --i) +#define MAXN 20 +#define MAXX (1<<16) +#define Inf 1e20 +#define IN(x, tmp) ((tmp>>x)&1) +double disCount[MAXN][MAXN]; +double price[MAXN], area[MAXN]; +double f[MAXX]; +double ans; +int n, m; +void input(){ +int t, xi; +double yi; +REP (i, n) +REP (j, n) +disCount[i][j] = 1.0; +REP (i, n) +{ +scanf("%lf %lf %d", &price[i], &area[i], &t); +while (t--) +{ +scanf("%d %lf", &xi, &yi); +disCount[i][xi-1] *= (100.0-yi)*0.01; +} +} +} +void solve(){ +double area0; +m = 1< cost) +{ +f[temp] = cost; +} +} +} +if (tmp) ans = min(ans, f[tmp]/area0); +} +printf("%.4lf\n", ans); +} +int main(){ +while (EOF != scanf("%d", &n)) +{ +if (0 == n) break; +input(); +solve(); +} +return 0; +} diff --git a/HDOJ/2376_autoAC.cpp b/HDOJ/2376_autoAC.cpp new file mode 100644 index 0000000..e396e1c --- /dev/null +++ b/HDOJ/2376_autoAC.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; +#define N 10010 +struct note +{ + int v,next,value; +}edge[N*2+10]; +int head[N]; +double dp[N]; +int sum[N]; +int n; +int kk; +int ss; +void add(int fa,int son,int value) +{ + edge[kk].v = son; + edge[kk].value = value; + edge[kk].next = head[fa]; + head[fa] = kk++; +} +void dfs(int root,int fa) +{ + sum[root] = 1; + for(int i = head[root];i != -1;i = edge[i].next) + { + int son = edge[i].v; + if(son == fa) continue; + dfs(son,root); + sum[root] += sum[son]; + ss += sum[son]*(n-sum[son]); + dp[root] += dp[son] + (double)sum[son]*(n-sum[son])*edge[i].value; + } +} +int main() +{ + int cas; + scanf("%d",&cas); + while(cas--) + { + ss = 0; + memset(head,-1,sizeof(head)); + memset(dp,0,sizeof(dp)); + kk = 1; + scanf("%d",&n); + int a,b,v; + for(int i = 1;i < n;i++) + { + scanf("%d%d%d",&a,&b,&v); + add(a,b,v); + add(b,a,v); + } + dfs(0,-1); + ss = n*(n-1) / 2; + printf("%llf\n",(double)dp[0] / ss); + } + return 0; +} diff --git a/HDOJ/2377_autoAC.cpp b/HDOJ/2377_autoAC.cpp new file mode 100644 index 0000000..8d07ff5 --- /dev/null +++ b/HDOJ/2377_autoAC.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include +using namespace std ; +#define MEM(a, v) memset (a, v, sizeof (a)) +#define INF (-1) +#define MAXN 10000 +struct EDGE { + int v, w, next ; +} ; +bool used[MAXN] ; +int nz, nr, edgeCnt ; +int first[MAXN], max_d[MAXN], dist[MAXN] ; +EDGE edge[20*MAXN] ; +void add (const int u, const int v, const int w) +{ + edge[edgeCnt].v = v ; + edge[edgeCnt].w = w ; + edge[edgeCnt].next = first[u] ; + first[u] = edgeCnt++ ; +} +void spfa (const int beg) +{ + int i, d, u, v ; + queue q ; + MEM (dist, INF) ; + MEM (used, 0) ; + if (max_d[beg] == INF) + max_d[beg] = 1 ; + dist[beg] = 1 ; + used[beg] = 1 ; + q.push (beg) ; + while (!q.empty ()) + { + u = q.front () ; + q.pop () ; + used[u] = 0 ; + for (i = first[u] ; i != -1 ; i = edge[i].next) + { + d = dist[u] + edge[i].w ; + v = edge[i].v ; + if (dist[v] == INF || dist[v] > d) + { + dist[v] = d ; + if (max_d[v] == INF || max_d[v] < dist[v]) + max_d[v] = dist[v] ; + if (!used[v]) + { + q.push (v) ; + used[v] = 1 ; + } + } + } + } +} +int main () +{ + int i, j ; + int u, v, w ; + int tcase, mz, minV, id ; + while (scanf ("%d", &tcase) != EOF) + { + while (tcase--) + { + MEM (first, -1) ; + MEM (max_d, INF) ; + edgeCnt = 0 ; + scanf ("%d%d", &nz, &nr) ; + for (i = 0 ; i < nz ; ++i) + { + scanf ("%d%d", &u, &mz) ; + while (mz--) + { + scanf ("%d", &v) ; + add (v, u, 1) ; + add (u, v, 1) ; + } + } + while (nr--) + { + scanf ("%d", &v) ; + for (i = 0 ; i < v ; ++i) + { + scanf ("%d", &u) ; + spfa (u) ; + } + } + minV = INF ; + id = -1 ; + for (i = 0 ; i < MAXN ; ++i) + if (max_d[i] != INF) + { + if (minV == INF || minV > max_d[i]) + { + minV = max_d[i] ; + id = i ; + } + } + printf ("%d %d\n", minV, id) ; + } + } + return 0 ; +} diff --git a/HDOJ/2378_autoAC.cpp b/HDOJ/2378_autoAC.cpp new file mode 100644 index 0000000..125ca8c --- /dev/null +++ b/HDOJ/2378_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +using namespace std; +const double eps = 1e-7; +int cases, m, c, gg; +double des, xs; +bool flag; +int gcd(int a, int b) { + if (b == 0) return a; else return gcd(b, a%b); +} +double abs(double x) { + if (x < 0) return -x; else return x; +} +int main() { + scanf("%d", &cases); + while (cases--) { + scanf("%lf", &des); + des = 4*des; + xs = des-int(des); + flag = true;if (abs(xs)>eps) flag = false; + scanf("%d", &m); + for (int i = 0; i < m; i++) { + scanf("%d", &c); + if (!i) gg = c; else gg = gcd(c, gg); + } + while ((gg&1)==0) gg>>=1; + if (int(des)%gg!=0) flag = false; + if (flag) puts("yes"); else puts("no"); + } + return 0; +} diff --git a/HDOJ/2379_autoAC.cpp b/HDOJ/2379_autoAC.cpp new file mode 100644 index 0000000..2cb76db --- /dev/null +++ b/HDOJ/2379_autoAC.cpp @@ -0,0 +1,44 @@ +#include +#include +long long a[20][60]; +int len[15]; +long long dfs(int n,int k) +{ + if(n==0&&k!=0) + return 0; + if(k<0||n<0) + return 0; + if(n==0&&k==0) + return 1; + if(a[n][k]) + return a[n][k]; + for(int i=3; i<=10; i++) + if(len[i]) + a[n][k]+=len[i]*dfs(n-1,k-i); + return a[n][k]; +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int m,n,q; + char c[20]; + scanf("%d%d%d",&m,&n,&q); + memset(len,0,sizeof(len)); + for(int i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define out(X) cerr << #X << ": " << (X) << endl +#define SZ(X) ((int)(X.size())) +#define LENGTH(X) ((int)(X.length())) +#define REP(I,N) for (int I = 0; I < (N); ++I) +#define FOR(I,L,H) for (int I = (L); I < (H); ++I) +#define MP(X,Y) make_pair((X),(Y)) +#define PB push_back +#define ALL(X) X.begin(), X.end() +template inline bool checkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } +template inline bool checkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } +typedef long long lint; +const double EPS = 1e-9; +int sgn(const double &x) {return (int)((x > EPS) - (x < -EPS));} +int T,N; +double tot,p; +vector bef,aft,init; +int check(const double &mid) { + bef.clear(); + aft.clear(); + for(int i = 0 ; i < N ; i++) { + bef.push_back(init[i]); + } + if (sgn(mid) != 0) bef.push_back(mid); + while(SZ(bef) > 1) { + sort(ALL(bef)); + aft.clear(); + aft.push_back((bef[0] + bef[1]) / (1 - p)); + for(int i = 2 ; i < SZ(bef) ; i++) { + aft.push_back(bef[i]); + } + bef = aft; + } + if (sgn(bef[0] - tot) > 0) { + return -1; + } + return 1; +} +int main() { + scanf("%d",&T); + while(scanf("%lf%lf%d",&tot,&p,&N) == 3) { + p /= 100.0; + init.clear(); + for(int i = 0 ; i < N ; i++) { + double w; + scanf("%lf",&w); + init.push_back(w); + } + double ans = -1; + double l = 0.0 ,r = tot,mid; + for(int cnt = 0 ; cnt < 200 ; cnt++){ + mid = (l + r) / 2; + if (check(mid) != -1) { + l = mid + EPS; + ans = mid; + } + else r = mid - EPS; + } + if (sgn(ans + 1) <= 0) { + printf("%d\n",-1); + continue; + } + printf("%.4f\n", ans); + } + return 0; +} diff --git a/HDOJ/2382_autoAC.cpp b/HDOJ/2382_autoAC.cpp new file mode 100644 index 0000000..32bbcd3 --- /dev/null +++ b/HDOJ/2382_autoAC.cpp @@ -0,0 +1,63 @@ +#include +#include +#define N 110 +#define eps 1e-8 +char map[N][N]; +double visit[N][N]; +double deal ( int c, int n, int m ) { + int i, j; + double ans = 0; + memset ( visit, 0, sizeof ( visit ) ); + visit[ 0 ][ c ] = 1; + for ( i = 0 ; i < n - 1 ; ++i ) { + for ( j = 0 ; j < m ; ++j ) { + if ( visit[ i ][ j ] > eps ) { + if ( map[ i ][ j ] != '.' ) { + ans += visit[ i ][ j ] * ( map[ i ][ j ] - '0' ); + } + else { + if ( map[ i + 1 ][ j ] != '*' ) { + visit[ i + 1 ][ j ] += visit[ i ][ j ]; + } + else { + if ( j > 0 ) { + visit[ i + 1 ][ j - 1 ] += visit[ i ][ j ] / 2; + } + if ( j < m - 1 ) { + visit[ i + 1 ][ j + 1 ] += visit[ i ][ j ] / 2; + } + } + } + } + } + } + for ( i = 0 ; i < m ; ++i ) { if ( map[ n - 1 ][ i ] != '*' && map[ n - 1 ][ i ] != '.' ) { + ans += visit[ n - 1 ][ i ] * ( map[ n - 1 ][ i ] - '0' ); + } + } + return ans; +} +int main () { + int i, n, m, t; + double ans, temp; + scanf ( "%d", &t ); + while ( t-- ) { + scanf ( "%d%d", &n, &m ); + getchar(); + for ( i = 0 ; i < n ; ++i ) { + gets( map[ i ] ); + if ( map[ i ][ 0 ] == '\0' ) --i; + } + ans = 0; + for ( i = 0 ; i < m ; ++i ) { + if ( map[ 0 ][ i ] != '.' ) { + if ( map[ 0 ][ i ] == '*' ) temp = 0; + else temp = map[ 0 ][ i ] - '0'; + } + else temp = deal( i, n, m ); + if ( temp - ans > eps ) ans = temp; + } + printf ( "%.6lf\n", ans ); + } + return 0; +} diff --git a/HDOJ/2383_autoAC.cpp b/HDOJ/2383_autoAC.cpp new file mode 100644 index 0000000..58ead88 --- /dev/null +++ b/HDOJ/2383_autoAC.cpp @@ -0,0 +1,201 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define SZ(v) ((int)(v).size()) +#define SQR(x) ((x) * (x)) +const int maxint = -1u>>1; +const int maxn = 100 + 4; +const double eps = 1e-9; +const double inf = 1e10; +int sgn(double x) { + return (x > eps) - (x < -eps); +} +struct P { + double x, y; + P() {} + P(double _x, double _y): x(_x), y(_y) {} + bool operator != (const P &a) const { + return sgn(x - a.x) || sgn(y - a.y); + } + P operator + (const P &a) const { + return P(x + a.x, y + a.y); + } + P operator - (const P &a) const { + return P(x - a.x, y - a.y); + } + P operator * (const double &m) const { + return P(x * m, y * m); + } + double length() const { + return sqrt(SQR(x) + SQR(y)); + } + P set(const double &m) const { + double len = length(); + return P(x * m / len, y * m / len); + } + P turn_left() const { + return P(-y, x); + } + double dot(const P &a, const P &b) const { + return (a.x - x) * (b.x - x) + (a.y - y) * (b.y - y); + } + double cross(const P &a, const P &b) const { + return (a.x - x) * (b.y - y) - (a.y - y) * (b.x - x); + } + double dist(const P &a) const { + return sqrt(sqrdist(a)); + } + double sqrdist(const P &a) const { + return SQR(a.x - x) + SQR(a.y - y); + } + void input() { + scanf("%lf%lf", &x, &y); + } + void output() const { + printf("%lf %lf\n", x, y); + } +}; +struct node { + int x; + double val; + node() {} + node(int _x, double _val): x(_x), val(_val) {} + bool operator < (const node &a) const { + return val > a.val; + } +}; +int n, m; +double r; +P cen[maxn]; +vector

rec; +vector > > v; +vector dist; +vector used; +bool in_cir(const P &p) { + for (int i = 0; i < n; ++i) { + if (sgn(cen[i].dist(p) - r) < 0) return true; + } + return false; +} +void cir_cross(const P &c1, const P &c2) { + if (sgn(c1.dist(c2) - r * 2) > 0) return ; + P mid = (c1 + c2) * 0.5; + P dir = (c2 - c1).turn_left().set(sqrt(SQR(r) - c1.sqrdist(c2) / 4)); + P p1 = mid + dir, p2 = mid - dir; + if (!in_cir(p1)) { + rec.push_back(p1); + } + if (p1 != p2 && !in_cir(p2)) { + rec.push_back(p2); + } +} +void spfa(int s) { + dist.resize(m); + used.resize(m); + for (int i = 0; i < m; ++i) { + dist[i] = inf; + used[i] = false; + } + priority_queue que; + que.push(node(s, 0)); + dist[s] = 0; + used[s] = false; + while (!que.empty()) { + node top = que.top(); + que.pop(); + used[top.x] = false; + for (int i = 0; i < (int)v[top.x].size(); ++i) { + int x = v[top.x][i].first; + if (dist[x] > dist[top.x] + v[top.x][i].second) { + dist[x] = dist[top.x] + v[top.x][i].second; + if (!used[x]) { + used[x] = true; + que.push(node(x, dist[x])); + } + } + } + } +} +int calc_init(const P &pt1) { + int res = 0; + for (int i = 0; i < n; ++i) { + if (sgn(pt1.dist(cen[i]) - r) <= 0) ++res; + } + return res; +} +void line_cross_cir(vector > &s, const P &p1, const P &p2, const P &c) { + double d = fabs(p1.cross(p2, c)) / p1.dist(p2); + if (sgn(d - r) > 0) return; + double s1 = sqrt(p1.sqrdist(c) - SQR(d)); + if (sgn(p1.dot(c, p2)) < 0) s1 = -s1; + double s2 = sqrt(SQR(r) - SQR(d)); + P pt1 = p1 + (p2 - p1).set(s1 - s2), pt2 = p1 + (p2 - p1).set(s1 + s2); + if (sgn(pt1.dot(p1, p2)) < 0) { + s.push_back(make_pair(pt1.dist(p1), 1)); + } + if (sgn(pt2.dot(p1, p2)) < 0) { + s.push_back(make_pair(pt2.dist(p1), -1)); + } +} +bool cmp(const pair &x1, const pair &x2) { + if (sgn(x1.first - x2.first) != 0) return x1.first < x2.first; + return x1.second > x2.second; +} +bool ok_line(const P &p1, const P &p2) { + P pt1 = p1 + (p2 - p1)*0.001; + vector > s; + for (int i = 0; i < n; ++i) { + line_cross_cir(s, pt1, p2, cen[i]); + } + sort(s.begin(), s.end()); + int cnt = calc_init(pt1); + if (cnt == 0) return false; + for (int i = 0; i < (int)s.size(); ++i) { + cnt += s[i].second; + if (cnt == 0) return false; + } + return true; +} +int main() { + int t; + scanf("%d", &t); + while (t--) { + scanf("%lf%d", &r, &n); + P st, ed; + st.input(); + ed.input(); + for (int i = 0; i < n; ++i) { + cen[i].input(); + } + rec.clear(); + rec.push_back(st); + rec.push_back(ed); + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + cir_cross(cen[i], cen[j]); + } + } + m = rec.size(); + v.resize(m); + for (int i = 0; i < m; ++i) v[i].clear(); + for (int i = 0; i < m; ++i) { + for (int j = 0; j < i; ++j) { + if (ok_line(rec[i], rec[j])) { + v[i].push_back(make_pair(j, rec[i].dist(rec[j]))); + v[j].push_back(make_pair(i, rec[i].dist(rec[j]))); + } + } + } + spfa(0); + if (sgn(dist[1] - inf) == 0) printf("-1\n"); + else printf("%.12lf\n", dist[1]); + } + return 0; +} diff --git a/HDOJ/2384_autoAC.cpp b/HDOJ/2384_autoAC.cpp new file mode 100644 index 0000000..a1bc7b2 --- /dev/null +++ b/HDOJ/2384_autoAC.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int cas,t,r; +struct Team +{ + char name[25]; + int pid[15]; + int pid_fs[15]; + int icount; + int tol_time; + int a[15],fa[15]; +} team[55]; +int findTeam(char xx[]) +{ + for(int i=0; iicount != d->icount) + return d->icount - c->icount; + else if(c->tol_time!=d->tol_time) + return c->tol_time - d->tol_time; + else + { + for(int i=c->icount; i>=1; i--) + { + if(c->a[i] != d->a[i]) + return c->a[i] - d->a[i]; + else if(c->fa[i] != d->fa[i]) + return d->fa[i] - c->fa[i]; + } + } + return strcmp(c->name,d->name); +} +void print() +{ + printf("1 %s %d %d\n",team[0].name,team[0].icount,team[0].tol_time); + int c1=1,c2=1; + for(int i=1; i=1; j--) + { + if(team[i-1].a[j]==team[i].a[j]) + { + if(team[i-1].fa[j]==team[i].fa[j]) + { + ; + } + else + { + c1=c1+c2; + printf("%d %s %d %d\n",c1,team[i].name,team[i].icount,team[i].tol_time); + c2=1; + goto to; + } + } + else + { + c1=c1+c2; + printf("%d %s %d %d\n",c1,team[i].name,team[i].icount,team[i].tol_time); + c2=1; + goto to; + } + } + c2++; + printf("%d %s %d %d\n",c1,team[i].name,team[i].icount,team[i].tol_time); +to: + ; + } + else + { + c1=c1+c2; + printf("%d %s %d %d\n",c1,team[i].name,team[i].icount,team[i].tol_time); + c2=1; + } + } + else + { + c1=c1+c2; + printf("%d %s %d %d\n",c1,team[i].name,team[i].icount,team[i].tol_time); + c2=1; + } + } +} +int main() +{ + scanf("%d",&cas); + int ti,index,id; + char name[25],res[15],ch; + while(cas--) + { + scanf("%d %d",&t,&r); + for(int i=0; i +#include +#include +#include +using namespace std; +const int maxn=100000+10; +struct N +{ + int x,p,m; + bool operator<(const N &a) const + { + return p q; + N a; + while(t--) + { + while(!q.empty()) q.pop(); + scanf("%d",&n); + for(i=0;i=0;i--) + { + q.push(node[i]); + sum=node[i].x; + while(!q.empty()&&sum!=0) + { + a=q.top(); + q.pop(); + if(a.m>=sum) + { + a.m-=sum; + p+=a.p*sum; + sum=0; + } + else + { + sum-=a.m; + p+=a.p*a.m; + a.m=0; + } + if(a.m!=0) + q.push(a); + } + if(q.empty()) + sum=0; + } + printf("%d\n",p); + } + return 0; +} diff --git a/HDOJ/2387_autoAC.cpp b/HDOJ/2387_autoAC.cpp new file mode 100644 index 0000000..68d492c --- /dev/null +++ b/HDOJ/2387_autoAC.cpp @@ -0,0 +1,86 @@ +#include +#include +int p[120][5], now, he[6] = {1, 1, 2, 6, 24, 120}; +int n, m, **map, **tmp, **ans; +int** dm(int n, int m) { + int i; + int *t = (int *)malloc(sizeof(int) * n * m); + int **pp = (int **)malloc(sizeof(int *) * n); + for(i = 0; i < n; ++i) { + pp[i] = t + i * m; + } + return pp; +} +void deld(int ** pp) { + free(*pp); + free(pp); +} +void p_f(int x) { + int i, j, bef = now - 1; + if(x == 0) return; + for(i = 0; i < x; ++i) { + for(j = 0; j < 5; ++j) p[now][j] = p[bef][j]; + p[now][i] = p[bef][x]; + p[now][x] = p[bef][i]; + now++; + for(j = 1; j < x; ++j) p_f(j); + } + return; +} +void cmp() { + int i, k = 0; + for(i = 0; i < n * m; ++i) { + if(*(*ans + i) > *(*tmp + i)) { + k = 1; break; + } + if(*(*ans + i) < *(*tmp + i)) break; + } + if(k == 1) { + for(i = 0; i < n * m; ++i) { + *(*ans + i) = *(*tmp + i); + } + } +} +void bl(int a, int b) { + int i, j; + for(i = 0; i < n; ++i) { + for(j = 0; j < m; ++j) { + tmp[p[a][i]][p[b][j]] = map[i][j]; + } + } + cmp(); +} +int main() { + int i, j, t, tt; + p[0][0] = 0; p[0][1] = 1; p[0][2] = 2; p[0][3] = 3; p[0][4] = 4; + now = 1; + for(i = 1; i < 5; ++i) p_f(i); + scanf("%d", &t); + for(tt = 0; tt < t; ++tt) { + scanf("%d %d", &n, &m); + map = dm(n, m); + tmp = dm(n, m); + ans = dm(n, m); + for(i = 0; i < n; ++i) { + for(j = 0; j < m; ++j) { + scanf("%d", &map[i][j]); + ans[i][j] = map[i][j]; + } + } + for(i = 0; i < he[n]; ++i) { + for(j = 0; j < he[m]; ++j) { + bl(i, j); + } + } + printf("Scenario #%d:\n", tt + 1); + for(i = 0; i < n * m; ++i) { + printf("%d", *(*ans + i)); + if(i != (n * m - 1)) printf(" "); + } + printf("\n\n"); + deld(ans); + deld(map); + deld(tmp); + } + return 0; +} diff --git a/HDOJ/2388_autoAC.cpp b/HDOJ/2388_autoAC.cpp new file mode 100644 index 0000000..538f3f9 --- /dev/null +++ b/HDOJ/2388_autoAC.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +using namespace std; +const int N = 10010; +struct node +{ + int v; + int w; + node(){}; + node(int x,int y):v(x),w(y){} + bool operator <(const node &cp)const + { + return w > cp.w; + } +}; +vectormap[N]; +priority_queueque; +int dist[N],visit[N]; +int n,m; +void input() +{ + scanf("%d%d",&n,&m); + for(int i = 0;i <= n;i ++) + map[i].clear(); + for(int i = 0;i < n;i ++) + scanf("%d",&dist[i]); + int u,v,a,b; + while(m --) + { + scanf("%d%d%d%d",&u,&v,&a,&b); + map[u].push_back(node(v,a)); + map[v].push_back(node(u,b)); + } + for(int i = 0;i < n;i ++) + visit[i] = 0; + while(!que.empty()) + que.pop(); + for(int i = 0;i < n;i ++) + que.push(node(i,dist[i])); +} +void solve() +{ + int x,y; + while(!que.empty()) + { + node tmp = que.top(); + que.pop(); + if(visit[tmp.v]) + continue; + visit[tmp.v] = 1; + dist[tmp.v] = tmp.w; + for(int i = 0;i < map[tmp.v].size();i ++) + { + x = map[tmp.v][i].v; + y = map[tmp.v][i].w; + if(dist[x] > tmp.w+y) + { + dist[x] = tmp.w+y; + que.push(node(x,dist[x])); + } + } + } +} +int main() +{ + int t,cas=0; + scanf("%d",&t); + while(t --) + { + cas ++; + input(); + solve(); + int ans = 0; + for(int i = 1;i < n;i ++) + { + if(dist[ans] < dist[i]) + ans = i; + } + printf("Scenario #%d:\n",cas); + printf("%d\n\n",ans); + } + return 0; +} diff --git a/HDOJ/2389_autoAC.cpp b/HDOJ/2389_autoAC.cpp new file mode 100644 index 0000000..16f2c8e --- /dev/null +++ b/HDOJ/2389_autoAC.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +using namespace std; +vector g[4000]; +struct node +{ + int x,y,s; +}PEO[4000]; +int mx[4000],my[4000],n1,n2,dx[4000],dy[4000]; +bool use[4000]; +bool find(int u) +{ + for(int i=0;i q; + memset(dx,0,sizeof(dx)); + memset(dy,0,sizeof(dy)); + for(int i=1;i<=n1;i++) + { + if(!mx[i]) q.push(i); + } + while(!q.empty()) + { + int u=q.front(); q.pop(); + for(int i=0;i=dist1) + { + g[j].push_back(i); + } + } + } + printf("Scenario #%d:\n%d\n\n",cas++,HKmatch()); + } +} diff --git a/HDOJ/2390_autoAC.cpp b/HDOJ/2390_autoAC.cpp new file mode 100644 index 0000000..ac92939 --- /dev/null +++ b/HDOJ/2390_autoAC.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const int maxn=50005; +int m,t; +struct node +{ + int day; + int start; + int end; +} p[maxn]; +int cmp(node a,node b) +{ + if(a.day==b.day) + { + return a.end=p[temp].end) + { + temp=i; + sum++; + } + if(p[i].day!=p[k].day) + { + k=i; + temp=i; + sum++; + } + } + printf("Scenario #"); + printf("%d:\n",++tcase); + printf("%d\n\n",sum); + } + return 0; +} diff --git a/HDOJ/2391_autoAC.cpp b/HDOJ/2391_autoAC.cpp new file mode 100644 index 0000000..05c29c6 --- /dev/null +++ b/HDOJ/2391_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int maxn=1001; +int va[maxn][maxn]; +int dp[maxn][maxn]; +int maxx(int a,int b,int c){ + int sum=a>b?a:b; + sum=sum>c?sum:c; + return sum; +} +int main() +{ + int t,r,c; + scanf("%d",&t); + for(int k=1;k<=t;k++) + { + scanf("%d%d",&r,&c); + memset(va,0,sizeof(va)); + memset(dp,0,sizeof(dp)); + for(int i=1;i<=r;i++) + for(int j=1;j<=c;j++) + scanf("%d",&va[i][j]); + for(int i=1;i<=r;i++) + for(int j=1;j<=c;j++) + { + dp[i][j]=maxx(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+va[i][j]; + } + cout<<"Scenario #"< +int main() +{ + int i,n,a,b,c; + scanf("%d",&n); + for(i=1;i<=n;i++) + { + scanf("%d%d%d",&a,&b,&c); + if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b) + printf("Scenario #%d:\nyes\n\n",i); + else + printf("Scenario #%d:\nno\n\n",i); + } + return 0; +} diff --git a/HDOJ/2394_autoAC.cpp b/HDOJ/2394_autoAC.cpp new file mode 100644 index 0000000..49d141c --- /dev/null +++ b/HDOJ/2394_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef __int64 ll; +bool solve( ll a, ll b, ll c, int k ) +{ + if( k == 0 ) + { + return true; + } + if( a % 2 == 0 ) + { + if( b % 2 == 0 ) + { + if( c % 2 == 0 ) + { + return solve( a / 2, b / 2, c / 2, k - 1 ); + } + else + { + return false; + } + } + else + { + if( c % 2 == 0 ) + { + return solve( 2 * a, b, c / 2, k - 1 ); + } + else + { + return solve( 4 * a, 4 * a + 2 * b, a + b + c, k -1 ); + } + } + } + else + { + if( b % 2 == 0 ) + { + if( c % 2 == 0 ) + { + return solve( 2 * a, b, c / 2, k - 1 ); + } + else + { + return solve( 4 * a, 4 * a + 2 * b, a + b + c, k - 1 ); + } + } + else + { + if( c % 2 == 0 ) + { + return solve( 2 * a, b, c / 2, k - 1 ) || + solve( 4 * a, 4 * a + 2 * b, a + b + c, k - 1 ); + } + else + { + return false; + } + } + } +} +int main() +{ + int n; + ll a, b, c; + scanf("%d",&n); + while( n-- ) + { + scanf("%I64d%I64d%I64d",&a,&b,&c); + if( solve( a, b, c, 32 ) )printf("YES\n"); + else printf("NO\n"); + } + return 0; +} diff --git a/HDOJ/2395_autoAC.cpp b/HDOJ/2395_autoAC.cpp new file mode 100644 index 0000000..58f8a28 --- /dev/null +++ b/HDOJ/2395_autoAC.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +int main() +{ + int i,t; + char t1[10],t2[10]; + int a1,b1,c1,a2,b2,c2; + char s1[3],s2[3]; + int p; + while(scanf("%d",&t)!=EOF) + { + for(i=0;i +#include +int d[105][20005]; +int main() +{ + int t,c=1; + scanf("%d",&t); + while(t--) + { + memset(d,0,sizeof(d)); + int n,ans=0,m,i,j,k,p=0,x=0,a[105]; + scanf("%d%d",&n,&m); + for(i=0;ia[p]) + p=i; + } + x=3*a[p]*m; + d[0][0]=1; + for(i=0;i +int main() +{ + double i; + double a,r,b; + while(scanf("%lf%lf%lf",&a,&r,&b)!=EOF) + { + for(i=1;;i++) + { + a=a+a*r*(1.0/100); + if(a>=b) break; + } + printf("%.0lf\n",i); + } + return 0; +} diff --git a/HDOJ/2399_autoAC.cpp b/HDOJ/2399_autoAC.cpp new file mode 100644 index 0000000..c4a919b --- /dev/null +++ b/HDOJ/2399_autoAC.cpp @@ -0,0 +1,50 @@ +#include +#include +int main() +{ + char s[1000]; + int i,num,flag; + double t; + while(gets(s)) + { + t=0; + num=0; + i=0; + flag=0; + while(s[i]) + { + switch(s[i++]) + { + case 'A': + t+=4.0; + num++; + continue; + case 'B': + t+=3.0; + num++; + continue; + case 'C': + t+=2.0; + num++; + continue; + case 'D': + t+=1.0; + num++; + continue; + case 'F': + num++; + continue; + case ' ': + continue; + default: + flag=1; + break; + } + } + if(flag==1) + printf("Unknown letter grade in input\n"); + else + printf("%.2lf\n",t/num); + } + return 0; +}