diff --git a/HDOJ/2600_autoAC.cpp b/HDOJ/2600_autoAC.cpp new file mode 100644 index 0000000..8152b99 --- /dev/null +++ b/HDOJ/2600_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +char hash[12000005]; +int main() +{ + int N,i,A,B,j,p,q,temp; + char s[100]; + while(scanf("%d",&N)!=EOF) + { + memset(hash,0,sizeof(hash)); + scanf("%d %d",&p,&q); + if(p>q) + { + temp=p; + p=q; + q=temp; + } + for(i=0;iB) + { + temp=A; + A=B; + B=A; + } + for(j=A;j<=B;j++) + { + if(j<0) + hash[-j]++; + else + hash[j]++; + } + gets(s); + } + for(i=q;i>=p;i--) + { + if(i>=0&&hash[i]==0) + { + printf("%d\n",i); + break; + } + if(i<0&&hash[-i]==0) + { + printf("%d\n",i); + break; + } + } + if(i +#include +int main() +{ + int n,k; + __int64 i,j,m; + scanf("%d",&n); + while(n--) + { + scanf("%I64d",&m); + m=m+1; + j=sqrt(m); + k=0; + for(i=2;i<=j;i++) + { + if(m%i==0) + k++; + } + printf("%d\n",k); + } + return 0; +} diff --git a/HDOJ/2602_autoAC.cpp b/HDOJ/2602_autoAC.cpp new file mode 100644 index 0000000..7d77182 --- /dev/null +++ b/HDOJ/2602_autoAC.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +using namespace std; +const int Max = 1000 + 10; +struct node +{ + int value; + int volum; +}a[Max]; +int f[Max]; +int main() +{ + int t; + int n,v; + int i,j; + while(scanf("%d",&t) != EOF) + { + while(t--) + { + scanf("%d %d",&n,&v); + memset(f, 0, sizeof(f)); + for(i=1; i<=n; i++) + { + scanf("%d",&a[i].value); + } + for(i=1; i<=n; i++) + { + scanf("%d",&a[i].volum); + } + for(i=1; i<=n; i++) + { + for(j=v; j>=a[i].volum; j--) + { + f[j] = max(f[j], f[j-a[i].volum] + a[i].value); + } + } + cout< +#include +#include +#define PI acos(-1.0) +#define G 9.87 +#define H1 3 +#define H2 0.5 +int main() +{ + double v,m,a; + while(~scanf("%lf%lf%lf",&v,&m,&a)) + { + double vx=v*cos(a*PI/180); + double vy=v*sin(a*PI/180); + double x,t1,t2,t; + if(vy*vy>G) + { + double t1=2*(vy-sqrt(vy*vy-2*H2*G))/G; + double t2=(sqrt(vy*vy+2*G*H1)-vy)/G; + t=t1+t2; + } + else + { + t=2*vy/G+(sqrt(vy*vy+2*G*H1)-vy)/G; + } + x=t*vx; + printf("%.3lf\n",x); + } + return 0; +} diff --git a/HDOJ/2604_autoAC.cpp b/HDOJ/2604_autoAC.cpp new file mode 100644 index 0000000..ea1fd17 --- /dev/null +++ b/HDOJ/2604_autoAC.cpp @@ -0,0 +1,64 @@ +#include +#include +#define ll long long +#define Max 4 +int mod; +struct Matrix +{ + int mm[Max][Max]; +}A,I; +Matrix matrixmul(Matrix a,Matrix b) +{ + int i,j,k; + Matrix c; + for (i = 0 ; i <= 3; i++) + for (j = 0; j <= 3;j++) + { + c.mm[i][j] = 0; + for (k = 0; k <= 3; k++) + c.mm[i][j] += (a.mm[i][k] * b.mm[k][j])%mod; + c.mm[i][j]%=mod; + } + return c; +} +Matrix quickpagow(int n) +{ + Matrix m = A, b = I; + while (n >= 1) + { + if (n & 1) + b = matrixmul(b,m); + n = n >> 1; + m = matrixmul(m,m); + } + return b; +} +int main () +{ + int n; + A.mm[0][0]=1,A.mm[0][1]=0,A.mm[0][2]=1,A.mm[0][3]=1; + A.mm[1][0]=1,A.mm[1][1]=0,A.mm[1][2]=0,A.mm[1][3]=0; + A.mm[2][0]=0,A.mm[2][1]=1,A.mm[2][2]=0,A.mm[2][3]=0; + A.mm[3][0]=0,A.mm[3][1]=0,A.mm[3][2]=1,A.mm[3][3]=0; + I.mm[0][0]=1,I.mm[0][1]=0,I.mm[0][2]=0,I.mm[0][3]=0; + I.mm[1][0]=0,I.mm[1][1]=1,I.mm[1][2]=0,I.mm[1][3]=0; + I.mm[2][0]=0,I.mm[2][1]=0,I.mm[2][2]=1,I.mm[2][3]=0; + I.mm[3][0]=0,I.mm[3][1]=0,I.mm[3][2]=0,I.mm[3][3]=1; + while(scanf("%d %d",&n,&mod)!=EOF) + { + if(n==1) + printf("%d\n",2%mod); + else if(n==2) + printf("%d\n",4%mod); + else if(n==3) + printf("%d\n",6%mod); + else if(n==4) + printf("%d\n",9%mod); + else + { + Matrix c=quickpagow(n-4); + printf("%d\n",((c.mm[0][0]*9)%mod+(c.mm[0][1]*6)%mod+(c.mm[0][2]*4)%mod+(c.mm[0][3]*2)%mod)%mod); + } + } + return 0; +} diff --git a/HDOJ/2606_autoAC.cpp b/HDOJ/2606_autoAC.cpp new file mode 100644 index 0000000..cf097f0 --- /dev/null +++ b/HDOJ/2606_autoAC.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +int ans[111]; +void init() +{ + int i,l; + ans[0]=1; + ans[1]=1; + ans[2]=ans[1]+4*ans[0]; + ans[3]=ans[2]+4*ans[1]+2*ans[0]+2*ans[0]; + for(i=4;i<=100;i++) + { + ans[i]=(ans[i-1]+4*ans[i-2]+2*ans[i-3]+ans[i-4])%19890907; + for(l=3;l<=i;l++) ans[i]=(ans[i]+2*ans[i-l])%19890907; + } + return ; +} +int main() +{ + init(); + int T,n; + scanf("%d",&T); + while(T--) + { + scanf("%d",&n); + printf("%d\n",ans[n]); + } + return 0; +} diff --git a/HDOJ/2607_autoAC.cpp b/HDOJ/2607_autoAC.cpp new file mode 100644 index 0000000..260ad07 --- /dev/null +++ b/HDOJ/2607_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#include +#define maxn 100002 +int X[maxn], Y[maxn], Z[maxn]; +char buf[40]; +int main() { + // freopen("data.in", "r", stdin); + int i, id = 0, cnt = 0, ret = 0; // id璁板版涓℃, ret璁板缁缁 + while (gets(buf)) { + if (*buf == NULL) { + if (id) + if (ret == 0) puts("None."); + else { + while (id--) { + if (ret >= X[id] && ret <= Y[id] && (ret - X[id]) % Z[id] == 0) + ++cnt; + } + printf("%d %d\n", ret, cnt); + } + id = cnt = ret = 0; + continue; + } + sscanf(buf, "%d%d%d", &X[id], &Y[id], &Z[id]); + for (i = X[id]; i <= Y[id]; i += Z[id]) + ret ^= i; + ++id; + } + if (id) + if (ret == 0) puts("None."); + else { + while (id--) { + if (ret >= X[id] && ret <= Y[id] && (ret - X[id]) % Z[id] == 0) + ++cnt; + } + printf("%d %d\n", ret, cnt); + } + return 0; +} diff --git a/HDOJ/2608_autoAC.cpp b/HDOJ/2608_autoAC.cpp new file mode 100644 index 0000000..795d597 --- /dev/null +++ b/HDOJ/2608_autoAC.cpp @@ -0,0 +1,27 @@ +#include +int main() +{ + int n,k,i,num; + scanf("%d",&n); + while(n--) + { + num=0; + scanf("%d",&k); + for(i=1;i<=k;i++) + { + if(i*i<=k) + num++; + else + break; + } + for(i=1;i<=k;i++) + { + if(2*i*i<=k) + num++; + else + break; + } + printf("%d\n",num%2); + } + return 0; +} diff --git a/HDOJ/2609_autoAC.cpp b/HDOJ/2609_autoAC.cpp new file mode 100644 index 0000000..7cd1c2b --- /dev/null +++ b/HDOJ/2609_autoAC.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +typedef struct TNode{ + struct TNode *left,*right; + int shit; +}Node; +Node p; +Node *root=&p; +Node *newnode() +{ + Node *u=(Node*) malloc(sizeof(Node)); + u->left=NULL; + u->right=NULL; + u->shit=0; + return u; +} +int addnode(char *s,int n) +{ + int fuck=0,i; + Node *u=root; + for(i=0;ileft==NULL) + u->left=newnode(); + u=u->left; + if(u->shit==0) {fuck=1;u->shit=1;} + } + else if(s[i]=='1') + { + if(u->right==NULL) + u->right=newnode(); + u=u->right; + if(u->shit==0) {fuck=1;u->shit=1;} + } + } + return fuck; +} +int min(int x,int y) +{ + if(x<=y) + return x; + return y; +} +int huiliyi(char *s,int n) +{ + int i,j,k,t; + i=0;j=1;k=0; + while(ileft); + remove(u->right); + u->shit=0; +} +int main() +{ + int t,sum,n,x,i,j; + char s[105],c[105]; + while(scanf("%d",&t)==1) + { + getchar(); + sum=0; + while(t--) + { + scanf("%s",s); + n=strlen(s); + x=huiliyi(s,n); + j=0; + for(i=x;ileft); + remove(root->right); + } + return 0; +} diff --git a/HDOJ/2610_autoAC.cpp b/HDOJ/2610_autoAC.cpp new file mode 100644 index 0000000..00c90cf --- /dev/null +++ b/HDOJ/2610_autoAC.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include +using namespace std; +int n,p,len,count_num; +int num[1001]; +bool flag; +typedef struct +{ + int n,pos; +}Tem; +Tem tem[1001]; +bool check(int s,int e) +{ + for(int i = s+1; i < e; i++) + if(num[i]==num[e])return false; + return true; +} +void print_sequence(int length) +{ + for(int i = 0; i < length-1;i++) + cout<= p)return; + if(dep==len) + { + count_num++; + flag = true; + print_sequence(len); + return; + } + for(int i=pos;i>n>>p) + { + for(int i=0;i>num[i]; + count_num = 0; + for(int i = 1;i < n;i++) + { + flag=false; + len = i; + dfs(0,0); + if(count_num>=p||!flag)break; + } + cout< +#include +#include +#include +#include +#include +using namespace std; +int a[1001]; +int n,p,len,tmp; +struct node { + int num; + int pos; +}; +node tree[1001]; +bool cmp(const node& x,const node& y) +{ + if(x.num!=y.num) + return x.numn) + return false; + for(i=pos;i pp ) + { + if(!flag) + { + pre=tree[i].num; + flag=true; + } + else if(pre == tree[i].num) + continue; + pre=tree[i].num; + a[deep]=tree[i].num; + if(dfs(deep+1,i+1,tree[i].pos)) + return true; + } + } + return false; +} +int main() +{ + while(~scanf("%d%d",&n,&p)) + { + int tc; + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct node +{ + int x,y; + int time; +}; + int n,m; +queue qq; +char tm[205][205]; +char vis[205][205]; +int kfc[2005][2]; +int ans1[505][505]; +int ans2[505][505]; +int ans[505][505][3]; + int dir[][2]={0,-1, 0,1, -1,0, 1,0}; + int y11,y2; + int m1,m2; +int bfs(int f,int c) +{ + while(!qq.empty()) qq.pop(); + int i; + node tmp; + tmp.x=f; + tmp.y=c; + tmp.time=0; + qq.push(tmp); + vis[f][c]=1; + while(!qq.empty()) + { + node t=qq.front(); + qq.pop(); + node k=t; + for (i=0;i<4;i++) + { + t=k; + t.x+=dir[i][0]; + t.y+=dir[i][1]; + if ((tm[t.x][t.y]=='.'||tm[t.x][t.y]=='@')&&vis[t.x][t.y]==0&& t.x>=1 &&t.y<=m&&t.y>=1&&t.x<=n) + { + vis[t.x][t.y]=1; + t.time++; + { + if ( f==y11 && c==y2 ) + { + ans[t.x][t.y][0]=t.time; + } + else + { + ans[t.x][t.y][1]=t.time; + } + } + qq.push(t); + } + } + } + return 0; +} +int main() +{ + int i,j; + while(scanf("%d%d",&n,&m)!=EOF) + { + getchar(); + int ok=0; + for (i=1;i<=n;i++) + { + for (j=1;j<=m;j++) + { + scanf("%c",&tm[i][j]); + if (tm[i][j]=='Y') + { + y11=i; + y2=j; + } + if (tm[i][j]=='M') + { + m1=i; + m2=j; + } + if (tm[i][j]=='@') + { + kfc[++ok][0]=i; + kfc[ok][1]=j; + } + } + getchar(); + } + int max=0x7f7f7f7f; + int h; + memset(vis,0,sizeof(vis)); + bfs(y11,y2); + memset(vis,0,sizeof(vis)); + bfs(m1,m2); + for (h=1;h<=ok;h++) + { + int q1=kfc[h][0]; + int q2=kfc[h][1]; + max=__min(ans[q1][q2][0]+ans[q1][q2][1],max); + } + __int64 ans=max*11; + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/2614_autoAC.cpp b/HDOJ/2614_autoAC.cpp new file mode 100644 index 0000000..1e71fb3 --- /dev/null +++ b/HDOJ/2614_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +int flag[16]; +int map[16][16],sum,n; +int max(int a,int b) +{ + return a>b?a:b; +} +void dfs(int th,int num,int time) +{ + for(int i=0;i +int n,m,min; +int ai[10],mi[10],used[10]; +int dfs(int dep,int hp) +{ + int i; + if(hp<=0) + { + if(dep-1=min) return 0; + for(i=1;i<=n;i++) + if(used[i]==0) + { + used[i]=1; + if(hp<=mi[i]) + dfs(dep+1,hp-2*ai[i]); + else + dfs(dep+1,hp-ai[i]); + used[i]=0; + } +} +int main() +{ + int i; + while(scanf("%d%d",&n,&m)!=EOF) + { + for(i=1;i<=n;i++) scanf("%d%d",&ai[i],&mi[i]); + for(i=1;i<=n;i++) used[i]=0; + min=n+1; + dfs(1,m); + if(min==n+1) min=-1; + printf("%d\n",min); + } +} diff --git a/HDOJ/2617_autoAC.cpp b/HDOJ/2617_autoAC.cpp new file mode 100644 index 0000000..3707bb2 --- /dev/null +++ b/HDOJ/2617_autoAC.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define M 100005 +char a[M]; +int main() +{ + int i,l,t,k; + int ji[30]; + while(gets(a)) + { + memset(ji,0,sizeof(ji)); + l=strlen(a);t=0; + for(i=0;i +#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 ROP freopen("input.txt", "r", stdin); +#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 = 1e7 + 2; +const int MOD = 1e9 + 7; +const int dir[][2] = { {-1, 0}, {0, -1}, { 1, 0 }, { 0, 1 } }; +int cases = 0; +typedef pair pii; +LL get_phi(int n) +{ + int m = (int)sqrt(n+0.5); + int ans = n; + for (int i = 2; i <= m; i++) if (n % i == 0) + { + ans = ans / i * (i-1); + while (n % i == 0) n /= i; + } + if (n > 1) ans = ans / n * (n-1); + return ans; +} +int main() +{ + int n; + while (~scanf("%d", &n)) + { + printf("%d\n", get_phi(get_phi(n))); + } + return 0; +} diff --git a/HDOJ/2620_autoAC.cpp b/HDOJ/2620_autoAC.cpp new file mode 100644 index 0000000..d65a652 --- /dev/null +++ b/HDOJ/2620_autoAC.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +typedef long long LL; +int main() +{ + LL n,k; + while(~scanf("%I64d%I64d",&n,&k)){ + LL ans=n*k; + if(n>k) n=k; + for(LL i=1;i<=n;){ + LL d=k/i; + LL j=k/d; + if(j>n) j=n; + ans-=d*(i+j)*(j-i+1)/2; + i=j+1; + } + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/2621_autoAC.cpp b/HDOJ/2621_autoAC.cpp new file mode 100644 index 0000000..8ba3a1a --- /dev/null +++ b/HDOJ/2621_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include + __int64 C(__int64 n, __int64 m) + { + __int64 i, j; + if (m > n/2) m = n - m; + for (i = 1, j = 1;i <= m; i++) + { + j = j * (n + 1 - i) / i; + } + return j; + } +int main () +{ + int i,j,t; + __int64 k1,k2,k; + __int64 m,n; + while(scanf("%I64d%I64d",&n,&m)!=EOF&&n||m) + { + t=m>n?n:m; + printf("%I64d\n",C(m+n,t)); + } + return 1; +} diff --git a/HDOJ/2626_autoAC.cpp b/HDOJ/2626_autoAC.cpp new file mode 100644 index 0000000..bc5cb22 --- /dev/null +++ b/HDOJ/2626_autoAC.cpp @@ -0,0 +1,35 @@ +#include +int main() +{ + int t,n; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + printf("Samuel will "); + switch(n) + { + case 13:printf("take test.\n");break; + case 9:printf("buy food.\n");break; + case 5:printf("meet friends.\n");break; + case 1:printf("decorate.\n");break; + case -3:printf("visit relative.\n");break; + case 12:printf("go home.\n");break; + case 8:printf("stay at home.\n");break; + case 4:printf("go to movies.\n");break; + case 0:printf("go out.\n");break; + case -4:printf("visit relative.\n");break; + case 11:printf("stay at home.\n");break; + case 7:printf("visit teachers.\n");break; + case 3:printf("stay at home.\n");break; + case -1:printf("be in the park.\n");break; + case -5:printf("stay at home.\n");break; + case 10:printf("buy clothes.\n");break; + case 6:printf("go to KTV.\n");break; + case 2:printf("decorate.\n");break; + case -2:printf("stay at home.\n");break; + case -6:printf("prepare dinner.\n");break; + } + } + return 0; +} diff --git a/HDOJ/2627_autoAC.cpp b/HDOJ/2627_autoAC.cpp new file mode 100644 index 0000000..919293a --- /dev/null +++ b/HDOJ/2627_autoAC.cpp @@ -0,0 +1,37 @@ +#include +int main() +{ + int t,n,i; + char a[100]; + int b[100]; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + getchar(); + scanf("%s",a); + int sum=0,p=0; + for(i=0;i0&&sum<20)printf("and he will stay in the prison for 3 year(s).\n"); + else if(sum>=20&&sum<30)printf("and he will stay in the prison for 5 year(s).\n"); + else if(sum>=30&&sum<40)printf("and he will stay in the prison for 10 year(s).\n"); + else if(sum>=40&&sum<50)printf("and he will stay in the prison for 15 year(s).\n"); + else if(sum>=50&&sum<60)printf("and he will stay in the prison for 20 year(s).\n"); + else if(sum>=60&&sum<70)printf("and he will stay in the prison for 25 year(s).\n"); + else if(sum>=70&&sum<80)printf("and he will stay in the prison for 30 year(s).\n"); + else if(sum>=80&&sum<90)printf("and he will stay in the prison for 35 year(s).\n"); + else + printf("and he will stay in the prison for 40 year(s).\n"); + } + return 0; +} diff --git a/HDOJ/2628_autoAC.cpp b/HDOJ/2628_autoAC.cpp new file mode 100644 index 0000000..0f0661a --- /dev/null +++ b/HDOJ/2628_autoAC.cpp @@ -0,0 +1,16 @@ +#include +int main() +{ + int t; + double n,m; + scanf("%d",&t); + while(t--) + { + scanf("%lf%lf",&n,&m); + if(n*52>=m) + printf("Oh,Samuel's hope will come true,thanks to the DcSLs.\n"); + else + printf("Unfortunately,Samuel's hope will not come true,more tourists are welcomed!\n"); + } + return 0; +} diff --git a/HDOJ/2629_autoAC.cpp b/HDOJ/2629_autoAC.cpp new file mode 100644 index 0000000..fb6711c --- /dev/null +++ b/HDOJ/2629_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +int main() +{ + int n; + int s[20],i,len; + char str[20]; + scanf("%d%*c",&n); + while(n--) + { + gets(str); + len = strlen(str); + for(i = 0;i +#include +char name[6][20]={"S.H.E","Jay","Elva","Jolin","Aska","Yoga"},temp[20]; +int main(){ + int T,n,s,h,m,h1,h2;scanf("%d",&T); + while(T--){ + scanf("%d",&n); + s=m=0; + while(n--) + { + scanf("%s %d:%d",temp,&h1,&h2); + for(int i=0;i<6;i++) + if(strcmp(temp,name[i])==0) m+=h1,s+=h2; + } + m+=s/60;s%=60; + h=m/60;m%=60; + printf("Samuel will watch Channel[V] for %d hour(s),%d minute(s),%d second(s).\n",h,m,s); + } + return 0; +} diff --git a/HDOJ/2631_autoAC.cpp b/HDOJ/2631_autoAC.cpp new file mode 100644 index 0000000..82f0f99 --- /dev/null +++ b/HDOJ/2631_autoAC.cpp @@ -0,0 +1,24 @@ +#include +int main() +{ + int t,h1,m1,h2,m2,n,t1,dh,flag; + char c; + scanf("%d",&t); + while(t--&&scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2)) + { + flag=1; + if(h1-12<0)flag=0; + if(h2480)flag=0; + scanf("%d%*c",&n); + if(n<8)flag=0; + scanf("%c%*c",&c); + if(c!='T')flag=0; + scanf("%c%*c",&c); + if(c!='T')flag=0; + if(flag)printf("Health life,NeverGone you should keep doing!\n"); + else printf("NeverGone should pay attention to his health!\n"); + } +} diff --git a/HDOJ/2632_autoAC.cpp b/HDOJ/2632_autoAC.cpp new file mode 100644 index 0000000..4f0c197 --- /dev/null +++ b/HDOJ/2632_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#define N 1000010 +#define esp 1e-10 +using namespace std; +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + double x,a,b; + scanf("%lf%lf%lf",&x,&a,&b); + int ans=0; + while(x*(1-b)>=a+esp) + { + ans++; + x*=(1-b); + } + printf("Samuel will change the appearance for %d time(s),before he decide to sell it.\n",ans); + } + return 0; +} diff --git a/HDOJ/2634_autoAC.cpp b/HDOJ/2634_autoAC.cpp new file mode 100644 index 0000000..3f845bf --- /dev/null +++ b/HDOJ/2634_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ +double a,sum; +int n, i,ca; +scanf("%d", &ca); +while (ca--) { +scanf("%d", &n); +sum = 0; +for (i = 0; i < n; ++i) { +scanf("%lf", &a); +sum += a; +} +printf("The average M = %.10lf.\n", sum / n); +} +return 0; +} diff --git a/HDOJ/2635_autoAC.cpp b/HDOJ/2635_autoAC.cpp new file mode 100644 index 0000000..11b2a1b --- /dev/null +++ b/HDOJ/2635_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +struct ss +{ + char a[100]; + int r,x,y,flag; +}s[10000]; +int main() +{ + int t,n,i,k1,k2,k3,max; + scanf("%d",&t); + while(t--&&scanf("%d",&n)) + { + for(i=0;imax){max=s[i].r;} + } + k1=max;max=0; + for(i=0;imax){k3=i;max=s[i].y;} + } + printf("The latest distribution Samuel will choose is %s.\n",s[k3].a); + } + return 0; +} diff --git a/HDOJ/2637_autoAC.cpp b/HDOJ/2637_autoAC.cpp new file mode 100644 index 0000000..ffbce0a --- /dev/null +++ b/HDOJ/2637_autoAC.cpp @@ -0,0 +1,15 @@ +#include +int main() +{ + int i,t,k,a,b,n; + scanf("%d",&t); + while(t--) + { + scanf("%d%d%d",&n,&a,&b); + k=1; + for(i=0;i +#include +int main() +{ + char nek[1000],bf[1000]; + int i,j,l,k; + int as,bs,c1,c2; + int ap,bp; + int max; + int t; + while(scanf("%d",&t)!=EOF) + { + while(t--) + { + max=0; + as=0; + bs=1; + scanf("%s",nek); + strcpy(bf,nek); + l=strlen(nek); + while(bsj;i--,j++) + { + if(nek[i]=='w'&&as) + { + c1++; + } + if(nek[j]=='w'&&bs) + { + c2++; + } + if(nek[i]=='p'&&as) + { + if(ap==0||ap==1) + { + ap=1; + c1++; + }else + {as=0; + } + } + if(nek[j]=='p'&&bs) + { + if(bp==0||bp==1) + { + bp=1; + c2++; + }else + { + bs=0; + } + } + if(nek[i]=='r'&&as) + { + if(ap==0||ap==2) + { + ap=2; + c1++; + }else + as=0; + } + if(nek[j]=='r'&&bs) + { + if(bp==0||bp==2) + { + bp=2; + c2++; + }else + { + bs=0; + } + } + } + if(max +#include +#include +#include +#define MAXN 105 +#define MAXV 1005 +int MyMax(int a,int b) +{ + return (a>b?a:b); +} +int main() +{ + int t,n,v,m; + while(scanf("%d",&t)!=EOF) + { + while(t--) + { + int i,j,k,tag; + int val[MAXN],vol[MAXN],dp[MAXV][35]; + int a[35],b[35]; + scanf("%d%d%d",&n,&v,&m); + for(i=1;i<=n;i++) + { + scanf("%d",&val[i]); + } + for(i=1;i<=n;i++) + { + scanf("%d",&vol[i]); + } + memset(dp,0,sizeof(dp)); + tag=1; + for(i=1;i<=n;i++) + { + for(j=v;j>=vol[i];j--) + { + for(k=1;k<=m;k++) + { + a[k]=dp[j-vol[i]][k]+val[i]; + b[k]=dp[j][k]; + } + int x,y,z; + x=y=z=1; + a[k]=b[k]=-1; + while(z<=m&&(y<=m||x<=m)) + { + if(a[x]>b[y]) + { + dp[j][z]=a[x++]; + } + else + { + dp[j][z]=b[y++]; + } + if(dp[j][z]!=dp[j][z-1]) + { + z++; + } + } + } + } + printf("%d\n",dp[v][m]); + } + } + return (0); +} diff --git a/HDOJ/2640_autoAC.cpp b/HDOJ/2640_autoAC.cpp new file mode 100644 index 0000000..50b644e --- /dev/null +++ b/HDOJ/2640_autoAC.cpp @@ -0,0 +1,3 @@ + @ +@@@ + @ diff --git a/HDOJ/2642_autoAC.cpp b/HDOJ/2642_autoAC.cpp new file mode 100644 index 0000000..dd1f1a3 --- /dev/null +++ b/HDOJ/2642_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +using namespace std; +const int N=1010; +int c[N][N]; +bool vis[N][N]; +int lowbit(int x) +{ + return x&(-x); +} +void add(int x,int y,int val) +{ + int i=y; + while(x<=N) + { + y=i; + while(y<=N) + { + c[x][y]+=val; + y+=lowbit(y); + } + x+=lowbit(x); + } +} +int sum(int x,int y) +{ + int i,sum=0; + i=y; + while(x) + { + y=i; + while(y) + { + sum+=c[x][y]; + y-=lowbit(y); + } + x-=lowbit(x); + } + return sum; +} +int main() +{ + int n,x1,x2,y1,y2; + scanf("%d",&n); + memset(c,0,sizeof(c)); + memset(vis,0,sizeof(vis)); + while(n--) + { + getchar(); + char c; + scanf("%c ",&c); + if(c=='Q') + { + scanf("%d%d%d%d",&x1,&x2,&y1,&y2); + x1++,x2++,y1++,y2++; + if(x1>x2)swap(x1,x2); + if(y1>y2)swap(y1,y2); + printf("%d\n",(sum(x2,y2)+sum(x1-1,y1-1)-sum(x1-1,y2)-sum(x2,y1-1))); + } + else if(c=='B') + { + scanf("%d%d",&x1,&y1); + if(vis[x1+1][y1+1]==1) + continue; + else + add(x1+1,y1+1,1); + vis[x1+1][y1+1]=1; + } + else if(c=='D') + { + scanf("%d%d",&x1,&y1); + if(vis[x1+1][y1+1]==0) + continue; + else + add(x1+1,y1+1,-1); + vis[x1+1][y1+1]=0; + } + } + return 0; +} diff --git a/HDOJ/2643_autoAC.cpp b/HDOJ/2643_autoAC.cpp new file mode 100644 index 0000000..f6b4c42 --- /dev/null +++ b/HDOJ/2643_autoAC.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; +const int N=110; +__int64 dp[N][N],fact[N]; +__int64 bell[N]; +const int mod=20090126; +void init() +{ + int i,j; + fact[0]=1; + for(i=1;i<=100;i++) + { + fact[i]=fact[i-1]*i%mod; + } + for(i=0;i<=100;i++) dp[i][1]=dp[i][i]=1; + for(i=2;i<=100;i++) //绗浜绫 + { + for(j=1;j>t; + while(t--) + { + cin>>n; + printf("%I64d\n",bell[n]); + } + return 0; +} diff --git a/HDOJ/2645_autoAC.cpp b/HDOJ/2645_autoAC.cpp new file mode 100644 index 0000000..8737227 --- /dev/null +++ b/HDOJ/2645_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#define N 333 +using namespace std; +int n,m; +char map[N][N]; +int dis[N][N],flag[N][N]; +int dir[4][2]={1,0, -1,0, 0,1, 0,-1}; +struct node +{ + int x,y; +}; +void solve() +{ + queueq; + node now,next; + memset(dis,0,sizeof(dis)); + memset(flag,0,sizeof(flag)); + int i,l; + for(i=0;i=n || next.y<0 || next.y>=m) continue; + if(flag[next.x][next.y]) continue; + q.push(next); + flag[next.x][next.y]=1; + dis[next.x][next.y]=dis[now.x][now.y]+1; + } + } +} +int main() +{ + int i,l; + while(scanf("%d%d",&n,&m)!=-1) + { + solve(); + for(i=0;i +#include +struct A +{ + int ts; + int outdegree; + int total; + int mem[15]; +}E[10011]; +int max(int a,int b) +{ + return a>b?a:b; +} +int topsort(int n) +{ + int k,i,j; + int flag; + int temp; + k=0; + while(k +#include +#include +#include +using namespace std; +typedef struct shop +{ + int price; + char name[35]; +}shop; +shop a[10005]; +shop M; +bool cmp(shop b,shop c) +{ + return strcmp(b.name,c.name)>0; +} +int erfen(int n,char s[]) +{ + int low=1,high=n,t; + while(low<=high) + { + t=(low+high)/2; + if(strcmp(s,a[t].name)==0) + break; + else if(strcmp(s,a[t].name)>0) + high=t-1; + else + low=t+1; + } + return t; +} +int main() +{ + int n,m,count; + int i,j; + char s[35]; + int price,tem; + while(scanf("%d",&n)!=EOF) + { + for(i=1;i<=n;i++) + { + scanf("%s",a[i].name); + a[i].price=0; + } + M.price=0; + scanf("%d",&m); + sort(a+1,a+n+1,cmp); + for(i=1;i<=m;i++) + { + for(j=1;j<=n;j++) + { + scanf("%d%s",&price,s); + if(strcmp(s,"memory")==0) + { + M.price+=price; + } + tem=erfen(n,s); + a[tem].price+=price; + } + count=0; + for(j=1;j<=n;j++) + { + if(a[j].price>M.price) + count++; + } + printf("%d\n",count+1); + } + } +} diff --git a/HDOJ/2650_autoAC.cpp b/HDOJ/2650_autoAC.cpp new file mode 100644 index 0000000..d6c5b71 --- /dev/null +++ b/HDOJ/2650_autoAC.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +const int Times=10; +using namespace std; +typedef long long LL; +LL multi(LL a,LL b,LL m) +{ + LL ans=0; + while(b) + { + if(b&1) + { + ans=(ans+a)%m; + b--; + } + b>>=1; + a=(a+a)%m; + } + return ans; +} +LL quick_mod(LL a,LL b,LL m) +{ + LL ans=1; + a%=m; + while(b) + { + if(b&1) + { + ans=multi(ans,a,m); + b--; + } + b>>=1; + a=multi(a,a,m); + } + return ans; +} +bool Miller_Rabin(LL n) +{ + if(n==2) return true; + if(n<2||!(n&1)) return false; + LL a,m=n-1,x,y; + int k=0; + while((m&1)==0) + { + k++; + m>>=1; + } + for(int i=0;i +#include +using namespace std; +int sum=0; +struct TireTree +{ + int num; + TireTree *next[9]; +}; +int Change(int a[],char str[]) +{ + int i,k=0,len=strlen(str),t=1; + for(i=1;inext[a[i]]!=NULL) + current=current->next[a[i]]; + else + { + TireTree *NewNode=new TireTree; + NewNode->num=0; + for(int j=0;j<9;j++) NewNode->next[j]=NULL; + current->next[a[i]]=NewNode; + current=NewNode; + } + i++; + } + current->num++; +} +void GetSum(TireTree *root) +{ + int temp=root->num; + sum+=(temp)*(temp-1)/2; + for(int k=0;k<9;++k) + if(root->next[k]) + GetSum(root->next[k]); +} +int main() +{ + int a[8],n,i,k; + char str[8]; + while(cin>>n) + { + TireTree *root=new TireTree; + root->num=0; + for(k=0;k<9;++k) root->next[k]=NULL; + sum=0; + for(i=0;i>str; + k=Change(a,str); + Insert(root,a,k); + } + GetSum(root); + cout< +#include +using namespace std; +struct Node{ + int a,b,c; +}; +bool com(Node &a,Node &b){ + return a.a=1;i--){ + kan[i]=no[i]=0; + int begin=i; + int end=number; + while(beginnodes[i].b){ + end=mid; + }else{ + begin=mid+1; + } + } + if(nodes[end].a>nodes[i].b){ + kan[i]=nodes[i].c+(kan[end]>no[end]?kan[end]:no[end]); + }else{ + kan[i]=nodes[i].c; + } + no[i]=(kan[i+1]>no[i+1]?kan[i+1]:no[i+1]); + } + printf("%d\n",kan[1]>no[1]?kan[1]:no[1]); + } +} diff --git a/HDOJ/2653_autoAC.cpp b/HDOJ/2653_autoAC.cpp new file mode 100644 index 0000000..26de55b --- /dev/null +++ b/HDOJ/2653_autoAC.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +using namespace std; +char g[100][100]; +bool vis[88][88][88]; +int n,m,p,t,si,sj,ans; +int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; +struct node +{ + int step,p,x,y; + node(int a=0,int b=0,int c=0,int d=0):x(a),y(b),p(c),step(d){} + bool friend operator <(const node a,const node b) + { + return a.step>b.step; + } +}; +void BFS() +{ + priority_queue Q; + node f=node(si,sj,p,0); + Q.push(f); + memset(vis,false,sizeof(vis)); + vis[si][sj][p]=true; + node temp; + while(!Q.empty()) + { + temp=Q.top(); + Q.pop(); + if(temp.step>t) + return ; + if(g[temp.x][temp.y]=='L') + { + ans=temp.step; + return ; + } + for(int k=0;k<4;k++) + { + int i=dir[k][0]+temp.x; + int j=dir[k][1]+temp.y; + if(i<0||i>n-1 || j<0 || j>m-1||g[i][j]=='#') + continue; + if(temp.p!=0 && !vis[i][j][temp.p-1]) + { + vis[i][j][temp.p-1]=true; + Q.push(node(i,j,temp.p-1,temp.step+1)); + } + if(g[temp.x][temp.y]!='@' && g[i][j]!='@'&&!vis[i][j][temp.p]) + { + vis[i][j][temp.p]=true; + Q.push(node(i,j,temp.p,temp.step+2)); + } + } + } + return ; +} +int main() +{ + int cas=0; + while(scanf("%d %d %d %d",&n,&m,&t,&p)==4) + { + for(int i=0;it) + printf("Poor Yifenfei, he has to wait another ten thousand years.\n"); + else printf("Yes, Yifenfei will kill Lemon at %d sec.\n",ans); + } + return 0; +} diff --git a/HDOJ/2656_autoAC.cpp b/HDOJ/2656_autoAC.cpp new file mode 100644 index 0000000..bc397d1 --- /dev/null +++ b/HDOJ/2656_autoAC.cpp @@ -0,0 +1,59 @@ +#include +#include +int X, K; +struct Integer +{ + int a[32]; + void init(int x) + { + int i; + for(i = 0; i < 32; i ++) + { + a[i] = x % 2; + x /= 2; + } + } + void getnext() + { + int i, j, cnt = 0; + for(i = 0;; i ++) + if(a[i] == 1) + { + if(a[i + 1] == 0) + { + a[i + 1] = 1; + for(j = 0; j <= i; j ++) + { + if(cnt) + -- cnt, a[j] = 1; + else + a[j] = 0; + } + break; + } + ++ cnt; + } + } +}integer; +void solve() +{ + int i; + long long int ans = 0; + integer.init(X); + for(i = 0; i < K; i ++) + integer.getnext(); + for(i = 31; i >= 0; i --) + ans = ans * 2 + integer.a[i]; + printf("%I64d\n", ans); +} +int main() +{ + for(;;) + { + scanf("%d%d", &X, &K); + if(!X && !K) + break; + solve(); + } + return 0; +} diff --git a/HDOJ/2660_autoAC.cpp b/HDOJ/2660_autoAC.cpp new file mode 100644 index 0000000..6aaf8c1 --- /dev/null +++ b/HDOJ/2660_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +struct node +{ + int v,w; +}p[50]; +int maxn,n,k,weight,vis[50]; +void dfs(int wei,int val,int step,int sum) +{ + if(sum == k || wei == weight) + { + if(maxn +using namespace std; +typedef unsigned long long int longint; +int main() +{ + int t; + cin >> t; + while (t--) + { + longint n, m; + cin >> n >> m; + longint ans; + ans = (n * m) - n - m; + cout << ans << endl; + } + return 0; +} diff --git a/HDOJ/2665_autoAC.cpp b/HDOJ/2665_autoAC.cpp new file mode 100644 index 0000000..f5d010b --- /dev/null +++ b/HDOJ/2665_autoAC.cpp @@ -0,0 +1,73 @@ +#include +#include +#define N 100010 +int T[N]; +int num[N]; +int san[N]; +int ls[N*20]; +int rs[N*20]; +int sum[N*20]; +int tot,rt; +int n, m; +void Build(int l,int r,int &rt) +{ + rt=++tot; + sum[rt]=0; + if(l==r) return ; + int m=(l+r)>>1; + Build(l,m,ls[rt]); + Build(m+1,r,rs[rt]); +} +void Update(int last,int p,int l,int r,int &rt) +{ + rt=++tot; + ls[rt]=ls[last]; + rs[rt]=rs[last]; + sum[rt]=sum[last]+1; + if(l==r) return ; + int m=(l+r)>>1; + if(p<=m) Update(ls[last],p,l,m,ls[rt]); + else Update(rs[last],p,m+1,r,rs[rt]); +} +int Query(int ss,int tt,int l,int r,int k) +{ + if(l==r) return l; + int m=(l+r)>>1; + int cnt=sum[ls[tt]]-sum[ls[ss]]; + if(k<=cnt) + return Query(ls[ss],ls[tt],l,m,k); + else + return Query(rs[ss],rs[tt],m+1,r,k-cnt); +} +void gogogo() +{ + int l,r,k; + for(int i=1;i<=n;i++) + { + scanf("%d",&num[i]); + san[i]=num[i]; + } + tot=0; + std::sort(san+1,san+n+1); + int cnt=std::unique(san+1,san+n+1)-san-1; + Build(1,cnt,T[0]); + for(int i=1;i<=n;i++) num[i]=std::lower_bound(san+1,san+cnt+1,num[i])-san; + for(int i=1;i<=n;i++) Update(T[i-1],num[i],1,cnt,T[i]); + while(m--) + { + scanf("%d%d%d",&l,&r,&k); + int id=Query(T[l-1],T[r],1,cnt,k); + printf("%d\n",san[id]); + } +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&m); + gogogo(); + } + return 0; +} diff --git a/HDOJ/2668_autoAC.cpp b/HDOJ/2668_autoAC.cpp new file mode 100644 index 0000000..716a9c2 --- /dev/null +++ b/HDOJ/2668_autoAC.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +using namespace std; +const int MAX=10000000+10; +char s[MAX]; +int pos[500]; +int main(){ + int n; + while(scanf("%d",&n)!=EOF){ + scanf("%s",s); + memset(pos,-1,sizeof pos); + int st=0,ed=0,len=0,temp=0; + for(int i=0;i=temp){ + if(i-temp>len){len=i-temp,st=temp,ed=i-1;} + temp=pos[s[i]]+1; + } + pos[s[i]]=i; + } + if(n-temp>len){len=n-temp,st=temp,ed=n-1;} + printf("%d %d %d\n",len,st,ed); + } + return 0; +} diff --git a/HDOJ/2669_autoAC.cpp b/HDOJ/2669_autoAC.cpp new file mode 100644 index 0000000..4b39fc4 --- /dev/null +++ b/HDOJ/2669_autoAC.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +typedef long long LL; +LL gcd(LL a, LL b) +{ + return b ? gcd(b, a%b) : a; +} +LL extend_gcd(LL a, LL b, LL &x, LL &y) +{ + if (b == 0) + { + x = 1; + y = 0; + return a; + } + LL d = extend_gcd(b, a%b, x, y); + LL t = x; + x = y; + y = t- a/b *y; + return d; +} +int main() +{ + LL a, b; + while (cin >> a >> b) + { + if (gcd(a, b) != 1) + cout << "sorry" << endl; + else + { + LL x, y; + extend_gcd(a, b, x, y); + while (x <= 0) + { + x+= b; + y-= a; + } + cout << x << " "<< y<< endl; + } + } + return 0; +} diff --git a/HDOJ/2670_autoAC.cpp b/HDOJ/2670_autoAC.cpp new file mode 100644 index 0000000..74231b5 --- /dev/null +++ b/HDOJ/2670_autoAC.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#define max(a,b) ( a>b ? a:b ) +using namespace std; +struct ha +{ + int a, b; +} s[1111]; +int haha ( ha a, ha b ) +{ + return a.b > b.b; +} +int main () +{ + int i, j, k; + int n, m, v; + int dp[1111]; + while ( ~scanf ("%d %d", &n, &m) ) + { + memset ( dp, 0, sizeof (dp)); + for ( i=0 ; i0 ; j-- ) + dp[j] = max (dp[j], dp[j-1]+s[i].a-(j-1)*s[i].b); + printf ("%d\n" ,dp[m]); + } +} diff --git a/HDOJ/2671_autoAC.cpp b/HDOJ/2671_autoAC.cpp new file mode 100644 index 0000000..807bbad --- /dev/null +++ b/HDOJ/2671_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define inf 0x6f6f6f6f +double liangdianzhijiandejuli(double ax,double ay,double x1,double y1) +{ + return sqrt((ax-x1)*(ax-x1)+(ay-y1)*(ay-y1)); +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + double ax,ay,bx,by,cx,cy,k,l; + double x1,y1,ans; + scanf("%lf",&k); + scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&cx,&cy); + if((k*ax-ay-k*cx+cy)*(k*bx-by-k*cx+cy)>0) + { + y1=(2*bx*k+by*k*k-by-2*k*cx+2*cy)/(k*k+1); + x1=bx-(y1-by)*k; + ans=liangdianzhijiandejuli(ax,ay,x1,y1); + } + else + ans=liangdianzhijiandejuli(ax,ay,bx,by); + printf("%.2lf\n",ans); + } + return 0; +} diff --git a/HDOJ/2672_autoAC.cpp b/HDOJ/2672_autoAC.cpp new file mode 100644 index 0000000..0a410ce --- /dev/null +++ b/HDOJ/2672_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + int n[11111]={0}; + n[2]=1,n[1]=1; + for(int i=3;i<11111;i++) + { + n[i]=(n[i-1]+n[i-2])%26; + } + char c[11111]; + while(gets(c)) + { + int num=0; + for(int i=0;c[i];i++) + { + if(isupper(c[i])) + { + num++; + printf("%c",isupper(c[i]+n[num])?c[i]+n[num]:c[i]+n[num]-26); + } + else + printf("%c",c[i]); + } + cout< +#include +#include +using namespace std; +int main() +{ + int n; + while(cin>>n) + { + vectorv(n),vv(n); + int i,j; + for(i=0;i>v[i]; + } + sort(v.begin(),v.end()); + int k=0; + for(i=0,j=n-1;i +#include +int arr[41]; +void init() +{ + int i; + arr[0] = 1; + for(i = 1; i<41; i++) + arr[i] = (i*arr[i-1])%2009; +} +int main(int argc, char* argv[]) +{ + int t; + init(); + while(1) + { + if(scanf("%d", &t)==EOF) + break; + if(t>=41) + { + printf("0\n"); + continue; + } + printf("%d\n", arr[t]); + } + return 0; +} diff --git a/HDOJ/2675_autoAC.cpp b/HDOJ/2675_autoAC.cpp new file mode 100644 index 0000000..923112e --- /dev/null +++ b/HDOJ/2675_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +using namespace std; +const double ee=2.718281828459; +const double eps=1e-7; +int main() +{ + double x,y; + while(scanf("%lf",&y)!=EOF) + { + double tmp=(1+log(y))/(y*ee); + double low=1+eps,hei=ee-eps,mid; + if(tmp*ee-1>eps){puts("Happy to Womens day!");continue;} + while(hei-low>eps) + { + mid=(hei+low)/2; + if(log(mid)*(y*ee)>(1+log(y))*mid) + hei=mid; + else + low=mid; + } + if(y==1)printf("%.5lf\n",(hei+low)/2); + else if(y>1) + { + double ans=(hei+low)/2; + low=ee+eps,hei=2000000000+eps; + while(hei-low>eps) + { + mid=(hei+low)/2; + if(log(mid)*(y*ee)<(1+log(y))*mid) + hei=mid; + else + low=mid; + } + printf("%.5lf %.5lf\n",ans,(hei+low)/2); + } + } + return 0; +} diff --git a/HDOJ/2677_autoAC.cpp b/HDOJ/2677_autoAC.cpp new file mode 100644 index 0000000..2190ecf --- /dev/null +++ b/HDOJ/2677_autoAC.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +using namespace std; +mapmp,has; +maphe; +char a[10010]; +int n,m,k,u; +int dfs(string s){ + if(mp.count(s))return mp[s]; + string l=he[s]; + int price=0; + for(int i=0;l[i]!='\0';i++){ + if(l[i]==' '||l[i]=='+')continue; + string g=""; + for(;l[i]!='\0'&&l[i]!=' ';i++) + g+=l[i]; + if(mp.count(g)) + price+=mp[g]; + else{ + mp.insert(make_pair(g,dfs(g))); + price+=mp[g]; + } + } + return price; +} +void dfs(string s,int t){ + if(!he.count(s)){ + has[s]-=t; + return; + } + if(has[s]>=t){ + has[s]-=t;return; + } + t=t-has[s]; + has[s]=0; + string l=he[s]; + for(int i=0;l[i]!='\0';i++){ + if(l[i]==' '||l[i]=='+')continue; + string g=""; + for(;l[i]!='\0'&&l[i]!=' ';i++) + g+=l[i]; + dfs(g,t); + } +} +void make_map(){ + map::iterator i; + for(i=he.begin();i!=he.end();i++) + mp.insert(make_pair(i->first,dfs(i->first))); +} +int main(void){ + int t; + while(~scanf("%d",&n)){ + mp.clear();has.clear();he.clear(); + for(int i=1;i<=n;i++){ + scanf("%s %d",a,&t); + mp.insert(make_pair(a,t)); + } + scanf("%d",&m); + for(int i=0;i::iterator it; + for(it=has.begin();it!=has.end();it++){ + if(it->second<0) + ans+=-(it->second)*mp[it->first]; + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/2680_autoAC.cpp b/HDOJ/2680_autoAC.cpp new file mode 100644 index 0000000..cf23a65 --- /dev/null +++ b/HDOJ/2680_autoAC.cpp @@ -0,0 +1,64 @@ +#include +#define max 1001 +#define INF 100000000 +int N; +int v[max]; +int dis[max]; +int g[max][max]; +void dijk() +{ + int i,j,mark,mindis; + for(i=0;i<=N;i++) + { + v[i] = 0; + dis[i] = INF; + } + dis[0] = 0; + v[0] = 1; + for(i=0;i<=N;i++) + { + mindis = INF; + mark = 0; + for(j=0;j<=N;j++) + if(!v[j] && dis[j] < mindis) + { + mindis = dis[j]; + mark = j; + } + v[mark] = j; + for(j=0;j<=N;j++) + if(!v[j] && dis[j] > dis[mark] + g[mark][j]) + dis[j] = dis[mark] + g[mark][j]; + } +} +int main() +{ + int W,M,Q,i,j,d,a,b; + while(~scanf("%d%d%d",&N,&M,&Q)) + { + for(i=0;i +#include +#include +#define maxn 200+10 +using namespace std; +class Girl +{ +public: + int s,t; + bool operator <(const class Girl g) + { + if(s==g.s) + return tb; +} +int main() +{ + int n,k,MAXK; + int sum,ans; + int i,j,cnt; + while(scanf("%d%d%d",&n,&k,&MAXK)!=EOF) + { + ans=0; + for(i=0;ians) + ans=sum; + } + printf("%d\n",ans==0?-1:ans); + } +} diff --git a/HDOJ/2682_autoAC.cpp b/HDOJ/2682_autoAC.cpp new file mode 100644 index 0000000..5d471ed --- /dev/null +++ b/HDOJ/2682_autoAC.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#define INF 2000002 +int hash[2000002]; +int lowcost[601]; +int e[601][601]; +int used[601]; +int w[601]; +int n,i,j; +void sushubiao() +{ + int i; + memset(hash,0,sizeof(hash)); + int num=0; + hash[1]=1; + hash[0]=1; + int M=2000002; + for(i=2; i<=M; i++) + { + if(!hash[i]) + { + for(j=i+i;j=b)return b; + else return a; +} +void prim() +{ + int sum=0; + int min; + int v; + for(i=0; i +#include +#include +#include +#include +using namespace std; +long long gcd(long long a,long long b) +{ + if(b==0) + return a; + return gcd(b,a%b); +} +long long Pow(long long a,long long b,long long mod) +{ + long long ans=1; + while(b) + { + if(b&1) + { + b--; + ans=(ans*a)%mod; + } + else + { + b/=2; + a=(a*a)%mod; + } + } + return ans; +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + long long a,m,n,k; + scanf("%I64d%I64d%I64d%I64d",&a,&m,&n,&k); + printf("%I64d\n",(Pow(a,gcd(m,n),k)+k-1)%k); + } + return 0; +} diff --git a/HDOJ/2686_autoAC.cpp b/HDOJ/2686_autoAC.cpp new file mode 100644 index 0000000..62f6c0b --- /dev/null +++ b/HDOJ/2686_autoAC.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +using namespace std; +const int MAXN = 2005; +const int MAXEDGE = 1e5 + 5; +const int INF = 0x3f3f3f3f; +int n; +struct CEdge +{ + int from, to, cap, flow, cost, next; +}edge[MAXEDGE]; +struct CMCMF +{ + int s, t, pp; + int head[MAXN], a[MAXN], d[MAXN], p[MAXN]; + bool inq[MAXN]; + CMCMF(int ss, int tt) + { + s = ss, t = tt; + pp = 0; + memset(head, -1, sizeof(head)); + } + void addEdge(int u, int v, int cap, int cost) + { + edge[pp] = (CEdge){u, v, cap, 0, cost, head[u]}; + head[u] = pp++; + edge[pp] = (CEdge){v, u, 0, 0, -cost, head[v]}; + head[v] = pp++; + } + bool bellmanFord(int &flow, int &cost) + { + memset(d, INF, sizeof(d)); + memset(inq, false, sizeof(inq)); + queue q; + q.push(s), inq[s] = true; + a[s] = INF, d[s] = 0, p[s] = -1; + while(!q.empty()) + { + int u = q.front(); + q.pop(), inq[u] = false; + int next = head[u]; + while(next != -1) + { + CEdge &e = edge[next]; + if(e.cap > e.flow && d[e.to] > d[u] + e.cost) + { + d[e.to] = d[u] + e.cost; + a[e.to] = min(a[u], e.cap - e.flow); + p[e.to] = next; + if(!inq[e.to]) inq[e.to] = true, q.push(e.to); + } + next = e.next; + } + } + if(d[t] == INF) return false; + cost += d[t] * a[t]; + flow += a[t]; + int u = t; + while(u != s) + { + edge[p[u]].flow += a[t]; + edge[p[u]^1].flow -= a[t]; + u = edge[p[u]].from; + } + return true; + } +}; +int a[33][33]; +int main() +{ + while(scanf("%d",&n) != EOF) + { + int s = 1, t = n*n; + CMCMF mcmf(s, t); + int tmp; + for(int i = 0;i < n; i++) + { + for(int j = 1;j <= n; j++) + { + scanf("%d",&tmp); + a[i][j] = tmp; + if(j != n) mcmf.addEdge(i*n+j, i*n+j+1 + n*n, 1, -tmp); + if(i != n-1) mcmf.addEdge(i*n+j, (i+1)*n+j+n*n, 1, -tmp); + mcmf.addEdge(i*n+j+n*n, i*n+j, 1, 0); + } + } + mcmf.addEdge(n*n + n*n, n*n, 1, 0); + int cost = 0, flow = 0; + while(mcmf.bellmanFord(flow, cost)); + cout<<-cost - a[0][1] + a[n-1][n]< +int main() +{ + int n,i,k,j,a[11][11],b[11][11]; + while(scanf("%d",&n)!=EOF){ + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + scanf("%d",&a[i][j]); + scanf("%d",&k); + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + b[i][j]=(a[i][j]+a[j][n+1-i]+a[n+1-i][n+1-j]+a[n+1-j][i])*(k/4); + if(k%4==0) + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + b[i][j]+=a[i][j]; + else if(k%4==1) + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + b[i][j]+=a[i][j]+a[n+1-j][i]; + else if(k%4==2) + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + b[i][j]+=a[i][j]+a[n+1-j][i]+a[n+1-i][n+1-j]; + else + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + b[i][j]+=a[i][j]+a[n+1-j][i]+a[n+1-i][n+1-j]+a[j][n+1-i]; + for(i=1;i<=n;i++){ + for(j=1;j<=n;j++){ + printf("%d",b[i][j]); + if(j +#include +using namespace std; +const int maxn=10005; +const int maxm=3000005; +int c[maxn],a[maxm],n; +int sum(int x) +{ + int s=0; + while(x>=1) + { + s+=c[x]; + x-=x&(-x); + } + return s; +} +void updata(int i) +{ + while(i<=maxn-1) + { + c[i]++; + i+=i&(-i); + } +} +int main() +{ + int i,m,x,y; + __int64 ans; + char str[2]; + while(scanf("%d",&n)>0) + { + memset(c,0,sizeof(c)); + ans=0; + for(i=0;icount) + ans--; + else + if(a[i] +#include +int a[1002]; +int lowbit(int x) +{ + return x&(-x); +} +void add(int x) +{ + while(x<=1000) + { + ++a[x]; + x=x+lowbit(x); + } +} +int getsum(int x) +{ + int sum=0; + while(x>0) + { + sum=sum+a[x]; + x=x-lowbit(x); + } + return sum; +} +int main() +{ + int i,j,n,x,sum; + while(scanf("%d",&n)==1) + { + sum=0; + memset(a,0,sizeof(a)); + for(i=1;i<=n;i++) + { + scanf("%d",&x); + sum=sum+(i-1-getsum(x)); + add(x); + } + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/2690_autoAC.cpp b/HDOJ/2690_autoAC.cpp new file mode 100644 index 0000000..ae3ca52 --- /dev/null +++ b/HDOJ/2690_autoAC.cpp @@ -0,0 +1,40 @@ +#include +int main() +{ + int max,min,n,i,x,t,a[10001],sum1,sum2,s; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + max=0; + min=10001; + s=0; + for(i=0;imax) + max=a[i]; + if(a[i]=n&&a[i]<0)s=1; + } + if(s==1||n==1&&max==0){ printf("Impossible!\n"); continue;} + sum1=sum2=0; + if(max==min+1){ + for(i=0;i +#include +const int Mod=199997; +const int maxn=1000000; +char names[]="BOWRYG"; +int s,t; +int a[24],b[24]; +int cnt,box[Mod]; +struct edge{ + long long to; + int next,step; + bool flag; +} e[maxn]; +struct point{ + int step; + bool flag; + char a[24]; +} qu[maxn]; +int tr[12][4]={{0,1,3,2}, + {4,5,13,12}, + {6,7,15,14}, + {8,9,17,16}, + {10,11,19,18}, + {20,21,23,22}}; +int netr[12][8]={{11,10,9,8,7,6,5,4}, + {0,2,6,14,20,22,19,11}, + {2,3,8,16,21,20,13,5}, + {3,1,10,18,23,21,15,7}, + {17,9,1,0,4,12,22,23}, + {12,13,14,15,16,17,18,19}}; +void pre() +{ + for(int i=6;i<12;i++) + { + for(int j=0;j<4;j++) + tr[i][j]=tr[i-6][3-j]; + for(int j=0;j<8;j++) + netr[i][j]=netr[i-6][7-j]; + } +} +void hash(int &p1,long long &p2) +{ + p2=0; + for(int i=0;i<24;i++) + p2=p2*6+a[i]; + p1=p2%Mod; +} +void add(int p1,long long p2,int step,bool flag) +{ + e[cnt].to=p2;e[cnt].step=step;e[cnt].flag=flag; + e[cnt].next=box[p1];box[p1]=cnt++; + t++; + qu[t].step=step; + qu[t].flag=flag; + for(int i=0;i<24;i++) qu[t].a[i]=a[i]; +} +void finds(int p1,long long p2,bool &flag,int &step) +{ + for(int p=box[p1];p!=-1;p=e[p].next) + if (e[p].to==p2) + { + flag=e[p].flag; + step=e[p].step; + return ; + } + step=-1; +} +int makeit() +{ + bool flag=1,nowflag; + int step,q1,q2,q3,nowstep; + for(int i=0;i<24;i++) + flag=flag&&(a[i]==b[i]); + if (flag) return 0; + cnt=0; + memset(box,-1,sizeof(box)); + int p1; + long long p2; + s=0;t=0; + hash(p1,p2); + add(p1,p2,0,0); + for(int i=0;i<24;i++) a[i]=b[i]; + hash(p1,p2); + add(p1,p2,0,1); + while(s!=t) + { + s++; + step=qu[s].step; + flag=qu[s].flag; + for(int i=0;i<24;i++) + a[i]=qu[s].a[i]; + for(int i=0;i<12;i++) + { + q1=a[tr[i][0]]; + q2=a[netr[i][0]]; + q3=a[netr[i][1]]; + for(int j=0;j<3;j++) + a[tr[i][j]]=a[tr[i][j+1]]; + a[tr[i][3]]=q1; + for(int j=0;j<6;j++) + a[netr[i][j]]=a[netr[i][j+2]]; + a[netr[i][6]]=q2;a[netr[i][7]]=q3; + hash(p1,p2); + finds(p1,p2,nowflag,nowstep); + if (nowstep==-1) + add(p1,p2,step+1,flag); + else + if (nowflag!=flag) return nowstep+step+1; + int ii=(i+6); + if (ii>=12) ii-=12; + q1=a[tr[ii][0]]; + q2=a[netr[ii][0]]; + q3=a[netr[ii][1]]; + for(int j=0;j<3;j++) + a[tr[ii][j]]=a[tr[ii][j+1]]; + a[tr[ii][3]]=q1; + for(int j=0;j<6;j++) + a[netr[ii][j]]=a[netr[ii][j+2]]; + a[netr[ii][6]]=q2;a[netr[ii][7]]=q3; + } + } +} +int trans(char ch) +{ + for(int i=0;i<6;i++) + if (names[i]==ch) return i; + return -1; +} +int main() +{ + int cas; + char s[10]; + pre(); + scanf("%d",&cas); + while(cas--) + { + for(int i=0;i<24;i++) + { + scanf("%s",s); + a[i]=trans(s[0]); + } + for(int i=0;i<24;i++) + { + scanf("%s",s); + b[i]=trans(s[0]); + } + printf("%d\n",makeit()); + } + return 0; +} diff --git a/HDOJ/2697_autoAC.cpp b/HDOJ/2697_autoAC.cpp new file mode 100644 index 0000000..88b2a7c --- /dev/null +++ b/HDOJ/2697_autoAC.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +using namespace std; +const int N =110; +int a[N]; +int dp[N][N]; +int main(){ + int t; + int n,m; + scanf("%d",&t); + while(t--){ + scanf("%d%d",&n,&m); + for(int i=1;i<=n;i++){ + scanf("%d",&a[i]); + } + memset(dp,0,sizeof(dp)); + for(int i=1;i<=n;i++){ + for(int j=0;j<=m;j++){ + int cnt=0; + int sum=0; + dp[i][j]=dp[i-1][j]; + for(int h=i;h>=1;h--){ + cnt++; + sum+=a[h]; + if(sum>j) break; + dp[i][j]=max(dp[i][j],dp[h-1][j-sum]+cnt*cnt); + } + } + } + printf("%d\n",dp[n][m]); + } + return 0; +} diff --git a/HDOJ/2698_autoAC.cpp b/HDOJ/2698_autoAC.cpp new file mode 100644 index 0000000..cc3cfe6 --- /dev/null +++ b/HDOJ/2698_autoAC.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long int64; +typedef pair PII; +#define MP(a,b) make_pair((a),(b)) +const int maxn = 115; +const int inf = 0x7fffffff; +const double pi=acos(-1.0); +const double eps = 1e-8; +struct Node{ + char s[ maxn ]; + int cnt; +}a[ maxn ],q[ maxn ]; +int Find( char s[],int n ){ + for( int i=1;ib.cnt; + else { + if( strcmp( a.s,b.s )<=0 ) return true; + else return false; + } +} +int main(){ + int T; + scanf("%d",&T); + while( T-- ){ + int n; + scanf("%d",&n); + char ID[ maxn ],Web[ maxn ]; + int Cnt = 1; + int cc; + while( n-- ){ + scanf("%s%s",ID,Web); + cc = Find( Web,Cnt ); + if( ID[0]=='V' ){ + if( cc==-1 ){ + strcpy( a[Cnt].s,Web ); + a[ Cnt ].cnt = 1; + Cnt++; + } + else{ + a[ cc ].cnt++; + } + } + else{ + int pp = 0; + for( int k=1;k