diff --git a/HDOJ/2901_autoAC.cpp b/HDOJ/2901_autoAC.cpp new file mode 100644 index 0000000..8df9f1d --- /dev/null +++ b/HDOJ/2901_autoAC.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +using namespace std; +const int maxN=305; +const int maxM=35; +typedef double db; +const db eps=1e-12; +db dp[maxN][maxM]; +int pre[maxN][maxM]; +db cur[maxM][maxM]; +db Prev[maxM][maxM]; +int shot[500],N; +int inv[maxM]; +int main() +{ + int T;scanf("%d",&T); + while(T--) + { + scanf("%d",&N); + memset(shot,-1,sizeof(shot)); + for(int i=0;idp[i+1][k]) + { + pre[i+1][k]=j; + dp[i+1][k]=tmp; + } + } + } + } + db maxx=-1e200; + int idx=-1; + for(int i=0;imaxx) + { + maxx=dp[l][i]; + idx=i; + } + } + int ans[500]; + int mm=l; + while(mm) + { + ans[mm]=idx; + idx=pre[mm][idx]; + mm--; + } + for(int i=1;i<=l;++i) + printf("%c",inv[ans[i]]); + printf("\n"); + } + } +} diff --git a/HDOJ/2904_autoAC.cpp b/HDOJ/2904_autoAC.cpp new file mode 100644 index 0000000..8c8cedb --- /dev/null +++ b/HDOJ/2904_autoAC.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +using namespace std; +struct Edge +{ + int l,r,w; + bool operator<(const Edge &b)const + { + return w>b.w; + } +}; +Edge p[100005]; +int set[105]; +int m; +int map[105][105],w[105]; +int find(int x) +{ + if(x==set[x])return x; + return set[x]=find(set[x]); +} +int main() +{ + int T; + scanf("%d",&T); + while(T--) + { + scanf("%d",&m); + memset(map,0,sizeof(map)); + for(int i=0;i +#include +#include +using namespace std; +const int oo = 1000000000; +char s[10010], cards[2][50]; +int dp[10010], nc[2], value[300]; +void update(int& x, int y) +{ + if (y > x) x = y; +} +int lv(int u) +{ + int ret = 0; + for (int i = 0; i < nc[u]; ++i) ret += value[cards[u][i]]; + return ret; +} +int hv(int u) +{ + int ret = 0, x = 0; + for (int i = 0; i < nc[u]; ++i) + if (cards[u][i] == 'A') ++x, ret += 11; + else ret += value[cards[u][i]]; + while (ret > 21 && x > 0) ret -= 10, --x; + return ret; +} +void getCard(int u, int& cur) +{ + cards[u][nc[u]++] = s[cur++]; +} +int main() +{ + for (int i = '2'; i <= '9'; ++i) value[i] = i-'0'; + value['T'] = value['J'] = value['Q'] = value['K'] = 10; + value['A'] = 1; + int T, n, p, q, l[2]; + scanf("%d", &T); + while (T--) { + scanf("%d%d%d", &n, &p, &q); + int cur = 0; + while (cur < n) { + scanf("%s", s+1+cur); + cur += strlen(s+1+cur); + } + for (int i = 1; i <= n; ++i) dp[i] = -oo; + dp[0] = 0; + for (int i = 0; i < n; ++i) if(dp[i] != -oo) { + if (i+4 > n) { + update(dp[n], dp[i]); + continue; + } + int cur = i + 1; + nc[0] = nc[1] = 0; + getCard(0, cur); + getCard(1, cur); + getCard(0, cur); + getCard(1, cur); + l[0] = value[cards[0][0]]+value[cards[0][1]]; + while(1) { + if (l[0] > 21) { + update(dp[cur-1], dp[i] - p); + break; + } + int pre = cur; + nc[1] = 2; + while (pre <= n && hv(1) < 17) getCard(1, pre); + if (hv(1) < 17) update(dp[n], dp[i]); + else { + int h[2] = {hv(0), hv(1)}; + if (lv(1) > 21) update(dp[pre-1], dp[i] + q); + else if (h[0] > h[1]) update(dp[pre-1], dp[i] + q); + else if (h[0] < h[1]) update(dp[pre-1], dp[i] - p); + else update(dp[pre-1], dp[i]); + } + if (cur <= n) { + l[0] += value[s[cur]]; + getCard(0, cur); + } + else { + update(dp[n], dp[i]); + break; + } + } + } + printf("%d\n", dp[n]); + } + return 0; +} diff --git a/HDOJ/2906_autoAC.cpp b/HDOJ/2906_autoAC.cpp new file mode 100644 index 0000000..79188da --- /dev/null +++ b/HDOJ/2906_autoAC.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +using namespace std; +typedef double db; +const db PI = acos(-1.0); +const db eps = 1e-15; +const db oo = 1e100; +struct pt{ + db x,y; + pt(){}pt(db x,db y):x(x),y(y){} + pt operator -(pt a){return pt(x-a.x,y-a.y);} + db operator *(pt a){return x*a.x+y*a.y;} + db operator &(pt a){return x*a.y-y*a.x;} + db len(){return sqrt(x*x+y*y);} + db ang(){return atan2(y,x);} + void getP(){scanf("%lf%lf",&x,&y);} +}; +struct circle{ + pt o; + db r,a,l; + void getC(){o.getP();l = o.len();a = o.ang();scanf("%lf",&r);} +}; +struct box{ + db s,d,c; +}; +const int MaxC = 1024; +circle cl[MaxC]; +box fm[MaxC][MaxC]; +db dis[MaxC],w[MaxC]; +bool U[MaxC]; +int sign(db x){return (x > eps)-(x < -eps);} +db calTime(int x,int y,db ct){ + box &cb = fm[x][y]; + if (cb.c > oo / 2) + return oo; + if (sign(cb.c) == 0) + return ct; + db ft = cb.s+floor((ct-cb.s) / cb.c-1.0)*cb.c; + while (sign(ft-ct) < 0 && sign(ct-ft-cb.d) > 0) + ft += cb.c; + return max(ft,ct); +} +int main(){ + int tCase; + scanf("%d",&tCase); + for (int ct = 1;ct <= tCase;ct++){ + int N; + scanf("%d",&N); + for (int i = 0;i < N;i++){ + cl[i].getC(); + scanf("%lf",&w[i]); + } + for (int i = 0;i < N;i++) + for (int j = 0;j < N;j++)if (i != j){ + box &cb = fm[i][j]; + db a = cl[i].l,b = cl[j].l,c = cl[j].r; + if (sign(c-fabs(a-b)) < 0){ + cb.c = oo; + continue; + } + if (sign(c-a-b) >= 0){ + cb.c = 0.0; + continue; + } + db cd = (a*a+b*b-c*c) / (2.0*a*b); + if (sign(cd-1.0) >= 0) cd = 1.0; + if (sign(cd+1.0) <= 0) cd = -1.0; + db da = acos(cd); + db cw = w[i]-w[j]; + db ca = cl[j].a-cl[i].a; + while (sign(ca+PI) < 0) ca += PI*2; + if (sign(cw) == 0){ + if (sign(fabs(ca)-da) <= 0) + cb.c = 0.0; + else + cb.c = oo; + continue; + } + cb.c = PI*2.0 / fabs(cw); + cb.d = da*2.0 / fabs(cw); + cb.s = ca / cw-cb.d*0.5; + } + memset(U,0,sizeof(U[0])*N); + dis[0] = 0.0; + for (int j = 1;j < N;j++) + dis[j] = calTime(0,j,0.0); + U[0] = true; + for (int i = 1;i < N;i++){ + int mj = -1; + db md = oo; + for (int j = 0;j < N;j++) + if (!U[j] && dis[j] < md) + md = dis[mj = j]; + if (mj == N-1) break; + U[mj] = true; + for (int j = 0;j < N;j++) + if (!U[j]){ + db nd = calTime(mj,j,md); + dis[j] = min(nd,dis[j]); + } + } + if (dis[N-1] > oo / 2) while(1); + printf("%.f\n",ceil(dis[N-1])); + } + return 0; +} diff --git a/HDOJ/2907_autoAC.cpp b/HDOJ/2907_autoAC.cpp new file mode 100644 index 0000000..279c985 --- /dev/null +++ b/HDOJ/2907_autoAC.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +using namespace std; +struct aa +{ + int x,y; + int t; +}a1[105],a2[105]; +bool camp(aa a,aa b) +{ + return a.y(B.y-A.y)*(C.x-A.x); +} +int main () +{ + int i,t,mt,n,s,tt,p,q; + bool mark[105][105]; + scanf("%d",&tt); + while(tt--) + { + scanf("%d%d%d",&p,&q,&n); + memset(mark,0,sizeof(mark)); + for(i=1;i=1;i--) + { + while(t!=mt&&!fx(a2[t-1],a2[t],a1[i])) + t--; + a2[++t]=a1[i]; + } + for(s=0,t--,i=1;i0) + printf("%d\n",ans); + else + printf("0\n"); + } + return 0; +} diff --git a/HDOJ/2908_autoAC.cpp b/HDOJ/2908_autoAC.cpp new file mode 100644 index 0000000..47a274a --- /dev/null +++ b/HDOJ/2908_autoAC.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include +using namespace std; +int n, w; +int data[1000]; +int interval [1000]; +void solve() +{ + int k = 0; + double sum = 0.01; + sort(data + 1, data + n + 1); + while(!(data[n] >= k*w && data[n] <= (k+1)*w-1)) + { + k++; + } + memset(interval, 0, sizeof(interval)); + for(int i = 1; i <= n; i++) + { + int kk = 0; + while(kk <= k) + { + if(data[i] >= kk*w && data[i] <= (kk+1)*w-1) + { + interval[kk] ++; + break; + } + else + { + kk++; + } + } + } + int max = 0; + for(int i = 0; i <= k; i++) + { + if(max < interval[i]) + { + max = interval[i]; + } + } + for(int i = 0; i <= k; i++) + { + sum += ((double)interval[i]) / ((double)max) * (k-i) / k; + } + printf("%.6lf\n", sum); +} +int main() +{ + while(1) + { + scanf("%d%d", &n, &w); + if(n == 0 && w == 0) + { + break; + } + else + { + for(int i = 1; i <= n; i++) + { + scanf("%d", &data[i]); + } + } + solve(); + } + return 0; +} diff --git a/HDOJ/2909_autoAC.cpp b/HDOJ/2909_autoAC.cpp new file mode 100644 index 0000000..6ea0f27 --- /dev/null +++ b/HDOJ/2909_autoAC.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; +int num[2][100000]; +int main() +{ + int n,m,k; + while(scanf("%d%d%d",&n,&m,&k)!=EOF&&(n||m||k)) + { + memset(num,0,sizeof(num)); + for(int i=1; i<=m; i++) + num[1][i]=1; + for(int i=2; i<=n; i++) + { + for(int j=1; j<=i*m; j++) + for(int l=1; l<=m; l++) + num[i%2][j+l]+=num[(i-1)%2][j]; + memset(num[(i-1)%2],0,sizeof(num[(i-1)%2])); + } + double res=0.0; + int i,j; + for(i=1; i<=k+1; i++) + res+=num[n%2][i]; + for(j=2;i<=n*m; i++,j++) + res+=num[n%2][i]*j; + int count=1; + for(int i=1;i<=n;i++) + count*=m; + res/=count; + printf("%.8lf\n",res); + } + return 0; +} diff --git a/HDOJ/2910_autoAC.cpp b/HDOJ/2910_autoAC.cpp new file mode 100644 index 0000000..6019806 --- /dev/null +++ b/HDOJ/2910_autoAC.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +using namespace std; +int st[20][50000]; +int a[20][5]; +int s[20]; +int ans,ans1,ans2; +void work(int h,int m,int s,int x) +{ + int i,j,k,l; + if(!(m>=(h%5)*12&&m<(h%5+1)*12)) return; + st[x][h/5*3600+m*60+s]=1; +} +int main() +{ + int n,i,j,k,l,m,q,w,e,r,t,num; + while (scanf("%d",&n)!=EOF) + { + memset(st,0,sizeof(st)); + if (n==0) break; + for (i=1;i<=n;i++) + { + scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]); + for (j=1;j<=60;j++) + { + work(a[i][1],a[i][2],a[i][3],i); + work(a[i][1],a[i][3],a[i][2],i); + work(a[i][2],a[i][1],a[i][3],i); + work(a[i][2],a[i][3],a[i][1],i); + work(a[i][3],a[i][2],a[i][1],i); + work(a[i][3],a[i][1],a[i][2],i); + a[i][1]=(a[i][1]+1)%60; + a[i][2]=(a[i][2]+1)%60; + a[i][3]=(a[i][3]+1)%60; + } + } + num=0; + j=0; + i=0; + memset(s,0,sizeof(s)); + while (1) + { + for (j=1;j<=n;j++) + { + if (st[j][i]==1) + { + if (s[j]==0) num++; + s[j]++; + } + } + i++; + if (num==n) break; + } + i--;j=0; + int flag=0; + while (1) + { + for (k=1;k<=n;k++) + { + if (st[k][j]==1) + { + if (s[k]==1) + { + flag=1; + num--; + } + s[k]--; + } + } + if (flag) break; + j++; + } + for (k=1;k<=n;k++) + { + if (st[k][j]==1) + { + if (s[k]==0) + { + num++; + } + s[k]++; + } + } + ans=i-j+1; + ans1=j; + ans2=i; + while (1) + { + while (1) + { + for (k=1;k<=n;k++) + { + if (st[k][j]==1) + { + if (s[k]==1) + { + num--; + } + s[k]--; + } + } + j++; + if (num45000)break; + for (k=1;k<=n;k++) + { + if (st[k][i]==1) + { + if (s[k]==0) + { + num++; + } + s[k]++; + } + } + if (num==n)break; + } + if (i>45000)break; + } + int h1,m1,s1,h2,m2,s2; + h1=ans1/3600; + m1=ans1-h1*3600; + m1=m1/60; + s1=ans1-h1*3600-m1*60; + h2=ans2/3600; + m2=ans2-h2*3600; + m2=m2/60; + s2=ans2-h2*3600-m2*60; + printf("%02d:%02d:%02d %02d:%02d:%02d\n",h1,m1,s1,h2,m2,s2); + } + return 0; +} diff --git a/HDOJ/2912_autoAC.cpp b/HDOJ/2912_autoAC.cpp new file mode 100644 index 0000000..269641c --- /dev/null +++ b/HDOJ/2912_autoAC.cpp @@ -0,0 +1,103 @@ +#include +#include +using namespace std; +struct point{ + double x,y,z; + point(double xx=0,double yy=0,double zz=0){ + x=xx,y=yy,z=zz; + } + point operator ^(double h){ + return point(x*h,y*h,z*h); + } + double operator ^(point h){ + return x*h.x+y*h.y+z*h.z; + } + point operator +(point h){ + return point(x+h.x,y+h.y,z+h.z); + } + point operator -(point h){ + return point(x-h.x,y-h.y,z-h.z); + } + point operator *(point b){ + return point(y*b.z-b.y*z, z*b.x-b.z*x, x*b.y-b.x*y); + } + double len2()const{ + return x*x+y*y+z*z; + } + double len()const{ + return sqrt(len2()); + } + point turnlen(double l)const { + double r=l/len(); + return point(x*r,y*r,z*r); + } + void input() + { + scanf("%lf%lf%lf",&x,&y,&z); + } +}p1,p2,ans; +struct sphere{ + point c; + double r; + void input(){ + c.input(); + scanf("%lf",&r); + } +}sph[110]; +int n; +const double eps=1e-8; +int sgn(double x) +{ + if(fabs(x)0?1:-1; +} +bool intersection(sphere s,point p1,point p2,point &c) +{ + double d=((p1-s.c)*(p2-s.c)).len()/(p1-p2).len(); + if(sgn(d-s.r)>=0) + return false; + point pp=(sgn(d)==0? s.c:s.c+((p1-s.c)*(p2-s.c)*(p1-p2)).turnlen(d) ); if(sgn((pp-p1)^(p2-p1))<=0) + return false; + c=pp+(p1-p2).turnlen(sqrt(s.r*s.r-d*d)); + return true; +} +point reflection(point p1,point rep,point c) +{ + double d=((rep-p1)*(c-p1)).len()/(rep-c).len(); + return p1+((rep-p1)*(c-p1)*(rep-c)).turnlen(d*2.0); +} +void compute() +{ + while(true){ + point c; + int k=-1; + for(int i=0;i +#include +#include +#include +#include +using namespace std; +bool vis[35][35][300][7]; +struct node +{ + int x; + int y; + int z; + int w; + int step; +}; +int x,y,ans; +int dx[4]={1,0,-1,0}; +int dy[4]={0,1,0,-1}; +char map[35][35]; +char res[10]; +void init() +{ + memset(map,0,sizeof(map)); + memset(vis,0,sizeof(vis)); +} +int tomy(int sta) +{ + int a, b, c; + a=sta%6; b=sta/6%6; c=sta/36%6; + int d, e, f; + d=5-a, e=5-b, f=5-c; + return a+d*6+e*36+b*216+c*1296+f*7776; +} +int top(int sta) +{ + return sta%6; +} +int bt(int sta) +{ + return sta/6%6; +} +int nor(int sta) +{ + return sta/36%6; +} +int sou(int sta) +{ + return sta/216%6; +} +int wes(int sta) +{ + return sta/1296%6; +} +int eas(int sta) +{ + return sta/7776%6; +} +int up(int sta) +{ + int t1, n1, s1, b1, e1, w1; + t1=sou(sta); + n1=top(sta); + s1=bt(sta); + b1=nor(sta); + e1=eas(sta); + w1=wes(sta); + return t1+s1*6+w1*36; +} +int down(int sta) +{ + int t1, n1, s1, b1, e1, w1; + t1=nor(sta); + n1=bt(sta); + s1=top(sta); + b1=sou(sta); + e1=eas(sta); + w1=wes(sta); + return t1+s1*6+w1*36; +} +int left(int sta) +{ + int t1, n1, s1, b1, e1, w1; + t1=eas(sta); + w1=top(sta); + b1=wes(sta); + e1=bt(sta); + n1=nor(sta); + s1=sou(sta); + return t1+s1*6+w1*36; +} +int right(int sta) +{ + int t1, n1, s1, b1, e1, w1; + t1=wes(sta); + w1=bt(sta); + b1=eas(sta); + e1=top(sta); + n1=nor(sta); + s1=sou(sta); + return t1+s1*6+w1*36; +} +char s[]="rmybgc"; +bool bfs() +{ + node n1,n2; + n1.x=x; + n1.y=y; + n1.z=0; + n1.w=78; + n1.step=0; + vis[x][y][78][0]=1; + queue q; + q.push(n1); + while(!q.empty()) + { + node n2=q.front(); + if(n2.z==6) + { + ans=n2.step; + return true; + } + q.pop(); + int t=tomy(n2.w); + for(int i=0;i<4;i++) + { + int tmpx=dx[i]+n2.x; + int tmpy=dy[i]+n2.y; + if(map[tmpx][tmpy]=='w') + { + int temp; + if(i==0) + temp=right(t); + else if(i==1) + temp=down(t); + else if(i==2) + temp=left(t); + else + temp=up(t); + if(vis[tmpx][tmpy][temp][n2.z]==0) + { + vis[tmpx][tmpy][temp][n2.z]=1; + n1.x=tmpx; + n1.y=tmpy; + n1.w=temp; + n1.z=n2.z; + n1.step=n2.step+1; + q.push(n1); + } + } + else if(map[tmpx][tmpy]==res[n2.z]) + { + int temp; + if(i==0) + temp=right(t); + else if(i==1) + temp=down(t); + else if(i==2) + temp=left(t); + else + temp=up(t); + int top=temp%6; + if(vis[tmpx][tmpy][temp][n2.z+1]==0&&s[top]==res[n2.z]) + { + n1.x=tmpx; + n1.y=tmpy; + n1.w=temp; + n1.z=n2.z+1; + n1.step=n2.step+1; + vis[tmpx][tmpy][temp][n2.z+1]=1; + q.push(n1); + } + } + } + } + return false; +} +int main() +{ + int n,d; + while(scanf("%d%d",&n,&d)!=EOF&&n+d) + { + init(); + for(int i=1;i<=d;i++) + for(int j=1;j<=n;j++) + { + scanf(" %c",&map[j][i]); + if(map[j][i]=='#') + { + x=j; + y=i; + map[j][i]='w'; + } + } + scanf(" %s",res); + if(bfs()) + printf("%d\n",ans); + else + printf("unreachable\n"); + } + return 0 ; +} diff --git a/HDOJ/2916_autoAC.cpp b/HDOJ/2916_autoAC.cpp new file mode 100644 index 0000000..831345e --- /dev/null +++ b/HDOJ/2916_autoAC.cpp @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef vector VI; +char buf[10005]; +int th; +void out(VI v){ + for(int i = 0; i < (int)v.size(); i ++) printf("%d ", v[i]); + printf("\n"); +} +VI mul(VI v1, VI v2){ + int n = (v1.size())*(v2.size())+1; + VI ret(n, 0); + for(int i = 0; i < (int)v1.size(); i ++){ + for(int j = 0; j < (int)v2.size(); j ++){ + ret[i+j] += v1[i]*v2[j]; + } + } + return ret; +} +VI add(VI v1, VI v2){ + int n = max(v1.size(), v2.size()); + VI ret(n, 0); + for(int i = 0; i < (int)v1.size(); i ++) ret[i] += v1[i]; + for(int i = 0; i < (int)v2.size(); i ++) ret[i] += v2[i]; + return ret; +} +VI getE(); +VI getP(){ + if(buf[th] == 'x'){ + VI ret(2, 0); + ret[1] = 1; + th ++; + return ret; + } + if(buf[th] == '('){ + th ++; + VI ret = getE(); + th ++; + return ret; + } + int v = 0; + while(buf[th] >= '0' && buf[th] <= '9'){ + v = v*10 + buf[th] - '0'; + th ++; + } + return VI(1, v); +} +VI getF(){ + VI ret = getP(); + if(buf[th] == '^'){ + th ++; + VI tmp = getP(), t2 = ret; + for(int i = 1; i < (int)tmp[0]; i ++){ + ret = mul(ret, t2); + } + } + return ret; +} +VI getT(){ + VI ret; + ret.push_back(1); + while(buf[th] && buf[th] != '+' && buf[th] != '-' && buf[th] != ')'){ + VI tmp = getF(); + ret = mul(ret, tmp); + } + return ret; +} +VI getE(){ + VI ret; + int sign = 0; + while(buf[th]){ + if(sign != 0 && buf[th] != '+' && buf[th] != '-') break; + sign = 1; + if(buf[th] == '-') sign = -1; + if(buf[th] == '+' || buf[th] == '-') th ++; + VI tmp = getT(); + if(sign == -1) for(int i = 0; i < (int)tmp.size(); i ++) tmp[i] = -tmp[i]; + ret = add(ret, tmp); + } + return ret; +} +int gcd(int a, int b){ + return a == 0 ? b : gcd(b%a, a); +} +void normal(VI& v){ + while(v.size() && v.back() == 0) v.pop_back(); + int by = v[0]; + for(int i = 1; i < (int)v.size(); i ++) by = gcd(by, v[i]); + for(int i = 0; i < (int)v.size(); i ++) v[i] /= by; + if(v.size() && v.back() < 0) for(int i = 0; i < (int)v.size(); i ++) v[i] = -v[i]; +} +void output(VI v){ + bool first = true; + for(int i = (int)v.size()-1; i >= 0; i --){ + if(v[i] == 0) continue; + if((v[i] == 1 || v[i] == -1) && i != 0){ + if(v[i] == 1) if(!first) printf("+"); + if(v[i] == -1) printf("-"); + }else{ + if(first){ + if(v[i] < 0){ + printf("-"); + v[i] = -v[i]; + } + printf("%d", v[i]); + first = false; + }else{ + printf("%+d", v[i]); + } + } + if(i == 0){ + }else if(i == 1){ + printf("x"); + }else printf("x^%d", i); + first = false; + } + printf("\n"); +} +int main() { + while(scanf("%s", buf)){ + if(strlen(buf) == 1 && buf[0] == '.') break; + th = 0; + VI v1 = getE(); + scanf("%s", buf); + th = 0; + VI v2 = getE(); + normal(v1); + normal(v2); + while(1){ + if(v1.size() < v2.size()) swap(v1, v2); + if(v2.size() == 0) break; + int l1 = v1.back(), l2 = v2.back(); + int by = gcd(l1, l2); + for(int i = v1.size()-1; i >= 0; i --){ + int tmp = v2.size()-1-(v1.size()-1-i), vt; + if(tmp < 0) vt = 0; + else vt = v2[tmp]; + v1[i] = v1[i]*(l2/by) - vt*(l1/by); + } + normal(v1); + } + output(v1); + } + return 0; +} diff --git a/HDOJ/2917_autoAC.cpp b/HDOJ/2917_autoAC.cpp new file mode 100644 index 0000000..cae29a0 --- /dev/null +++ b/HDOJ/2917_autoAC.cpp @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const double eps = 1e-8; +const double pi = acos(-1.0); +int sgn(double d) { + if (d > eps) + return 1; + if (d < -eps) + return -1; + return 0; +} +struct point { + double x, y; + point(double _x = 0, double _y = 0): x(_x), y(_y) { + } + void input() { + scanf("%lf%lf", &x, &y); + } + double len() const { + return sqrt(x * x + y * y); + } + point trunc(double l) const { + double r = l / len(); + return point(x * r, y * r); + } + point rotate_left() const { + return point(-y, x); + } + point rotate_right() const { + return point(y, -x); + } +}; +bool operator==(const point& p1, const point& p2) { + return sgn(p1.x - p2.x) == 0 && sgn(p1.y - p2.y) == 0; +} +bool operator<(const point& p1, const point& p2) { + return sgn(p1.x - p2.x) == 0 ? sgn(p1.y - p2.y) < 0 : p1.x < p2.x; +} +point operator+(const point& p1, const point& p2) { + return point(p1.x + p2.x, p1.y + p2.y); +} +point operator-(const point& p1, const point& p2) { + return point(p1.x - p2.x, p1.y - p2.y); +} +double operator^(const point& p1, const point& p2) { + return p1.x * p2.x + p1.y * p2.y; +} +double operator*(const point& p1, const point& p2) { + return p1.x * p2.y - p1.y * p2.x; +} +bool get_intersection(const point& p1, const point& p2, const point& p3, const point& p4, point& c) { + double d1 = (p2 - p1) * (p3 - p1), d2 = (p2 - p1) * (p4 - p1); + if (sgn(d1 - d2) == 0) + return false; + c = point((p3.x * d2 - p4.x * d1) / (d2 - d1), (p3.y * d2 - p4.y * d1) / (d2 - d1)); + return true; +} +int n; +point p[16]; +pair dp[1 << 11][11][11], ans; +bool solve(); +void compute(); +int main() { + while (solve()); + return 0; +} +bool solve() { + scanf("%d", &n); + if (n == 0) + return false; + for (int i = 0; i < n; ++i) + p[i].input(); + sort(p, p + n); + n = unique(p, p + n) - p; + if (n < 2) { + puts("0 0.0000000"); + return true; + } + compute(); + printf("%d %.8lf\n", ans.first, ans.second); + return true; +} +void compute() { + for (int i = 0; i < (1 << n); ++i) + for (int j = 0; j < n; ++j) + for (int k = 0; k < n; ++k) + dp[i][j][k].first = 256; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (i == j) + continue; + dp[(1 << i) | (1 << j)][i][j] = make_pair(0, (p[j] - p[i]).len()); + } + } + for (int i = 0; i < (1 << n); ++i) { + for (int x = 0; x < n; ++x) { + if (((i >> x) & 1) == 0) + continue; + for (int y = 0; y < n; ++y) { + if (y == x || ((i >> y) & 1) == 0) + continue; + if (dp[i][x][y].first == 256) + continue; + pair& cur = dp[i][x][y]; + for (int j = 0; j < n; ++j) { + if (((i >> j) & 1) == 1) + continue; + pair& res = dp[i | (1 << j)][y][j]; + if (sgn((p[j] - p[x]) * (p[y] - p[x])) == 0) { + if (sgn((p[j] - p[y]) ^ (p[x] - p[y])) < 0) { + res = min(res, make_pair(cur.first, cur.second + (p[j] - p[y]).len())); + } else { + res = min(res, make_pair(cur.first + 1, cur.second + (p[j] - p[y]).len())); + } + } else { + res = min(res, make_pair(cur.first + 1, cur.second + (p[j] - p[y]).len())); + } + } + for (int j = 0; j < n; ++j) { + if (((i >> j) & 1) == 1) + continue; + for (int k = 0; k < n; ++k) { + if (k == j || ((i >> k) & 1) == 1) + continue; + pair& res = dp[i | (1 << j) | (1 << k)][j][k]; + point c; + if (get_intersection(p[x], p[y], p[j], p[k], c)) { + if (sgn((p[x] - p[y]) ^ (c - p[y])) < 0 && sgn((p[k] - p[j]) ^ (c - p[j])) < 0) { + res = min(res, make_pair(cur.first + 1, cur.second + (c - p[y]).len() + (c - p[k]).len())); + } + } + } + } + } + } + } + ans.first = 256; + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) + ans = min(ans, dp[(1 << n) - 1][i][j]); +} diff --git a/HDOJ/2918_autoAC.cpp b/HDOJ/2918_autoAC.cpp new file mode 100644 index 0000000..c6d6376 --- /dev/null +++ b/HDOJ/2918_autoAC.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +using namespace std; +char s[20]; +int map[15],r,step; +int check(int a[]) +{ + int i; + for(i = 1; i<=9; i++) + if(a[i] != i) + return 0; + return 1; +} +void swap(int s[],int a,int b,int c,int d) +{ + int t=s[a]; + s[a]=s[b],s[b]=s[c],s[c]=s[d]; + s[d]=t; +} +void work(int a[],int id) +{ + if(id==1) swap(a,1,2,5,4); + if(id==2) swap(a,2,3,6,5); + if(id==3) swap(a,4,5,8,7); + if(id==4) swap(a,5,6,9,8); + if(id==5) swap(a,8,9,6,5); + if(id==6) swap(a,7,8,5,4); + if(id==7) swap(a,5,6,3,2); + if(id==8) swap(a,4,5,2,1); +} +int dfs(int a[],int deep) +{ + if(check(a)) + return 1; + if(deep>=step) + return 0; + for(int i = 1; i<=8; i++) + { + work(a,i); + if(dfs(a,deep+1)) return 1; + work(a,9-i); + } + return 0; +} +int main() +{ + int i,j,cas = 1; + while(~scanf("%s",s)) + { + if(!strcmp(s,"0000000000")) + break; + r = s[0]-'0'; + for(i = 1; i<=9; i++) + map[i] = s[i]-'0'; + step = 0; + while(step<=r) + { + if(dfs(map,0))break; + step++; + } + if(step<=r) + printf("%d. %d\n",cas++,step); + else + printf("%d. -1\n",cas++); + } + return 0; +} diff --git a/HDOJ/2919_autoAC.cpp b/HDOJ/2919_autoAC.cpp new file mode 100644 index 0000000..0d192b3 --- /dev/null +++ b/HDOJ/2919_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +using namespace std; +const int MAX=30+10; +int hash1[200],hash2[10]; +char a[MAX],b[MAX]; +void Map(){ + hash2[0]=63,hash1[63]=0; + hash2[1]=10,hash1[10]=1; + hash2[2]=93,hash1[93]=2; + hash2[3]=79,hash1[79]=3; + hash2[4]=106,hash1[106]=4; + hash2[5]=103,hash1[103]=5; + hash2[6]=119,hash1[119]=6; + hash2[7]=11,hash1[11]=7; + hash2[8]=127,hash1[127]=8; + hash2[9]=107,hash1[107]=9; +} +int main(){ + Map(); + int lena,lenb,sum=0,i,j,p,temp=1; + while(~scanf("%s",a),strcmp(a,"BYE")){ + i=j=sum=0,temp=1; + while(a[i++] != '+'); + lena=i-1; + while(a[i] != '=')b[j++]=a[i++]; + lenb=j; + for(i=lena-3,j=lenb-3;i>=0 && j>=0;i-=3,j-=3){ + p=(a[i]-'0')*100+(a[i+1]-'0')*10+a[i+2]-'0'; + sum+=hash1[p]*temp; + p=(b[j]-'0')*100+(b[j+1]-'0')*10+b[j+2]-'0'; + sum+=hash1[p]*temp; + temp*=10; + } + while(i>=0){ + p=(a[i]-'0')*100+(a[i+1]-'0')*10+a[i+2]-'0'; + sum+=hash1[p]*temp; + temp*=10; + i-=3; + } + while(j>=0){ + p=(b[j]-'0')*100+(b[j+1]-'0')*10+b[j+2]-'0'; + sum+=hash1[p]*temp; + temp*=10; + j-=3; + } + printf("%s",a); + while(temp>sum)temp/=10; + while(temp){ + printf("%03d",hash2[sum/temp]); + sum=sum%temp; + temp=temp/10; + } + cout< +#include +#include +#include +#include +#include +using namespace std; +#define ll long long +#define N 105000 +struct Obj +{ + int sign,len; + ll val; +}obj[N]; +ll p[N],ha[N]; +int tot; +void init(char *s) +{ + int len=strlen(s); + tot=0; + for(int i=0,nxt=0;ilen || ha[obj[i].len]!=obj[i].val) return false; + cur+=obj[i].len; + continue; + } + if(i==tot-1) + { + if(cur+obj[i].len>len+1) return false; + if((len+1-(cur+obj[i].len))%2) return false; + cur=len+1-obj[i].len; + return ha[cur+obj[i].len-1]-ha[cur-1]*p[obj[i].len]==obj[i].val; + } + while(cur<=len+1&&cur+obj[i].len<=len+1) + { + if(ha[cur+obj[i].len-1]-ha[cur-1]*p[obj[i].len]==obj[i].val) break; + cur+=2; + } + if(cur>len+1||cur+obj[i].len>len+1) return false; + cur+=obj[i].len; + } + } + --cur; + return cur<=len&&(len-cur)%2==0; +} +char s[N]; +int main () +{ + p[0]=1; + for(int i=1;i +#include +#include +#include +#include +#include +#include +using namespace std; +int f[410][820], val[410][810]; +int main() +{ + int n, kase = 0; + while (cin >> n) + { + if (n == 0) break; + for (int i = 1; i <= n; i++) + { + f[i][0] = 0; + for (int j = 1; j <= 2 * i - 1; j++) + { + scanf("%d", &val[i][j]); + f[i][j] = f[i][j - 1] + val[i][j]; + } + } + int ans = -0x3f3f3f3f; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= 2 * i - 1; j += 2) + { + int tmp = 0; + for (int k = i; k <= n; k++) + { + if (j + 2 * (k - i) > 2 * k - 1) break; + tmp += f[k][j + 2 * (k - i)] - f[k][j - 1]; + if (tmp > ans) ans = tmp; + } + } + for (int i = n; i >= 1; i--) + { + for (int j = 2; j <= 2 * i - 1; j += 2) + { + int tmp = 0; + for (int k = i; k >= 1; k--) + { + if (j - 2 * (i - k) < 1) break; + if (j > 2 * k - 1) break; + tmp += f[k][j] - f[k][j - 2 * (i - k) - 1]; + if (tmp > ans) ans = tmp; + } + } + } + kase++; + cout << kase << ". " << ans << endl; + } +} diff --git a/HDOJ/2922_autoAC.cpp b/HDOJ/2922_autoAC.cpp new file mode 100644 index 0000000..9889fe4 --- /dev/null +++ b/HDOJ/2922_autoAC.cpp @@ -0,0 +1,13 @@ +#include +int main() +{ + int a,b,ans; + while(scanf("%d%d",&a,&b),a!=-1|| b!=-1) + { + ans=0; + if(a==1 || b==1) ans=1; + if(ans) printf("%d+%d=%d\n",a,b,a+b); + else printf("%d+%d!=%d\n",a,b,a+b); + } + return 0; +} diff --git a/HDOJ/2924_autoAC.cpp b/HDOJ/2924_autoAC.cpp new file mode 100644 index 0000000..d68d303 --- /dev/null +++ b/HDOJ/2924_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; +const int M = 1010; +int Map[M][M]; +int C[M]; +int R[M]; +int main() +{ + int n; + int k = 0; + while(scanf("%d",&n),n) + { + memset(C,0,sizeof(C)); + memset(R,0,sizeof(R)); + int ans = 0; + int res = 0; + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= n; j++) + { + cin>>Map[i][j]; + ans += Map[i][j]; + C[i] += Map[i][j]; + } + } + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= n; j++) + { + R[i] += Map[j][i]; + } + int cnt = C[i] - R[i]; + if(cnt > 0) + { + res += cnt; + } + } + printf("%d. %d %d\n",++k,ans,res); + } + return 0; +} diff --git a/HDOJ/2925_autoAC.cpp b/HDOJ/2925_autoAC.cpp new file mode 100644 index 0000000..efc048f --- /dev/null +++ b/HDOJ/2925_autoAC.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + int n,d,w; + while(cin>>n>>d) + { + if(n==0&&d==0) break; + int ans=0; + for(int i=2;i<=n;i++) + ans=(ans+d)%i; + cout< +#include +__int64 f[70]; +__int64 work(int n,__int64 r,__int64 st,__int64 ed) +{ + __int64 sum=0,num; + if(n==0)return 1; + num=f[n]/2; + if(r<=num){ + if(ed<=num){ + sum=work(n-1,r,st,ed); + }else if(st>num){ + sum=work(n-1,r,st-num,ed-num); + }else { + sum=work(n-1,r,st,num); + sum+=work(n-1,r,1,ed-num); + } + }else{ + if(ed<=num){ + sum=work(n-1,r-num,st,ed); + }else if(st>num){ + sum=-work(n-1,r-num,st-num,ed-num); + }else { + sum=work(n-1,r-num,st,num); + sum-=work(n-1,r-num,1,ed-num); + } + } + return sum; +} +int main() +{ + int i,j; + int n; + __int64 r,st,ed,ans; + f[0]=1; + for(i=1;i<=60;i++){ + f[i]=f[i-1]*2; + } + while(scanf("%d%I64d%I64d%I64d",&n,&r,&st,&ed)){ + if(n==-1&&r==-1&&st==-1&&ed==-1)break; + ans=work(n,r+1,st+1,ed+1); + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/2931_autoAC.cpp b/HDOJ/2931_autoAC.cpp new file mode 100644 index 0000000..3d43cd8 --- /dev/null +++ b/HDOJ/2931_autoAC.cpp @@ -0,0 +1,138 @@ +#include +#include +int num[3],tot,n,f; +char s[3][100],ans[3][100]; +int check() +{ + char str[100]; + int a=0,b=0,c; + for(int i=0;i=0;i--) + { + str[i]='0'+c%10; + c/=10; + } + if(c>0||str[0]=='0') + return 0; + for(int i=0;i=num[a]) + { + b=0; + a++; + } + if(a==2) + { + if(check()) + tot++; + return; + } + if(s[a][b]!='*') + dfs(a,b+1); + else + { + for(int i=0;i<10;i++) + { + if(b==0&&i==0) + continue; + s[a][b]='0'+i; + dfs(a,b+1); + if(tot>1) + { + s[a][b]='*'; + return; + } + } + s[a][b]='*'; + } +} +void search(int a,int b,int c) +{ + if(b>=num[a]) + { + b=0; + a++; + } + if(c==n) + { + tot=0; + dfs(0,0); + if(tot==1) + { + f=1; + for(int i=0;i<3;i++) + strcpy(ans[i],s[i]); + } + return; + } + if(a>=3) + return; + char ch=s[a][b],tc; + for(int i=0;i<=10;i++) + { + if(i==1&&b==0) + continue; + if(!i) + tc='*'; + else + tc='0'+i-1; + if(tc==s[a][b]) + search(a,b+1,c); + else + { + s[a][b]=tc; + search(a,b+1,c+1); + } + if(f) + { + s[a][b]=ch; + return; + } + s[a][b]=ch; + } +} +void work() +{ + int m=0; + for(int i=0;i<3;i++) + m+=num[i]; + for(n=1;n<=m;n++) + { + f=0;; + search(0,0,0); + if(f) + return; + } +} +int main() +{ + int cas=1; + memset(s,0,sizeof(s)); + while(scanf("%s",s[0])&&s[0][0]!='0') + { + scanf("%s%s",s[1],s[2]); + for(int i=0;i<3;i++) + num[i]=strlen(s[i]); + tot=0; + dfs(0,0); + printf("Case %d: ",cas++); + if(tot==1) + printf("%s %s %s\n",s[0],s[1],s[2]); + else + { + work(); + printf("%s %s %s\n",ans[0],ans[1],ans[2]); + } + memset(s,0,sizeof(s)); + } + return 0; +} diff --git a/HDOJ/2932_autoAC.cpp b/HDOJ/2932_autoAC.cpp new file mode 100644 index 0000000..4eeeaf2 --- /dev/null +++ b/HDOJ/2932_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +const int maxn = 17; +const int MAXN = 100017; +int main() +{ + int n; + int cas = 0; + int a[maxn], b[maxn], c[maxn]; + while(scanf("%d",&n)&&n) + { + for(int i = 1; i <= n; i++) + scanf("%d%d%d", &a[i], &b[i], &c[i]); + int ans; + int cont = 0; + for(ans = 1; ans < MAXN; ans++) + { + cont = 0; + for(int i = 1; i <= n; i++) + { + if(c[i] <= a[i]) + cont++; + } + if(cont == n) + break; + for(int i = 1; i <= n; i++) + { + if(c[i] == a[i]+b[i] || (c[i] == a[i] && cont > n-cont)) + { + c[i] = 0; + } + c[i]++; + } + } + if(ans == MAXN) + ans = -1; + printf("Case %d: %d\n", ++cas, ans); + } + return 0; +} diff --git a/HDOJ/2935_autoAC.cpp b/HDOJ/2935_autoAC.cpp new file mode 100644 index 0000000..11cd803 --- /dev/null +++ b/HDOJ/2935_autoAC.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include +using namespace std; +struct P +{ + double x,y; +}c[25],d[25]; +int ans[25]; +bool operator<(P a,P b) +{ + if(a.x!=b.x)return a.x5.0+eps) + continue; + ans[0]=ctd[a]; + for(j=1;j5*ssd+eps || d[j].x-d[j-1].x+eps(6-ans[j-1])*sd+eps) + break; + if(d[j-1].y-d[j].y>ans[j-1]*sd+eps) + break; + double dis=d[j].y-d[j-1].y; + int tmp=(int)(dis/sd); + if(dis>=0) + { + if(tmp*sd-dis+eps<0) + tmp++; + if(tmp*sd-dis>0+eps) + break; + } + else + { + if(tmp*sd-dis>0+eps) + tmp--; + if(tmp*sd-dis+eps<0) + break; + } + ans[j]=tmp+ans[j-1]; + } + if(j==n) + { + break; + } + } + printf("Case %d: ",++T); + for(i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define me(s) memset(s,0,sizeof(s)) +#define pb push_back +typedef long long ll; +typedef unsigned int uint; +typedef unsigned long long ull; +typedef pair P; +const int N=256; +int n,m,target; +mapsol; +queueq; +bool icy[N]; +char link_l[N],link_r[N],clear_l[N],clear_r[N]; +void init() +{ + memset(icy,0,sizeof(icy)); + icy['O']=icy['[']=icy[']']=icy['=']=true; + memset(link_l,' ',sizeof(link_l)); + link_l['O']=']';link_l['[']='='; + memset(link_r,' ',sizeof(link_r)); + link_r['O']='[';link_r[']']='='; + memset(clear_l,' ',sizeof(clear_l)); + clear_l[']']='O';clear_l['=']='[';clear_l['O']='O';clear_l['[']='['; + memset(clear_r,' ',sizeof(clear_r)); + clear_r['[']='O';clear_r['=']=']';clear_r['O']='O';clear_r[']']=']'; +} +string fall(string s) +{ + int k,r,p; + for(int i=n-1;i>=0;i--) + for(int j=0;jtarget/m)b=x/m-target/m; + else b=(x/mb?a:b; +} +bool expand(string s,char cmd) +{ + string seq=sol[s]+cmd; + int x=s.find('@'); + s[x]='.'; + if(cmd=='<'||cmd=='>') + { + s[x]='@'; + int p=(cmd=='<'?x+m-1:x+m+1); + if(s[p]=='X')return false; + else if(s[p]=='.') + { + s[p]='O'; + if(icy[s[p-1]])s[p-1]=link_r[s[p-1]]; + if(s[p-1]!='.')s[p]=link_l[s[p]]; + if(icy[s[p+1]])s[p+1]=link_l[s[p+1]]; + if(s[p+1]!='.')s[p]=link_r[s[p]]; + } + else + { + s[p]='.'; + if(icy[s[p-1]])s[p-1]=clear_r[s[p-1]]; + if(icy[s[p+1]])s[p+1]=clear_l[s[p+1]]; + } + } + else + { + int p=(cmd=='L'?x-1:x+1); + if(s[p]=='.')s[p]='@'; + else + { + if(s[p]=='O') + { + int k; + if(cmd=='L'&&s[p-1]=='.') + { + for(k=p-1;k>0;k--)if(s[k-1]!='.'||s[k+m]=='.')break; + s[p]='.';s[k]='O';s[x]='@'; + } + if(cmd=='R'&&s[p+1]=='.') + { + for(k=p+1;k15)return false; + if(s.find('@')==target) + { + printf("%s\n",seq.c_str()); + return true; + } + if(!sol.count(s)) + { + sol[s]=seq; + q.push(s); + } + return false; +} +int main() +{ + int rnd=0; + init(); + while(~scanf("%d%d",&n,&m)) + { + if(!n)break; + char mp[20][20]; + for(int i=0;i'))break; + if(expand(s,'L'))break; + if(expand(s,'R'))break; + } + while(!q.empty())q.pop(); + } +} diff --git a/HDOJ/2937_autoAC.cpp b/HDOJ/2937_autoAC.cpp new file mode 100644 index 0000000..589003e --- /dev/null +++ b/HDOJ/2937_autoAC.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +using namespace std; +char tg[10][10] = { + " _ _ ", + "| |", + "|_ _|" +}; +struct Grid{ + char s[5][12]; + bool input(){ + for(int i = 0; i < 5; i ++) if(!gets(s[i])) return false; + return true; + } + void output(){ + for(int i = 0; i < 5; i ++) printf("%s\n", s[i]); + printf("\n"); + } + bool move(int x, int y){ + for(int i = 0; i <= 2; i ++){ + for(int j = 0; j <= 4; j ++){ + if(i == 0 && (j == 0 || j == 2 || j == 4)) continue; + if(s[x+i][y+j] == tg[i][j]) s[x+i][y+j] = '.'; + if(s[x+i][y+j] == '.') continue; + return false; + } + } + return true; + } + bool ok(){ + for(int i = 0; i < 5; i ++){ + for(int j = 0; j < 9; j ++){ + if(s[i][j] != '.' && s[i][j] != ' ') return false; + } + } + return true; + } +}g[8]; +bool dfs(int th){ + if(g[th].ok()) return true; + if(th == 6) return false; + for(int i = 0; i + 2 < 5; i ++){ + for(int j = 0; j + 4 < 9; j += 2){ + g[th+1] = g[th]; + if(g[th+1].move(i, j)){ + if(dfs(th+1)) return true; + } + } + } + return false; +} +int main() { + int cas = 0; + while(g[0].input()){ + printf("Case %d: ", ++cas); + printf("%s\n", dfs(0) ? "Yes" : "No"); + } + return 0; +} diff --git a/HDOJ/2940_autoAC.cpp b/HDOJ/2940_autoAC.cpp new file mode 100644 index 0000000..552e2d2 --- /dev/null +++ b/HDOJ/2940_autoAC.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +using namespace std; +#define Max 2000 +int num[Max], pre[Max]; +void init() +{ + memset(num, 0, sizeof(num)); + memset(pre, 0, sizeof(pre)); + pre[0] = 1; + for(int i = 2; i <= 110; i++) + { + int c = 0; + for(int j = 0; j < Max; j++) + { + int sum = pre[j]*i + c; + pre[j] = sum%16; + c = sum/16; + } + int k; + for(k = Max-1; k >= 0; k--) if(pre[k]) + break; + for(int j = 0; j <= k; j++) if(!pre[j]) + num[i]++; + } +} +int main(void) +{ + int n; + init(); + while(cin>>n && n >= 0) + { + cout< +int main() +{ + int i,n,t,a[102]; + while(scanf("%d",&n),n) + { + for(i=0;i + using namespace std; + __int64 p[21][21]; + __int64 gcd(__int64 a, __int64 b) +{ + return b ? gcd(b, a % b) : a; + } + void init() + { + int i, j; + for (i = 0; i <= 20; ++i) + { + p[i][0] = 1; + p[i][i] = 0; + } + for (i = 2; i <= 20; ++i) + for (j = 1; j < i; ++j) + p[i][j] = p[i - 1][j] + p[i - 1][j - 1] * (i - 1); + } + void solve(int s, int n) + { + __int64 sum = 0, total = 0 , g; + int i; + for (i = 0; i < s; ++i) + sum += p[n][i]; + total = sum; + for ( ; i < n; ++i) + total += p[n][i]; + g = gcd(sum, total); + sum /= g; + total /= g; + if (total == 1 && sum == 1) + printf("1\n"); + else if (sum == 0) + printf("0\n"); + else printf("%I64d/%I64d\n", sum, total); +} +int main() +{ + init(); + int tcase, w, h, n, s; + scanf("%d", &tcase); + while (tcase--) + { + scanf("%d%d%d", &w, &h, &s); + solve(s, w * h); + } + return 0; +} diff --git a/HDOJ/2948_autoAC.cpp b/HDOJ/2948_autoAC.cpp new file mode 100644 index 0000000..f45730d --- /dev/null +++ b/HDOJ/2948_autoAC.cpp @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define eps 1e-12 +#define MAXN 55 +#define INF 1e30 +#define mem0(a) memset(a,0, sizeof(a)) +#define mem1(a) memset(a,-1,sizeof(a)) +double MAX(double a, double b) {return a > b ? a : b;} +double MIn(double a, double b) {return a < b ? a : b;} +typedef long long LL; +struct Point{ + double x,y; + Point(double x=0, double y=0):x(x),y(y){} +}; +struct Polygon +{ + Point p[MAXN]; + int Size; +}; +struct Circle +{ + Point o; + double r; + Circle(){} + Circle(Point _o, double _r):o(_o),r(_r){} +}; +Point operator + (Point A, Point B) {return Point(A.x+B.x, A.y+B.y);} +Point operator - (Point A, Point B) {return Point(A.x-B.x, A.y-B.y);} +Point operator * (Point A, double p) {return Point(A.x*p, A.y*p);} +Point operator / (Point A, double p) {return Point(A.x/p, A.y/p);} +int dcmp(double x) { + if(fabs(x) < eps) return 0; + else return x < 0 ? -1 : 1; +} +bool operator == (const Point &A, const Point &B) { + return dcmp(A.x-B.x) == 0 && dcmp(A.y-B.y) == 0; +} +double Dot(Point A, Point B) { return A.x*B.x + B.y*B.y;} +double Length(Point A) { return sqrt(Dot(A,A));} +double Angle(Point A, Point B) {return acos(Dot(A,B) / Length(A) / Length(B));} +double cross(Point A, Point B) {return A.x*B.y - A.y*B.x;} +bool crossed(Point a, Point b, Point c, Point d) +{ + if(cross(a-c, d-c)*cross(b-c, d-c)<=0 && cross(c-a, b-a)*cross(d-a, b-a)<=0) + { + return true; + } + return false; +} +bool isPointOnSegent(Point p, Point s, Point e) +{ + double d = (p.x-s.x) * (e.x-p.x); + double a = (p.y-s.y) / (p.x-s.x); + double b = (e.y-p.y) / (e.x-p.x); + if(dcmp(d)==1 && dcmp(a-b)==0)return true; + return false; +} +int isPointInPolygon(Point p, Polygon poly) +{ + int w = 0; + int n = poly.Size; + for(int i=0;i 0 && d1 <= 0 && d2 > 0) w++; + if(k < 0 && d2 <= 0 && d1 > 0) w--; + } + if(w != 0) return 1; + return 0; +} +struct R +{ + Point a, b; + R(){} + R(Point _a, Point _b) + { + a = _a; + b = _b; + } +}r[1001]; +struct T +{ + Point a, b, c; + T(){} + T(Point _a, Point _b, Point _c) { + a = _a; b = _b; c = _c; + } +}t[1001]; +Circle c[1001]; +int S, N; +int cntC = 0, cntT = 0, cntR = 0; +int calc(double x, double y) +{ + Point p = Point(x, y); + int ans = 0; + for(int i=0;i=r[i].a.x&&x<=r[i].b.x && y>=r[i].a.y&&y<=r[i].b.y) ans ++; + } + return ans; +} +int main() +{ + char ch;double x, y, rr; + while(~scanf("%d%*c", &S)) + { + cntT = cntC = cntR = 0; + for(int i=0;i cntB ? "Bob" : (cntA == cntB ? "Tied" : "Hannah")); + } + } + return 0; +} diff --git a/HDOJ/2949_autoAC.cpp b/HDOJ/2949_autoAC.cpp new file mode 100644 index 0000000..859bd57 --- /dev/null +++ b/HDOJ/2949_autoAC.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef pair PII; +typedef vector VI; +#define PB push_back +#define MP make_pair +#define clr(a,b) (memset(a,b,sizeof(a))) +#define rep(i,a) for(int i=0; i<(int)a.size(); i++) +const int INF = 0x3f3f3f3f; +const double eps = 1E-8; +int T; +int n,l,r; +char s[200010]; +int num[200010]; +LL tot = 1ll*n*(n+1)/2; +double fun1(int lim) +{ + double ret = 0; + int ed = 1,sum = num[1]; + for(int st=1; st<=n; st++) + { + while(sum <= lim && ed < n) + { + ed ++; + sum += num[ed]; + } + if(sum > lim) ret += 1.0*(n - ed + 1)/(1ll*n*(n-st+1)) ; + sum -= num[st]; + } + return ret; +} +double fun2(int lim) +{ + double ret = 0; + int ed = 1,sum = num[1]; + for(int st=1; st<=n; st++) + { + while(sum < lim && ed < n) + { + ed ++; + sum += num[ed]; + } + if(sum >= lim) + { + if(ed-1 >= st) ret += 1.0*(ed - st)/(1ll*n*(n-st+1)); + } + else + { + ret += 1.0*(ed - st + 1)/(1ll*n*(n-st+1)); + } + sum -= num[st]; + } + return ret; +} +int main() +{ + scanf("%d",&T); + while(T--) + { + scanf("%d",&n); + scanf("%s",s+1); + scanf("%d%d",&l,&r); + num[0] = 0; + for(int i=1; i<=n; i++) num[i] = s[i] - 'A'; + double a,b,c; + c = fun1(r); + a = fun2(l); + b = 1 - a - c; + printf("%lf %lf %lf\n",b,a,c); + } + return 0; +} diff --git a/HDOJ/2950_autoAC.cpp b/HDOJ/2950_autoAC.cpp new file mode 100644 index 0000000..6f1c661 --- /dev/null +++ b/HDOJ/2950_autoAC.cpp @@ -0,0 +1,17 @@ +#include +#include +#include +using namespace std; +char s1[1000],s2[1000]; +int T; +int main() +{ + scanf("%d",&T); + while(T--) + { + scanf("%s%s",s1,s2); + if(strcmp(s1,s2) == 0) puts("OK"); + else puts("ERROR"); + } + return 0; +} diff --git a/HDOJ/2952_autoAC.cpp b/HDOJ/2952_autoAC.cpp new file mode 100644 index 0000000..a7cbbc7 --- /dev/null +++ b/HDOJ/2952_autoAC.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +using namespace std; +int H,W; +char Map[105][105]; +int direct[][2] = {{-1,0}, {1,0}, {0,-1}, {0, 1}}; +void DFS(int i, int j) { + if(i<1 || i>H || j<1 || j>W) + return; + Map[i][j] = '.'; + for(int k=0; k<4; ++k) + if(Map[i+direct[k][0]][j+direct[k][1]] == '#') + DFS(i+direct[k][0], j+direct[k][1]); +} +int main() +{ + int T; + cin >> T; + while(cin >> H >> W) { + for(int i=1; i<=H; ++i) + for(int j=1; j<=W; ++j) + cin >> Map[i][j]; + int counts = 0; + for(int i=1; i<=H; ++i) + for(int j=1; j<=W; ++j) + if(Map[i][j] == '#') { + DFS(i, j); + ++counts; + } + cout << counts << endl; + } + return 0; +} diff --git a/HDOJ/2953_autoAC.cpp b/HDOJ/2953_autoAC.cpp new file mode 100644 index 0000000..169740d --- /dev/null +++ b/HDOJ/2953_autoAC.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +using namespace std; +int cvr[6][12]={ + {4,12,13,5,3,2,11,19,20,21,14,6}, + {12,13,5,4,11,19,20,21,14,6,3,2}, + {7,6,14,15,1,3,5,13,21,23,16,8}, + {6,14,15,7,5,13,21,23,16,8,1,3}, + {1,0,2,3,8,9,10,11,4,5,6,7}, + {0,2,3,1,10,11,4,5,6,7,8,9}}; +int block[8][3]={ + {3,5,6},{1,7,8},{0,9,10},{2,4,11}, + {12,19,20},{13,14,21},{15,16,23},{17,18,22}}; +struct S{ + char s[30]; + friend bool operator< (const S& a,const S& b){ + return strcmp(a.s,b.s)<0; + } + void change(){ + map col; + map flag; + col[s[17]]='B'; flag[s[17]]=true; + col[s[18]]='W'; flag[s[18]]=true; + col[s[22]]='Y'; flag[s[22]]=true; + for(int i=0;i<7;i++){ + int cnt=0,sum=0,has=3; + if(flag[s[block[i][0]]]){cnt++;sum+=col[s[block[i][0]]];has-=0;} + if(flag[s[block[i][1]]]){cnt++;sum+=col[s[block[i][1]]];has-=1;} + if(flag[s[block[i][2]]]){cnt++;sum+=col[s[block[i][2]]];has-=2;} + if(cnt!=2) continue; + if(sum=='B'+'W') col[s[block[i][has]]]='O'; + if(sum=='B'+'Y') col[s[block[i][has]]]='G'; + if(sum=='Y'+'W') col[s[block[i][has]]]='R'; + } + for(int i=0;i<24;i++){ + s[i]=col[s[i]]; + } + } +}s; +map step; +void in(char &c){ + c=getchar(); + while(c<=32) c=getchar(); +} +void bfs0(){ + strcpy(s.s,"OOOORRGGBBWWRRGGBBWWYYYY"); + step.clear(); + step[s]=-1; + queue > que; + que.push(make_pair(s,0)); + while(!que.empty()){ + S u=que.front().first; + int d=que.front().second; + que.pop(); + for(int i=0;i<6;i++){ + S v=u; + for(int j=0;j<12;j++){ + v.s[cvr[i][j]]=u.s[cvr[i^1][j]]; + } + if(step[v]) continue; + step[v]=d+1; + if(d<6){ + que.push(make_pair(v,d+1)); + } + } + } +} +map vis; +int bfs1(){ + s.change(); + if(step[s]){ + if(step[s]==-1) return 0; + else return step[s]; + } + vis.clear(); + vis[s]=true; + queue > que; + que.push(make_pair(s,0)); + while(!que.empty()){ + S u=que.front().first; + int d=que.front().second; + que.pop(); + for(int i=0;i<6;i++){ + S v=u; + for(int j=0;j<12;j++){ + v.s[cvr[i][j]]=u.s[cvr[i^1][j]]; + } + if(vis[v]) continue; + vis[v]=true; + if(step[v]){ + if(step[v]==-1) return d+1; + else return step[v]+d+1; + } + que.push(make_pair(v,d+1)); + } + } + return -1; +} +int main(){ + bfs0(); + int t; + scanf("%d",&t); + while(t--){ + for(int i=0;i<24;i++){ + in(s.s[i]); + } + int ans=bfs1(); + printf("%d\n",ans); + } +} diff --git a/HDOJ/2954_autoAC.cpp b/HDOJ/2954_autoAC.cpp new file mode 100644 index 0000000..421e9e0 --- /dev/null +++ b/HDOJ/2954_autoAC.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +using namespace std; +const int MAX=10; +int main(){ + int t,b,w; + cin>>t; + while(t--){ + cin>>b>>w; + if(w&1)printf("0.00 1.00\n"); + else printf("1.00 0.00\n"); + } + return 0; +} diff --git a/HDOJ/2955_autoAC.cpp b/HDOJ/2955_autoAC.cpp new file mode 100644 index 0000000..e987125 --- /dev/null +++ b/HDOJ/2955_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct bank +{ + int mon; + float pro; +}b[110]; +int n; +int main () +{ + int T,i,j; + cin>>T; + int sum; + double dp[100010]; + while(T--) + { + float p; + cin>>p>>n; + sum=0; + for(i=1;i<=n;i++) + { + cin>>b[i].mon>>b[i].pro; + sum+=b[i].mon; + } + memset(dp,0,sizeof(dp)); + dp[0]=1; + for(i=1;i<=n;i++) + for(j=sum;j>=b[i].mon;j--) + { + if(dp[j]=0&&dp[i]<(1-p);i--); + cout< +using namespace std; +int main() +{ + double a[4]; + while(cin>>a[0]>>a[1]>>a[2]>>a[3],(a[0]+a[1]+a[2]+a[3])!=0) + { + double min=0,max=0; + int i; + double l[3],r[3]; + l[0]=a[1]-0.5; + l[1]=a[2]-0.5; + l[2]=a[3]-0.5; + if(l[0]<0) + l[0]=0.0; + if(l[1]<0) + l[1]=0.0; + if(l[2]<0) + l[2]=0.0; + for(i=0;i<3;i++) + { + r[i]=a[i+1]+0.499999; + } + min=l[0]*9+l[1]*4+l[2]*4; + max=r[0]*9+r[1]*4+r[2]*4; + if(a[0]<=max&&a[0]>=min) + cout<<"yes"< +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define M 1005 +struct dance{ + char s[105]; +}p[M]; +int k; +bool judge1 (int i) +{ + if (i-1 >= 0 && !strcmp (p[i-1].s, "jiggle") || + i-2 >= 0 && !strcmp (p[i-2].s, "jiggle") || + i+1 < k && !strcmp (p[i+1].s, "twirl")) + return true; + return false; +} +bool judge2 () +{ + if (k < 3) return false; + if (strcmp (p[k-1].s, "clap") != 0 || + strcmp (p[k-2].s, "stomp") != 0 || + strcmp (p[k-3].s, "clap") != 0) + return false; + return true; +} +void solve () +{ + int i, j, tw = 0, ho = 0, dip = 0, ans[10], has[10]; + memset (has, 0, sizeof(has)); + for (i = 0; i < k; i++) + { + if (!strcmp (p[i].s, "dip")) + { + if (!judge1 (i)) + { + has[1] = 1; + for (j = 0; j < 3; j++) p[i].s[j] -= 32; + } + dip = 1; + } + if (!strcmp (p[i].s, "twirl")) tw = 1; + if (!strcmp (p[i].s, "hop")) ho = 1; + } + if (tw && !ho) has[3] = 1; + if (!judge2 ()) has[2] = 1; + if (!strcmp (p[0].s, "jiggle")) has[4] = 1; + if (!dip) has[5] = 1; + int id = 0; + for (i = 1; i <= 5; i++) + if (has[i]) + ans[id++] = i; + if (id == 0) printf ("form ok:"); + else if (id == 1) printf ("form error %d:", ans[0]); + else + { + printf ("form errors %d", ans[0]); + for (i = 1; i < id-1; i++) + printf (", %d", ans[i]); + printf (" and %d:", ans[id-1]); + } + for (i = 0; i < k; i++) + printf (" %s", p[i].s); + printf ("\n"); +} +int main () +{ + while (~scanf ("%s", p[0].s)) + { + k = 1; + while (1) + { + char ch = getchar (); + if (ch == '\n') break; + scanf ("%s", p[k++].s); + } + solve (); + } + return 0; +} diff --git a/HDOJ/2962_autoAC.cpp b/HDOJ/2962_autoAC.cpp new file mode 100644 index 0000000..ad3b750 --- /dev/null +++ b/HDOJ/2962_autoAC.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +using namespace std; +const int SIZE = 10010; +const int INF = 0xfffffff; +int u[5*SIZE], v[5*SIZE], w[5*SIZE], nex[5*SIZE], h[5*SIZE]; +int first[SIZE], d[SIZE]; +int n, m, cnt; +int s, e; +void read_graph(int u1, int v1, int w1, int h1) +{ + u[cnt] = u1; v[cnt] = v1; w[cnt] = w1; h[cnt] = h1; + nex[cnt] = first[u[cnt]]; + first[u[cnt]] = cnt++; +} +int spfa(int src, int mid) +{ + queue q; + bool inq[SIZE] = {0}; + for(int i = 1; i <= n; i++) d[i] = (i == src)?0:INF; + q.push(src); + while(!q.empty()) + { + int x = q.front(); q.pop(); + inq[x] = 0; + for(int e = first[x]; e!=-1; e = nex[e]) if(d[v[e]] > d[x]+w[e] && mid <= h[e]) + { + d[v[e]] = d[x] + w[e]; + if(!inq[v[e]]) + { + inq[v[e]] = 1; + q.push(v[e]); + } + } + } + if(d[e] == INF) return 0; + return 1; +} +void init() +{ + memset(first, -1, sizeof(first)); + cnt = 0; +} +int main() +{ + int times = 0; + while(~scanf("%d%d", &n, &m), n, m) + { + init(); + while(m--) + { + int u1, v1, w1, h1; + scanf("%d%d%d%d", &u1, &v1, &h1, &w1); + if(h1 == -1) h1 = INF; + read_graph(u1, v1, w1, h1); + read_graph(v1, u1, w1, h1); + } + int x = 0, y, ans = INF, mid, h; + scanf("%d%d%d", &s, &e, &y); + while(x <= y) + { + mid = (x+y)>>1; + if(spfa(s, mid)) + { + x = mid+1; + ans = d[e]; + h = mid; + } + else y = mid-1; + } + if(times) printf("\n"); + printf("Case %d:\n", ++times); + if(ans != INF) + { + printf("maximum height = %d\n", h); + printf("length of shortest route = %d\n", ans); + } + else + { + printf("cannot reach destination\n"); + } + } +} diff --git a/HDOJ/2964_autoAC.cpp b/HDOJ/2964_autoAC.cpp new file mode 100644 index 0000000..34e2813 --- /dev/null +++ b/HDOJ/2964_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +using namespace std; +const int prime[21]= {2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,51,53,57,59}; +int a[21]; +__int64 bases[21]; +int main() +{ + bases[0]=1; + for(int i=1; i<=20; i++) + bases[i]=bases[i-1]*prime[i-1]; + int n,r; + while(cin>>n&&n) + { + for(int i=0; i<=20; i++) + { + if(bases[i]<=n && bases[i+1]>n) + { + r=i; + break; + } + } + memset(a,0,sizeof(a)); + int m=n; + for(int i=r; i>=0; i--) + { + a[i]=n/bases[i]; + n=n%bases[i]; + } + cout< +typedef long long LL; +LL getgcd(LL a,LL b) +{ + if(!b)return a; + return getgcd(b,a%b); +} +void gcd(LL a,LL b,LL& d,LL& x,LL& y) +{ + if(!b){d=a;x=1;y=0;} + else + { + gcd(b,a%b,d,y,x); + y-=x*(a/b); + } +} +bool calcu(LL a,LL b,LL x,LL y) +{ + if(x<0) + { + while(x<0) + { + x+=b; + y-=a; + } + if(y>0) + return true; + } + else if(y<0) + { + while(y<0) + { + x-=b; + y+=a; + } + if(x>0) + return true; + } + return false; +} +int main() +{ + int t; + LL a,b,c,d; + scanf("%d",&t); + while(t--) + { + scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d); + if(c%a==0&&d%b==0||c%b==0&&d%a==0) + printf("YES\n"); + else + { + LL p=getgcd(a,b); + if(c%p||d%p) + printf("NO\n"); + else + { + a/=p;b/=p; + c/=p;d/=p; + LL x,y,gg=a*b,v; + if(c%gg==0) + { + gcd(a,b,v,x,y); + if(calcu(a,b,x*d,y*d)) + { + printf("YES\n"); + continue; + } + } + if(d%gg==0) + { + gcd(a,b,v,x,y); + if(calcu(a,b,x*c,y*c)) + { + printf("YES\n"); + continue; + } + } + printf("NO\n"); + } + } + } + return 0; +} diff --git a/HDOJ/2966_autoAC.cpp b/HDOJ/2966_autoAC.cpp new file mode 100644 index 0000000..3796a66 --- /dev/null +++ b/HDOJ/2966_autoAC.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const int N = 111111; +struct Point { + LL x[3]; +} p[N], ori[N]; +int split[20], cur, dim; +bool cmp(Point a, Point b) { + return a.x[cur] < b.x[cur]; +} +#define lson l, m - 1, depth + 1 +#define rson m + 1, r, depth + 1 +void build(int l, int r, int depth) { + if (l >= r) return ; + int m = l + r >> 1; + cur = depth % dim; + nth_element(p + l, p + m, p + r + 1, cmp); + build(lson); + build(rson); +} +template T sqr(T x) { return x * x;} +const LL inf = 0x7777777777777777ll; +LL dist(Point x, Point y) { + LL ret = 0; + for (int i = 0; i < dim; i++) { + ret += sqr(x.x[i] - y.x[i]); + } + return ret ? ret : inf; +} +LL find(Point x, int l, int r, int depth) { + int cur = depth % dim; + if (l >= r) { + if (l == r) return dist(x, p[l]); + return inf; + } + int m = l + r >> 1; + LL ret = dist(x, p[m]), tmp; + if (x.x[cur] < p[m].x[cur]) { + tmp = find(x, lson); + if (tmp > sqr(x.x[cur] - p[m].x[cur])) { + tmp = min(tmp, find(x, rson)); + } + } else { + tmp = find(x, rson); + if (tmp > sqr(x.x[cur] - p[m].x[cur])) { + tmp = min(tmp, find(x, lson)); + } + } + return min(ret, tmp); +} +int main() { + int n, T; + scanf("%d", &T); + while (T-- && scanf("%d", &n)) { + dim = 2; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { + scanf("%I64d", &ori[i].x[j]); + } + p[i] = ori[i]; + } + build(0, n - 1, 0); + for (int i = 0; i < n; i++) { + printf("%I64d\n", find(ori[i], 0, n - 1, 0)); + } + } + return 0; +} diff --git a/HDOJ/2967_autoAC.cpp b/HDOJ/2967_autoAC.cpp new file mode 100644 index 0000000..e921ce0 --- /dev/null +++ b/HDOJ/2967_autoAC.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +using namespace std; +const int maxn=110; +char s[maxn][maxn]; +int visit[maxn]; +int n; +int len[maxn]; +int ans[maxn]; +int en[maxn],fa[maxn]; +int solve(int dep,int num) +{ + if (en[dep]!=0) return en[dep]-1; + visit[dep]=num; + for(int i=0;i=visit[t]) + { + if (ans[j]>0) return 1; + if (len[j]>maxs) maxs=len[j]; + counts++; + } + if (counts>1) return 2; + if (maxs>1) return 1; + return 0; + } + int now=solve(t,num+1); + if (now==0) continue; + return now; + } + visit[dep]=0; + return 0; +} +int find_fa(int u) +{ + if (fa[u]!=u) fa[u]=find_fa(fa[u]); + return fa[u]; +} +int main() +{ + int cas; + scanf("%d",&cas); + while(cas--) + { + scanf("%d",&n); + for(int i=0;i +#include +#include +using namespace std; +struct P{ + int l; + int i; + P(){} +}p[1000000],q[1000000]; +bool cmp(P a,P b){ + return a.l'9'||c<'0')c=getchar(); + do{ + r=r*10+c-'0'; + c=getchar(); + }while(c>='0'&&c<='9'); + return r; +} +int res[1000000]; +bool fl[1000000]; +int main(){ + int ca; + scanf("%d",&ca); + while(ca-->0){ + int n,d; + scanf("%d%d",&n,&d); + for(int i=0;i=0;i--){ + while(j>=0&&p[j].l>q[i].l){ + int fr=p[j].i; + fl[fr]=true; + if(fr>0&&fr0&&fl[fr-1]); + else if(fr +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int maxn=600010; +int sa[maxn],Rank[maxn]; +char s[maxn]; +int N; +int main() +{ + int T; + scanf("%d",&T); + while(T--) + { + scanf("%d",&N); + for(int i=1;i<=N;i++) + { + scanf("%d",&sa[i]); + Rank[sa[i]]=i; + } + Rank[N+1]=-1; + int k=0; + s[sa[1]]=k+'a'; + for(int i=2;i<=N;i++) + { + int x=sa[i-1],y=sa[i]; + if(Rank[x+1]>Rank[y+1])k++; + s[sa[i]]=k+'a'; + } + if(k>=26)printf("-1\n"); + else + { + s[N+1]=0; + printf("%s\n",s+1); + } + } + return 0; +} diff --git a/HDOJ/2971_autoAC.cpp b/HDOJ/2971_autoAC.cpp new file mode 100644 index 0000000..6de8f2f --- /dev/null +++ b/HDOJ/2971_autoAC.cpp @@ -0,0 +1,58 @@ +#include +#include +#define MAXD 4 +int N, M, a2; +struct Matrix +{ + int a[MAXD][MAXD]; + Matrix() + { + memset(a, 0, sizeof(a)); + } +}; +Matrix multiply(Matrix &x, Matrix &y) +{ + int i, j, k; + Matrix z; + for(k = 0; k < 4; k ++) + for(i = 0; i < 4; i ++) + if(x.a[i][k]) + { + for(j = 0; j < 4; j ++) + if(y.a[k][j]) + z.a[i][j] = (z.a[i][j] + (long long)x.a[i][k] * y.a[k][j]) % M; + } + return z; +} +void powmod(Matrix &unit, Matrix &mat, int n) +{ + while(n) + { + if(n & 1) + unit = multiply(mat, unit); + n >>= 1; + mat = multiply(mat, mat); + } +} +void solve() +{ + Matrix mat, unit; + unit.a[0][0] = unit.a[2][0] = 1, unit.a[1][0] = ((long long)a2 * a2) % M, unit.a[3][0] = a2; + mat.a[0][0] = mat.a[0][1] = 1; + mat.a[1][1] = (4ll * a2 * a2) % M, mat.a[1][2] = 1, mat.a[1][3] = ((-4ll * a2) % M + M) % M; + mat.a[2][1] = 1; + mat.a[3][1] = (2ll * a2) % M, mat.a[3][3] = M - 1; + powmod(unit, mat, N - 1); + printf("%d\n", unit.a[0][0]); +} +int main() +{ + int t; + scanf("%d", &t); + while(t --) + { + scanf("%d%d%d", &a2, &N, &M); + solve(); + } + return 0; +} diff --git a/HDOJ/2972_autoAC.cpp b/HDOJ/2972_autoAC.cpp new file mode 100644 index 0000000..1b35c89 --- /dev/null +++ b/HDOJ/2972_autoAC.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +using namespace std; +struct node +{ + int l,r,id,flag; + bool operator < (const node &b) const + { + return r>b.r; + } +}; +priority_queue q; +bool cmp(const node &a,const node &b) +{ + if (a.l!=b.l) return a.lb.id; +} +node a[100010]; +int main() +{ + int T; + scanf("%d",&T); + while (T--) + { + int n; + scanf("%d",&n); + for (int i=0;ians) ans=now+numa+numb; + if (bad==1) + if (now+numa+numb>maxs) maxs=now+numa+numb; + } + maxs+=!good; + if (maxs>ans) ans=maxs; + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/2973_autoAC.cpp b/HDOJ/2973_autoAC.cpp new file mode 100644 index 0000000..934818a --- /dev/null +++ b/HDOJ/2973_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; +#define LL long long +#define M 3100300 +int tag[M],p[M]; +void Prime() +{ + memset(tag,0,sizeof(tag)); + memset(p,0,sizeof(p)); + int cnt=0,i,j; + for( i=2;i +#include +#include +#include +using namespace std; +const int MAX = 510000; +int pre[MAX], cnt[MAX]; +int isleaf[MAX]; +queue q; +long long n, mod; +int prime[MAX], num_prime, cprime[MAX], isprime[MAX]; +void init() +{ + scanf("%d%d", &n, &mod); + pre[1] = -1; + memset(isleaf, 0, sizeof(isleaf)); + for (int i = 2; i <= n; i++) + { + scanf("%d", &pre[i]); + isleaf[pre[i]]++; + } + for (int i = 1; i <= n; i++) + if (!isleaf[i]) + q.push(i); +} +void bfs() +{ + for (int i = 1; i <= n; i++) + cnt[i] = 1; + while (!q.empty()) + { + int u = q.front(); + q.pop(); + if (u == 1) + continue; + cnt[pre[u]] += cnt[u]; + isleaf[pre[u]]--; + if (!isleaf[pre[u]]) + q.push(pre[u]); + } +} +void prime_init() +{ + memset(isprime, 1, sizeof(isprime)); + int cnt = 0; + isprime[0] = isprime[1] = -1; + for (int i = 2; i < MAX; i++) + if (isprime[i] != -1) + { + isprime[i] = cnt++; + for (int j = 2; j * i < MAX; j++) + isprime[i * j] = -1; + } + num_prime = 0; + for (int i = 2; i <= MAX; i++) + if (isprime[i] != -1) + prime[num_prime++] = i; +} +void fac(int a, int v) +{ + for (int i = 0; a != 1; i++) + { + while (a % prime[i] == 0) + cprime[i] += v, a /= prime[i]; + if (isprime[a] != -1) + cprime[isprime[a]] += v, a = 1; + } +} +long long pow(int a, int b) +{ + long long x = a, r = 1; + while (b) + { + if (b & 1) + r = (r * x) % mod; + x = (x * x) % mod; + b >>= 1; + } + return r; +} +long long solve() +{ + memset(cprime, 0, sizeof(cprime)); + for (int i = 2; i < n; i++) + fac(i, 1); + for (int i = 2; i <= n; i++) + fac(cnt[i], -1); + long long res = 1; + for (int i = 0; i <= n && res != 0; i++) + if (cprime[i]) + res = (res * pow(prime[i], cprime[i])) % mod; + return res; +} +int main() +{ + prime_init(); + int t; + scanf("%d", &t); + while (t--) + { + init(); + bfs(); + cout << solve() << endl; + } + return 0; +} diff --git a/HDOJ/2977_autoAC.cpp b/HDOJ/2977_autoAC.cpp new file mode 100644 index 0000000..e2c6ec9 --- /dev/null +++ b/HDOJ/2977_autoAC.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const int N = 2000009; +int visit[N]; +struct node{ + int a[5]; +} re[N]; +int ans[N]; +int map[4][4]; +void makemap(int k) +{ + for(int i=0;i<3;i++) + for(int j=0;j<3;j++) + { + map[i][j]=k%5; + k/=5; + } +} +struct quenod{ + int s,step; +}; +queue que; +bool v[5]; +bool oor(int x,int y) +{ + if(x<0||x>2) return false; + if(y<0||y>2) return false; + return true; +} +int dx[]={0,0,-1,1}; +int dy[]={-1,1,0,0}; +bool ok(int x,int y,int n) +{ + memset(v,0,sizeof(v)); + int tx,ty; + for(int i=0;i<4;i++) + { + tx = x+dx[i],ty=y+dy[i]; + if(!oor(tx,ty)) continue; + v[map[tx][ty]]=true; + } + for(int i=1;i=w) + { + ou = true; + printf("Case %d: %d\n",T++,ans[i]); + break; + } + } + if(!ou) + { + printf("Case %d: Impossible\n",T++); + } + } + return 0; +} diff --git a/HDOJ/2978_autoAC.cpp b/HDOJ/2978_autoAC.cpp new file mode 100644 index 0000000..941bb7d --- /dev/null +++ b/HDOJ/2978_autoAC.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#define OP(s) cout<<#s<<"="<>m>>k; + string s1,s2; + map mp; + while (n--) + { + map vd; + cin>>s1>>s2; + int len = s1.length(); + for (int i = 0;i <= len-k;i++) + { + string tmp = ""; + for (int j =0;j < k;j++) tmp += s1[i+j]; + if (!vd[tmp]) + { + vd[tmp] = 1; + int id; + if (mp[tmp] == 0) + { + mp[tmp] = ++tota; + id = tota; + a[id].count = 0; + a[id].yes = 0; + a[id].str = tmp; + } + else id = mp[tmp]; + a[id].count++; + if (s2 == "Yes") a[id].yes++; + } + } + } + int ans = -1,ansc = 1,ansy = 2; + for (int i = 1;i <= tota;i++) + { + if (a[i].count < m) continue; + int y1 = a[i].yes,c1 = a[i].count; + if (y1 * ansc < ansy*c1 + || y1*ansc == ansy*c1 && c1 > ansc + || y1*ansc == ansy*c1 && c1 == ansc && a[i].str < a[ans].str + ) + { + ans = i,ansy = y1,ansc = c1; + } + } + if (ans == -1) cout<<"No solution\n"; + else cout< +#include +#include +#include +using namespace std; +#define maxm 210 +#define maxn 5 +double inf = 1e100; +double eps = 1e-5; +void pivot(int m,int n, double a[maxm][maxn], int B[maxm], int N[maxn], int r, int c){ + int i, j; + swap(N[c], B[r]); + a[r][c] = 1 / a[r][c]; + for(j = 0; j <= n; j++) + if(j != c) + a[r][j] *= a[r][c]; + for(i = 0; i <= m; i++) + if(i != r){ + for(j = 0; j <= n; j++) + if(j != c) + a[i][j] -= a[i][c] * a[r][j]; + a[i][c] = -a[i][c] * a[r][c]; + } +} +int feasible(int m, int n, double a[maxm][maxn],int B[maxm], int N[maxn]){ + int r, c, i; + double p, v; + while(1){ + for(p = inf, i = 0; i < m; i++) + if(a[i][n] < p) + p = a[r=i][n]; + if(p > -eps) + return 1; + for(p = 0, i = 0; i < n; i++) + if(a[r][i] < p) + p = a[r][c=i]; + if(p > -eps) + return 0; + p = a[r][n] / a[r][c]; + for(i = r + 1; i < m; i++) + if(a[i][c] > eps){ + v = a[i][n] / a[i][c]; + if(v < p) + r = i, p = v; + } + pivot(m, n, a, B, N, r, c); + } +} +int simplex(int m, int n, double a[maxm][maxn], double b[maxn], double &ret){ + int B[maxm], N[maxn], r, c, i; + double p, v; + for(i = 0; i p) + p = a[m][c=i]; + if(p < eps){ + for(i = 0; i < n; i++) + if(N[i] < n) + b[N[i]] = 0; + for(i = 0; i < m; i++) + if(B[i] < n) + b[B[i]] = a[i][n]; + ret = -a[m][n]; + return 1; + } + for(p = inf, i = 0; i < m; i++) + if(a[i][c] > eps){ + v = a[i][n] / a[i][c]; + if(v < p) + p= v, r = i; + } + if(p == inf) + return -1; + pivot(m, n, a, B, N, r, c); + } +} +double A[maxm][maxn], B[maxn]; +int main() +{ + int n , ca = 1, L, R; + while(scanf("%d", &n) != EOF){ + if(n == 0) + break; + scanf("%d%d", &L, &R); + for(int i = 0; i < n; i++){ + int x, y, z, p; + scanf("%d%d%d%d", &x, &y, &z, &p); + A[2*i][0] = x; + A[2*i][1] = y; + A[2*i][2] = z; + A[2*i][3] = p - L; + A[2*i+1][0] = -x; + A[2*i+1][1] = -y; + A[2*i+1][2] = -z; + A[2*i+1][3] = R - p; + } + A[2*n][0] = 1.0; + A[2*n][1] = -1.0; + A[2*n][2] = 0.0; + A[2*n][3] = 0; + A[2*n+1][0] = 0.0; + A[2*n+1][1] = 1.0; + A[2*n+1][2] = -1.0; + A[2*n+1][3] = 0; + A[2*n+2][0] = -1.0; + A[2*n+2][1] = 0.0; + A[2*n+2][2] = 0.0; + A[2*n+2][3] = 0; + scanf("%lf%lf%lf", &A[2*n+3][0], &A[2*n+3][1], &A[2*n+3][2]); + A[2*n+3][3] = -R; + double ret; + int sta = simplex(2*n+3, 3, A, B, ret); + printf("Case %d: ", ca++); + if(sta == -1) + printf("Too expensive!\n"); + else if(sta == 0) + printf("Inconsistent data\n"); + else + printf("%.4lf\n",ret); + } + return 0; +} diff --git a/HDOJ/2980_autoAC.cpp b/HDOJ/2980_autoAC.cpp new file mode 100644 index 0000000..111bf16 --- /dev/null +++ b/HDOJ/2980_autoAC.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +using namespace std; +double r,w,t; +char buf[500]; +const double eps = 1e-8; +const double pi = acos(-1.0); +struct Point +{ + double x,y; + Point() {} + Point(double _x,double _y) + { + x = _x; + y = _y; + } + Point(Point _a,Point _b) + { + x = _b.x-_a.x; + y = _b.y-_a.y; + } + void transXY(double B) + { + double tx = x,ty = y; + x = tx*cos(B) - ty*sin(B); + y = tx*sin(B) + ty*cos(B); + } + double Length() + { + return sqrt(eps+x*x+y*y); + } +}; +int cmp(double a,double b) +{ + if (fabs(a-b) < eps) return 0; + if (a < b) return -1; + return 1; +} +double sqr(double a) +{ + return a*a; +} +Point p[4],res[4]; +int main() +{ + int ft = 0; + while (true) + { + gets(buf); + if (strlen(buf) == 1) break; + sscanf(buf,"%lf%lf%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y); + scanf("%lf%lf%lf",&r,&t,&w); + gets(buf); + w = pi*w/180; + double theta = w*t; + theta = theta-2*pi*floor(theta/(2*pi)); + double l = r*w*t; + double totl = 0; + Point tv; + for (int i = 0; i < 4; i++) + { + tv = Point(p[i],p[(i+1)%4]); + totl += tv.Length()-2*r; + } + res[0] = p[0]; + for (int i = 1;i < 4;i++) + { + tv = Point(p[i-1],p[i]); + tv.transXY(-theta); + res[i] = Point(res[i-1].x+tv.x,res[i-1].y+tv.y); + } + l = l-totl*floor(l/totl); + double pre = 0.0,len; + Point prep,nowp,xp; + tv = Point(p[0],p[1]); + len = tv.Length(); + xp = Point(p[0].x+tv.x*r/len,p[0].y+tv.y*r/len); + prep = Point(xp.x+tv.y*r/len,xp.y-tv.x*r/len); + for (int i = 0; i < 4; i++) + { + tv = Point(res[i],res[(i+1)%4]); + len = tv.Length(); + if (cmp(pre+len-2*r,l) >= 0) + { + l -= pre; + l += r; + xp = Point(res[i].x+tv.x*l/len,res[i].y+tv.y*l/len); + nowp = Point(xp.x+tv.y*r/len,xp.y-tv.x*r/len); + tv = Point(nowp,prep); + for (int j = 0;j < 4;j++) + res[j] = Point(res[j].x+tv.x,res[j].y+tv.y); + break; + } + pre += len-2*r; + } + ft++; + printf("Case %d:",ft); + for (int i = 0;i < 4;i++) + printf(" %.3f %.3f",res[i].x,res[i].y); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/2982_autoAC.cpp b/HDOJ/2982_autoAC.cpp new file mode 100644 index 0000000..706803e --- /dev/null +++ b/HDOJ/2982_autoAC.cpp @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include +#include +#include +#define LL long long +#define pii pair +#define pdi pair +#define INF 0x7f7f7f7f +using namespace std; +const int N=200; +int x[N], y[N], rudu[N]; +int earn, lost, n; +vector vect[N], vec[N]; +double sum; +struct node +{ + int from, to, cap, flow; + double val; + node(){}; + node(int from,int to,double val,int cap,int flow):from(from),to(to),val(val),cap(cap),flow(flow){}; +}edge[90000]; +int edge_cnt; +void add_node(int from,int to,double val,int cap,int flow) +{ + edge[edge_cnt]=node(from, to, val, cap, flow ); + vec[from].push_back(edge_cnt++); +} +void build_graph() +{ + for(int i=1; i<=n; i++) + { + for(int j=0; j0) + { + add_node(0, i, 0, rudu[i], 0); + add_node(i, 0, 0, 0, 0); + } + if(rudu[i]<0) + { + add_node(i, n+1, 0, -rudu[i], 0); + add_node(n+1, i, 0, 0, 0); + } + } +} +int flow[N], path[N], inq[N]; +double cost[N]; +double spfa(int s,int e) +{ + deque que(1,s); + cost[s]=0; + flow[s]=INF; + inq[s]=1; + while(!que.empty()) + { + int x=que.front(); + que.pop_front(); + inq[x]=0; + for(int i=0; ie.flow && cost[e.to]>cost[e.from]+e.val ) + { + flow[e.to]=min(flow[e.from],e.cap-e.flow); + cost[e.to]=cost[e.from]+e.val; + path[e.to]=vec[x][i]; + if(!inq[e.to]) + { + inq[e.to]=1; + que.push_back(e.to); + } + } + } + } + return cost[e]; +} +double mcmf(int s,int e) +{ + double ans_cost=0.0; + while(true) + { + memset(flow,0,sizeof(flow)); + memset(inq,0,sizeof(inq)); + memset(path,0,sizeof(path)); + for(int i=0; i<=e; i++) cost[i]=1e39; + double tmp=spfa(s,e); + if(tmp>1e38) return ans_cost; + ans_cost+=tmp; + int ed=e; + while(ed!=s) + { + int t=path[ed]; + edge[t].flow+=flow[n+1]; + edge[t^1].flow-=flow[n+1]; + ed=edge[t].from; + } + } +} +int main() +{ + int b, j=0; + while(scanf("%d", &n), n) + { + scanf("%d%d",&earn,&lost); + for(int i=0; i<=n+1; i++) vect[i].clear(); + for(int i=0; i<=n+1; i++) vec[i].clear(); + memset(edge,0,sizeof(edge)); + memset(rudu,0,sizeof(rudu)); + edge_cnt=0; + sum=0; + for(int i=1; i<=n; i++) + { + scanf("%d%d",&x[i],&y[i]); + while(scanf("%d",&b), b) vect[i].push_back(b); + } + build_graph(); + printf("Case %d: %.2f\n", ++j, -(mcmf(0,n+1)+sum)+0.0000001 ); + } + return 0; +} diff --git a/HDOJ/2984_autoAC.cpp b/HDOJ/2984_autoAC.cpp new file mode 100644 index 0000000..c40b09e --- /dev/null +++ b/HDOJ/2984_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#define EPS (1e-8) +double dp[1010]; +using namespace std; +double cal(double a,double b,double pre,double p) { + return (p-pre)/(1+pow(p-a,b)); +} +double get_max(int a,double b,double pre) { + double l = a+1 ,r = 1e10; + while(abs(l-r)>EPS) { + double mid = (l+r)/2.0,mmid = (r+mid)/2.0; + if(cal(a,b,pre,mmid)cal(a,b,pre,ans+1)?cal(a,b,pre,ans):cal(a,b,pre,ans+1); +} +double get(double a,double b,int n) { + dp[0] = a; + for(int i(1);i!=n;++i) + dp[i] = dp[i-1] + get_max(a,b,dp[i-1]); + return dp[n-1]; +} +int main() { + double a,b,n; + int t(0); + while(cin>>n) { + if(n==0) break; + cin>>a>>b; + printf("Case %d: %.2lf\n",++t,get(a,b,n)); + } + return 0; +} diff --git a/HDOJ/2985_autoAC.cpp b/HDOJ/2985_autoAC.cpp new file mode 100644 index 0000000..7f8fa00 --- /dev/null +++ b/HDOJ/2985_autoAC.cpp @@ -0,0 +1,37 @@ +#include +#include +int a[10010]; +int gcd(int a, int b) +{ + return b > 0 ? gcd(b, a%b) : a; +} +int n, m; +void Solve() +{ + while(~scanf("%d%d", &n, &m)) + { + if(!n && !m) + { + break; + } + int sum = 0; + for(int i = 0; i < n; ++i) + { + for(int j = 0; j < m; ++j) + { + scanf("%d", &a[i]); + } + sum += a[i]; + } + for(int i = 0; i < n; ++i) + { + int t = gcd(sum, a[i]); + printf("%d / %d\n", a[i]/t, sum/t); + } + } +} +int main() +{ + Solve(); + return 0; +} diff --git a/HDOJ/2986_autoAC.cpp b/HDOJ/2986_autoAC.cpp new file mode 100644 index 0000000..6de056d --- /dev/null +++ b/HDOJ/2986_autoAC.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +map val; +int con(char *str) { + int a, b; + sscanf(str, "%d.%d", &a, &b); + return a * 10 + b; +} +bool check(int a, int b, char *p) { + if (!strcmp(p, "=")) return a == b; + if (!strcmp(p, "<=")) return a <= b; + if (!strcmp(p, ">=")) return a >= b; + if (!strcmp(p, "<")) return a < b; + if (!strcmp(p, ">")) return a > b; + return false; +} +int main() { + int n, m; + char buf[2][100]; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int i = 0; i < 2; i++) cin >> buf[i]; + val[buf[0]] = con(buf[1]); + } + for (int cas = 1; cas <= m; cas++) { + int sum = 0; + while (true) { + cin >> buf[0]; + sum += val[buf[0]]; + cin >> buf[0]; + if (buf[0][0] != '+') break; + } + int x; + cin >> x; + cout << "Guess #" << cas << " was " << (check(sum, x * 10, buf[0]) ? "correct." : "incorrect.") << endl; + } + } + return 0; +} diff --git a/HDOJ/2988_autoAC.cpp b/HDOJ/2988_autoAC.cpp new file mode 100644 index 0000000..7a963a4 --- /dev/null +++ b/HDOJ/2988_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +using namespace std; +#define maxn 200010 +struct node{ + int u,v,w; +}edge[maxn]; +int parent[maxn]; +int n,m,ans,sum; +int cmp(const node &p,const node &q){ + return p.w=0;i=parent[i]) + ; + while(i!=x){ + int tmp=parent[x]; + parent[x]=i; + x=tmp; + } + return i; +} +void Union(int x,int y){ + int r1=Find(x),r2=Find(y); + if(r1==r2) return; + if(parent[r1] +using namespace std; +int dp[200][200],a[200],sum,temp; +int main() +{ + int i,j,k,n,min; + while(cin>>n&&n) + { + min=0; + sum=0; + for(i=1;i<=n;i++) + cin>>a[i]; + for(i=1;i<=n;i++) + { + sum+=a[i]; + dp[1][i]=(1+i)*sum; + } + for(i=2;i<=n;i++) + for(j=i;j<=n;j++) + { + sum=0;min=100000000; + for(k=j;k>=i;k--) + { + sum+=(i+j)*a[k]; + temp=dp[i-1][k-1]+sum; + if(tempdp[i][n]) + min=dp[i][n]; + } + cout< +#include +#include +using namespace std; +int ans; +int n, a, b, y[1005]; +void cal(int x){ + int ret1 = 0, ret2 = 0; + for(int i = 1; i <= n; i++) + { + ret1 += y[i] / x; + if(y[i] % x){ + ret1++; + ret2 += x - y[i] % x; + } + } + if(b * ret1 * 6 + a * ret2 < ans){ + ans = b * ret1 * 6 + a * ret2; + } +} +int main() +{ + while(scanf("%d", &n) != EOF &&n){ + scanf("%d%d", &a, &b); + int Max = -1; + for(int i = 1; i <= n; i++){ + scanf("%d", &y[i]); + y[i] = y[i] * 6; + if(Max < y[i]){ + Max = y[i]; + } + } + Max = Max / 3; + ans = 0x7fffffff; + for(int i = 1; i <= n; i++) + for(int j = 1; j <= 3; j++) + if(y[i] / j >= Max) { + cal(y[i] / j); + } + int tmp = 6; + if(ans % 2 == 0) + ans /= 2, tmp /= 2; + if(ans % 3 == 0) + ans /= 3, tmp /= 3; + printf("%d", ans); + if(tmp != 1) + printf(" / %d", tmp); + cout << endl; + } + return 0; +} diff --git a/HDOJ/2991_autoAC.cpp b/HDOJ/2991_autoAC.cpp new file mode 100644 index 0000000..78988cd --- /dev/null +++ b/HDOJ/2991_autoAC.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +const int MAXN=10030; +int a[MAXN]; +int main(int argc, char *argv[]) +{ + long n; + while(scanf("%ld",&n) && n) + { + int count=1; + memset(a,0,sizeof(a)); + a[n]=1; + while(1) + { + long t=n*n/100; + n=t%10000; + a[n]++; + if(a[n]==2) break; + count++; + } + printf("%d\n",count); + } + return 0; +} diff --git a/HDOJ/2992_autoAC.cpp b/HDOJ/2992_autoAC.cpp new file mode 100644 index 0000000..6eb8588 --- /dev/null +++ b/HDOJ/2992_autoAC.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const int maxn=10005; +const int INF=0x3fffffff; +int que[maxn]; +int st[110]; +int g[110][110]; +int inque[maxn]; +int dis[maxn]; +int n, num; +struct Node +{ + int v, cost; + Node(int v_,int cost_) + { + v=v_, cost=cost_; + } +}; +mapmp; +vectorvt[maxn]; +void spfa(int start) +{ + int h=0, t=0; + for(int i=1; i<=n; i++) + { + dis[i]=INF; + inque[i]=0; + } + dis[start]=0; + inque[start]=1; + que[t++]=start; + while(h!=t) + { + int u=que[h++]; + inque[u]=0; + if(h==maxn) h=0; + for(int i=0; idis[u]+cost) + { + dis[v]=dis[u]+cost; + if(!inque[v]) + { + inque[v]=1; + que[t++]=v; + if(t==maxn) t=0; + } + } + } + } + for(int i=1; i<=n; i++) + { + if(dis[i]<=600) + { + g[mp[start]][mp[i]]=1; + } + } +} +void floyd() +{ + for(int k=0; k<=num+1; k++) + for(int i=0; i<=num+1; i++) + for(int j=0; j<=num+1; j++) + { + if(g[i][j]>g[i][k]+g[k][j]) + g[i][j]=g[i][k]+g[k][j]; + } +} +int main() +{ + int h, m, u, v, cost; + while(cin >> n, n) + { + cin >> num; + mp.clear(); + for(int i=0; i<=n; i++) + vt[i].clear(); + for(int i=0; i<=num+2; i++) + for(int j=0; j<=num+2; j++) + { + g[i][j]=INF; + if(i==j) g[i][j]=0; + } + for(int i=1; i<=num; i++) + { + scanf("%d",st+i); + mp[st[i]]=i; + } + st[0]=1; + mp[1]=0; + st[num+1]=n; + mp[n]=num+1; + cin >> m; + for(int i=0; i +#include +using namespace std; +const int maxn=50; +const __int64 INF=(__int64)1<<60; +typedef __int64 lld; +typedef struct node +{ + lld v[maxn][maxn]; + }node; +node d,e1,e2,e; +int n,tmin,tmax; +node mul1(node a,node b) +{ + int i,j,k; + node c; + for(i=0;i>=1; + } + return t; + } +node mul2(node a,node b) +{ + int i,j,k; + node c=a; + for(i=0;i>=1; + } + return t; + } +int main() +{ + int i,j,k; + for(i=0;i<50;i++)for(j=0;j<50;j++)e.v[i][j]=0; + for(i=0;i<50;i++)e.v[i][i]=1; + while(scanf("%d%d%d",&n,&tmin,&tmax)!=EOF) + { + for(i=0;i +#include +#include +#include +#include +#define N 10005 +#define LL long long +#define inf 1<<29 +#define eps 1e-7 +using namespace std; +int n,a[100],m,k,cnt,sg[1005]; +int get_sg(int n){ + if(sg[n]!=-1) + return sg[n]; + int vis[10000]; + memset(vis,0,sizeof(vis)); + for(int i=0;i