diff --git a/HDOJ/2100_autoAC.cpp b/HDOJ/2100_autoAC.cpp new file mode 100644 index 0000000..341b41a --- /dev/null +++ b/HDOJ/2100_autoAC.cpp @@ -0,0 +1,37 @@ +#include +#include +int main() +{ + int l,l1,l2,i; + char a[205],b[205],c[205],*p; + while(scanf("%s %s",a,b)!=EOF) + { + l1=strlen(a)-1; + l2=strlen(b)-1; + l=l1>l2?l1:l2; + l++; + c[0]='A'; + for(i=l;i>0;i--,l1--,l2--) + { + if(l1>=0&&l2>=0) + c[i]=a[l1]+b[l2]-65; + else if(l1>=0&&l2<0) + c[i]=a[l1]; + else if(l1<0&&l2>=0) + c[i]=b[l2]; + } + c[l+1]='\0'; + for(i=l;i>0;i--) + if(c[i]>'Z') + { + c[i-1]+=1; + c[i]=c[i]-26; + } + for(p=c;;p++) + { + if(*p!='A') + break; + } + puts(p); + } +} diff --git a/HDOJ/2101_autoAC.cpp b/HDOJ/2101_autoAC.cpp new file mode 100644 index 0000000..7b609f4 --- /dev/null +++ b/HDOJ/2101_autoAC.cpp @@ -0,0 +1,12 @@ +#include +int main() +{ + int a,b,n; + while(scanf("%d%d",&a,&b)!=EOF) + {n=a+b; + if((n%86)==0) + printf("yes\n"); + else + printf("no\n");} + return 0; +} diff --git a/HDOJ/2102_autoAC.cpp b/HDOJ/2102_autoAC.cpp new file mode 100644 index 0000000..4b25d38 --- /dev/null +++ b/HDOJ/2102_autoAC.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +using namespace std; +int n,m,t; +int gx[]={1,0,-1,0},gy[]={0,1,0,-1}; +char map[3][20][20]; +bool found,mark[3][20][20]; +bool can(int x,int y,int z){ + if(x<0||x>=m||y<0||y>=n||mark[z][y][x]) + return false; + return true; +} +void dfs(int x,int y,int z,int s){ + if(map[z][y][x]=='P'){ + if(s<=t) + found=true; + return ; + } + for(int i=0;i<4;i++){ + if(s>t||found) + return ; + if(can(x+gx[i],y+gy[i],z)){ + if(map[z][y+gy[i]][x+gx[i]]=='#'&&(map[!z][y+gy[i]][x+gx[i]]=='.'||map[!z][y+gy[i]][x+gx[i]]=='P')&&!mark[!z][y+gy[i]][x+gx[i]]){ + mark[z][y][x]=1; + dfs(x+gx[i],y+gy[i],z^1,s+1); + mark[z][y][x]=0; + } + else if(map[z][y+gy[i]][x+gx[i]]=='.'||map[z][y+gy[i]][x+gx[i]]=='P'){ + mark[z][y][x]=1; + dfs(x+gx[i],y+gy[i],z,s+1); + mark[z][y][x]=0; + } + } + } +} +int main(){ + int i,j,T; + scanf("%d",&T); + while(T--){ + scanf("%d%d%d",&n,&m,&t); + for(i=0;i<2;i++) + for(j=0;j +using namespace std; +long long powe(int n); +int main() +{ + int t; + cin>>t; + while(t--) + { + int m,n; + cin>>m>>n; + int *p=new int[n]; + for(int i=0;i!=n;++i) + cin>>p[i]; + int i; + for(i=0;i!=m;++i) + { + if(p[i]==1) + break; + } + long long sum; + if(i==m) + sum=10000*(powe(n-i)-1); + if(i +int gcd(int a,int b) +{ + return b==0?a:gcd(b,a%b); +} +int main() +{ + int n,m; + while(scanf("%d%d",&n,&m),n!=-1&&m!=-1) + { + if(gcd(n,m)==1) puts("YES"); + else puts("POOR Haha"); + } + return 0; +} diff --git a/HDOJ/2105_autoAC.cpp b/HDOJ/2105_autoAC.cpp new file mode 100644 index 0000000..08c7d52 --- /dev/null +++ b/HDOJ/2105_autoAC.cpp @@ -0,0 +1,19 @@ +#include +#include +using namespace std; +int main() +{ + int n; + while(cin>>n&&n) + { + while(n--) + { + double x1,x2,x3,y1,y2,y3; + cin>>x1>>y1>>x2>>y2>>x3>>y3;\ + double ans1=(double)(x1+x2+x3)/3.0; + double ans2=(double) (y1+y2+y3)/3.0; + printf("%.1lf %.1lf\n",ans1,ans2); + } + } + return 0; +} diff --git a/HDOJ/2106_autoAC.cpp b/HDOJ/2106_autoAC.cpp new file mode 100644 index 0000000..3b959b6 --- /dev/null +++ b/HDOJ/2106_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +using namespace std; +const int N = 100001; +char str[N]; +int main () +{ + int n, sum, digit, len, t; + while ( scanf("%d", &n) != EOF ) + { + sum = 0; + while ( n-- ) + { + scanf("%s", str); + digit = 0; + if ( str[strlen(str) - 2] == '0' ) + { + digit = 10; + len = strlen(str) - 5; + } + else + { + digit = str[strlen(str) - 2] - '0'; + len = strlen(str) - 4; + } + t = 1; + for ( int i = len; i >= 0; i-- ) + { + sum += ( str[i] - '0' ) * t; + t *= digit; + } + } + printf("%d\n", sum); + } + return 0; +} diff --git a/HDOJ/2107_autoAC.cpp b/HDOJ/2107_autoAC.cpp new file mode 100644 index 0000000..7438bb9 --- /dev/null +++ b/HDOJ/2107_autoAC.cpp @@ -0,0 +1,19 @@ +#include +int main() +{ + int t,a,max; + while(scanf("%d",&t)!=EOF &&t!=0) + { + max=0; + while(t--) + { + scanf("%d",&a); + if(a>max) + { + max=a; + } + } + printf("%d\n",max); + } + return 0; +} diff --git a/HDOJ/2108_autoAC.cpp b/HDOJ/2108_autoAC.cpp new file mode 100644 index 0000000..22fd170 --- /dev/null +++ b/HDOJ/2108_autoAC.cpp @@ -0,0 +1,42 @@ +#include +struct Point +{ + int x,y; +}; +typedef struct Point point; +int main() +{ + point a[10001],s,t; + int i,n,flag; + while(scanf("%d",&n)!=EOF&&n!=0) + { + flag=1; + for(i=0;i +#include +#include +using namespace std; +int main() +{ + int a[105],b[105],i; + int n; + while(scanf("%d",&n)&&n) + { + int sum,sum1; + sum=sum1=0; + for(i=0;ib[i]) + sum+=2; + if(a[i] +#include +using namespace std; +int num[100],price[100],c1[10050],c2[10050]; +int main(){ + int n,sum; + int m; + while(~scanf("%d",&n)&&n) + { + sum=0; + memset(c1,0,sizeof(c1)); + memset(c2,0,sizeof(c2)); + for(int i=1;i<=n;i++) + { + scanf("%d%d",&price[i],&num[i]); + sum+=price[i]*num[i]; + } + m=sum/3; + if(sum%3!=0) + { + printf("sorry\n"); + continue; + } + for(int i=0;i<=num[1]*price[1]&&i<=m;i+=price[1]) + c1[i]=1; + for(int i=2;i<=n;i++) + { + for(int j=0;j<=m;j++) + { + for(int k=0;k<=num[i]*price[i]&&k+j<=m;k+=price[i]) + c2[k+j]+=c1[j]%10000; + } + for(int j=0;j<=m;j++) + { + c1[j]=c2[j]%10000; + c2[j]=0; + } + } + if(c1[m]==0) + printf("sorry\n"); + else + printf("%d\n",c1[m]); + } + return 0; +} diff --git a/HDOJ/2111_autoAC.cpp b/HDOJ/2111_autoAC.cpp new file mode 100644 index 0000000..e6cf460 --- /dev/null +++ b/HDOJ/2111_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +using namespace std; +struct node +{ + int qian; + int v; +}; +bool cmp(node a,node b) +{ + return a.qian>b.qian; +} +int main() +{ + int rong,zhonglei; + int i; + node f[2000]; + while(scanf("%d",&rong)&&rong) + { + int jiazhi=0; + scanf("%d",&zhonglei); + for(i=1;i<=zhonglei;i++) + scanf("%d%d",&f[i].qian,&f[i].v); + sort(f+1,f+1+zhonglei,cmp); + for(i=1;i<=zhonglei;i++) + { + if(rong-f[i].v>=0) + { + jiazhi+=f[i].v*f[i].qian; + rong-=f[i].v; + } + else + { + jiazhi+=f[i].qian*rong; + break; + } + } + printf("%d\n",jiazhi); + } + return 0; +} diff --git a/HDOJ/2112_autoAC.cpp b/HDOJ/2112_autoAC.cpp new file mode 100644 index 0000000..4cce865 --- /dev/null +++ b/HDOJ/2112_autoAC.cpp @@ -0,0 +1,96 @@ +#include +#include +#define INF 0x3f3f3f +#define max 150+10 +int visit[max],map[max][max],dist[max]; +char str[max][max]; +int n; +void dijkstra() +{ +} +int main() +{ + int i,j,next,mindist; + int t,x,y,c; + char s[30],e[30]; + while(scanf("%d",&n)&&(n!=-1)) + { + for(i=1;i<150;i++) + { + for(j=1;j<150;j++) + { + if(i==j) + map[i][j]=0; + else + map[i][j]=INF; + } + } + scanf("%s %s",s,e); + strcpy(str[1],s); + strcpy(str[2],e); + t=2; + for(j=1;j<=n;j++) + { + scanf("%s %s %d",s,e,&c); + for(i=1,x=max,y=max;i<=t;i++) + { + if(strcmp(str[i],s)==0&&x==max) + x=i; + if(strcmp(str[i],e)==0&&y==max) + y=i; + if(x!=max&&y!=max) + break; + } + if(x==max) + { + t++; + x=t; + strcpy(str[x],s); + } + if(y==max) + { + t++; + y=t; + strcpy(str[y],e); + } + if(map[x][y]>c) + map[x][y]=map[y][x]=c; + } + if(strcmp(str[1],str[2])==0) + { + printf("0\n"); + continue; + } + for(i=1;i<150;i++) + { + visit[i]=0; + dist[i]=map[1][i]; + } + visit[1]=1; + for(i=2;i<=t;i++) + { + mindist=INF; + for(j=1;j<=t;j++) + { + if(!visit[j]&&mindist>dist[j]) + { + mindist=dist[j]; + next=j; + } + } + visit[next]=1; + for(j=1;j<=t;j++) + { + if(!visit[j]&&dist[next]+map[next][j] +#include +using namespace std; +int main() +{ + __int64 num; + int k = 0; + int sum; + int yu; + while(scanf("%I64d", &num) != EOF) + { + if(k) + cout << endl; + else + k = 1; + sum = 0; + while(num) + { + yu = num % 10; + if(!(yu % 2)) + { + sum += yu; + } + num /= 10; + } + cout << sum << endl; + } + return 0; +} diff --git a/HDOJ/2114_autoAC.cpp b/HDOJ/2114_autoAC.cpp new file mode 100644 index 0000000..d924bee --- /dev/null +++ b/HDOJ/2114_autoAC.cpp @@ -0,0 +1,11 @@ +#include +int main() +{ + __int64 n,s; + while(~scanf("%I64d",&n)) + { + s=((n*(n+1)/2%10000)*(n*(n+1)/2%10000))%10000; + printf("%04I64d\n",s); + } + return 0; +} diff --git a/HDOJ/2115_autoAC.cpp b/HDOJ/2115_autoAC.cpp new file mode 100644 index 0000000..da4a977 --- /dev/null +++ b/HDOJ/2115_autoAC.cpp @@ -0,0 +1,63 @@ +#include +#include +int main() +{ + int n,k=1,i,j,s,mc,a[10],b[10]; + char c[10][50],q[50]; + while(scanf("%d",&n)&&n!=0) + { + for(i=0;i=n) + break; + } + } + if(k!=1) + putchar('\n'); + printf("Case #%d\n",k); + k++; + for(i=0;i0&&a[i]==a[i-1]&&b[i]==b[i-1]) + mc=mc; + else + mc=i+1; + printf("%s %d\n",c[i],mc); + } + } +} diff --git a/HDOJ/2116_autoAC.cpp b/HDOJ/2116_autoAC.cpp new file mode 100644 index 0000000..c93a5c4 --- /dev/null +++ b/HDOJ/2116_autoAC.cpp @@ -0,0 +1,124 @@ +#include +using namespace std; +int main(int argc, char *argv[]) +{ + int k; + while(scanf("%d",&k)!=EOF) + { + char aa[100]; + char bb[100]; + scanf("%s%s",&aa,&bb); + int aa2[71]; + int bb2[71]; + memset(aa2,0,sizeof(aa2)); + memset(bb2,0,sizeof(bb2)); + int ii; + int alen=strlen(aa); + int blen=strlen(bb); + int aweizhi=70; + int bweizhi=70; + for(ii=alen-1;ii>=0;ii--) + { + if(aa2[aweizhi]!='-') + { + aa2[aweizhi]=aa[ii]-'0'; + aweizhi-=1; + } + } + for(ii=blen-1;ii>=0;ii--) + { + if(bb2[bweizhi]!='-') + { + bb2[bweizhi]=bb[ii]-'0'; + bweizhi-=1; + } + } + int cc[100]; + memset(cc,0,sizeof(cc)); + cc[70]=1; + int i; + for(i=1;i=0;j--) + { + cc[j]*=2; + } + for(j=70;j>=0;j--) + { + if(cc[j]/10>0) + { + cc[j-1]+=cc[j]/10; + cc[j]=cc[j]%10; + } + } + } + int jingwei=0; + int ir; + for(ir=0;ir<=70;ir++) + { + aa2[ir]+=bb2[ir]; + int j2; + for(j2=70;j2>=0;j2--) + { + if(aa2[j2]/10>0) + { + aa2[j2-1]+=aa2[j2]/10; + aa2[j2]=aa2[j2]%10; + } + } + blen-=1; + } + int weizhi=0; + for(i=0;i<=70;i++) + { + if(cc[i]!=0) + { + weizhi=i; + break; + } + } //cc:k + int weizhi2=0; + for(i=0;i<=70;i++) + { + if(aa2[i]!=0) + { + weizhi2=i; + break; + } + } + int flag=0; + if(aa[0]=='-'&&bb[0]=='-') + { + int iii; + for(iii=0;iii<=70;iii++) + { + if(aa2[iii]>cc[iii]) + { + flag=1; + break; + } + } + }else if(aa[0]!='-'&&bb[0]!='-') + { + cc[70]-=1; + int iii; + for(iii=0;iii<=70;iii++) + { + if(aa2[iii]>cc[iii]) + { + flag=1; + break; + } + } + } + if(flag==1) + { + cout<<"Yes"< +int main() +{ + int n,m,i,t,x; + int s; + while(scanf("%d%d",&n,&m)!=EOF) + { s=1; + while(m--) + { + s=s*10; + t=s/n; + s=s%n; + } + printf("%d\n",t%10); + } + return 0; +} diff --git a/HDOJ/2118_autoAC.cpp b/HDOJ/2118_autoAC.cpp new file mode 100644 index 0000000..94535c8 --- /dev/null +++ b/HDOJ/2118_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +int energy[205][2105]; +int f[205][2105]; +int dx[4]={1,0,1,2}; +int dy[4]={0,1,2,1}; +int n,m,K; +void dp() +{ + int i,j,k; + f[1][1]=energy[1][1]; + for(i=1;i<=n;i++) + { + for(j=1;j<=(i-1)*m+1;j++)if(f[i][j]-K>0) + { + for(k=0;k<4;k++) + { + int xx=i+dx[k]; + int yy=j+dy[k]; + if(yy<=(xx-1)*m+1&&(f[xx][yy]==-1||f[xx][yy]0&&(ans<0||ans>f[n][i]))ans=f[n][i]; + } + if(ans>0)printf("%d\n",ans); + else printf("what a pity mouse!!\n"); +} +int main() +{ + int i,j; + while(scanf("%d %d %d",&n,&m,&K)!=EOF) + { + for(i=1;i<=n;i++) + { + for(j=1;j<=(i-1)*m+1;j++) + { + scanf("%d",&energy[i][j]); + f[i][j]=-1; + } + } + dp(); + } + return 0; +} diff --git a/HDOJ/2119_autoAC.cpp b/HDOJ/2119_autoAC.cpp new file mode 100644 index 0000000..651ef82 --- /dev/null +++ b/HDOJ/2119_autoAC.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define mod 1000000007 +#define inf 0x7f7f7f7f +int vis[505]; +int pre[505]; +int mat[505][505]; +int n,m,ans; +int find(int x) +{ + int i; + for(i=1;i<=m;i++) + { + if(!vis[i]&&mat[x][i]) + { + vis[i]=1; + if(pre[i]==-1 ||find(pre[i])) + { + pre[i]=x; + return 1; + } + } + } + return 0; +} +int init() +{ + int i; + ans=0; + memset(pre,-1,sizeof(pre)); + for(i=1;i<=n;i++) + { + memset(vis,0,sizeof(vis)); + if(find(i)) + ans++; + } + return ans; +} +int main() +{ + int i,j; + while(cin>>n,n) + { + cin>>m; + for(i=1;i<=n;i++) + for(j=1;j<=m;j++) + cin>>mat[i][j]; + int ans1=init(); + cout< +int parent[1001],n; +void ynaiyxc() +{ + int i; + for(i=0;i<=1000;i++) + parent[i]=i; +} +int yxc(int x) +{ + if(x!=parent[x]) parent[x]=yxc(parent[x]); + return parent[x]; +} +int main() +{ + int m,num,a,b,i; + while(scanf("%d%d",&n,&m)!=EOF) + { + ynaiyxc(); + num=0; + for(i=0;i +using namespace std; +#include +#include +#define MAXN 1005 +#define INF 0x7f7f7f7f +typedef __int64 type; +struct node +{ + int u, v; + type w; +}edge[MAXN * MAXN]; +int pre[MAXN], id[MAXN], vis[MAXN], n, m, pos; +type in[MAXN]; +type Directed_MST(int root, int V, int E) +{ + type ret = 0; + while(true) + { + int i; + for( i = 0; i < V; i++) + in[i] = INF; + for( i = 0; i < E; i++) + { + int u = edge[i].u; + int v = edge[i].v; + if(edge[i].w < in[v] && u != v) + { + pre[v] = u; + in[v] = edge[i].w; + if(u == root) + pos = i; + } + } + for( i = 0; i < V; i++) + { + if(i == root) + continue; + if(in[i] == INF) + return -1; + } + int cnt = 0; + memset(id, -1, sizeof(id)); + memset(vis, -1, sizeof(vis)); + in[root] = 0; + for( i = 0; i < V; i++) + { + ret += in[i]; + int v = i; + while(vis[v] != i && id[v] == -1 && v != root) + { + vis[v] = i; + v = pre[v]; + } + if(v != root && id[v] == -1) + { + for(int u = pre[v]; u != v; u = pre[u]) + id[u] = cnt; + id[v] = cnt++; + } + } + if(cnt == 0) + break; + for( i = 0; i < V; i++) + if(id[i] == -1) + id[i] = cnt++; + for( i = 0; i < E; i++) + { + int u = edge[i].u; + int v = edge[i].v; + edge[i].u = id[u]; + edge[i].v = id[v]; + if(id[u] != id[v]) + edge[i].w -= in[v]; + } + V = cnt; + root = id[root]; + } + return ret; +} +int main() +{ + int i; + while(scanf("%d%d", &n, &m) != EOF) + { + type sum = 0; + for( i = 0; i < m; i++) + { + scanf("%d%d%I64d", &edge[i].u, &edge[i].v, &edge[i].w); + edge[i].u++; edge[i].v++; + sum += edge[i].w; + } + sum ++; + for( i = m; i < m + n; i++) + { + edge[i].u = 0; + edge[i].v = i - m + 1; + edge[i].w = sum; + } + type ans = Directed_MST(0, n + 1, m + n); + if(ans == -1 || ans - sum >= sum) + puts("impossible"); + else + printf("%I64d %d\n",ans - sum, pos - m); + puts(""); + } + return 0; +} diff --git a/HDOJ/2122_autoAC.cpp b/HDOJ/2122_autoAC.cpp new file mode 100644 index 0000000..00c8adb --- /dev/null +++ b/HDOJ/2122_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#define max 10000+10 +using namespace std; +int set[1010]; +int city,road; +struct line +{ + int start; + int end; + int money; +}num[max]; +bool cmp(line a,line b) +{ + return a.money1) + break; + } + } + if(exist>1) + printf("impossible\n\n"); + else + printf("%d\n\n",need); + } + return 0; +} diff --git a/HDOJ/2123_autoAC.cpp b/HDOJ/2123_autoAC.cpp new file mode 100644 index 0000000..46275fa --- /dev/null +++ b/HDOJ/2123_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + int n,i,j,a; + scanf("%d",&n); + while(n--) + { + scanf("%d",&a); + for(i=1;i<=a;i++) + { + for(j=1;j +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef __int64 ll; +bool comp(ll a,ll b){ + return a>b; +} +int main() +{ + int n; + ll L,ai; + vector buf; + while(cin>>L>>n) + { + for(int i=0;i>ai; + buf.push_back(ai); + } + sort(buf.begin(),buf.end(),comp); + int min=0; + ll sum=0; + for(vector::size_ i=0;i!=buf.size()&&sum +#include +int main() +{ + int n,m; + int dp[50][50]; + int i,l; + int x,y,flag; + int x1,y1,x2,y2; + while(scanf("%d%d",&n,&m)!=-1) + { + scanf("%d%d%d%d",&y1,&x1,&y2,&x2); + if(x1+y1>x2+y2) {x=x1;y=y1;} + else {x=x2;y=y2;} + if(x1!=x2) flag=-1; + else flag=1; + memset(dp,0,sizeof(dp)); + dp[0][0]=1; + for(l=1;l +using namespace std; +int main() +{ + int T,i,j,k; + int N,V,v[31],dp[35][505]; + scanf("%d",&T); + while(T--) + { + scanf("%d%d",&N,&V); + for(i=1;i<=N;i++) + scanf("%d",&v[i]); + memset(dp,0,sizeof(dp)); + for(j=0;j<=V;j++) + dp[0][j]=1; + for(i=1;i<=N;i++) + { + for(k=i;k>=1;k--) + { for(j=V;j>=v[i];j--) + if(dp[k-1][j-v[i]]) + dp[k][j]+=dp[k-1][j-v[i]]; + } + } + int sel=0,kind=0; + for(i=N;i>=1;i--) + for(j=V;j>=0;j--) + if(dp[i][j]) {sel=dp[i][j];kind=i;goto lab;} +lab: if(sel) + printf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n",sel,kind); + else printf("Sorry, you can't buy anything.\n"); + } + return 0; +} diff --git a/HDOJ/2127_autoAC.cpp b/HDOJ/2127_autoAC.cpp new file mode 100644 index 0000000..cb444a7 --- /dev/null +++ b/HDOJ/2127_autoAC.cpp @@ -0,0 +1,135 @@ +#include +#include +#include +using namespace std; +char stack[500]; +int top; +char output[500], input[500]; +int outLen; +int priority(char op) +{ + if (op=='+' || op=='-') + return 1; + if (op=='*' || op=='/') + return 2; + else + return 0; +} +bool isOperator(char op) +{ + return (op=='+' || op=='-' || op=='*' || op=='/'); +} +void Polish(char *s,int len) +{ + memset(output,'\0',sizeof output); + outLen = 0; + for (int i=len-1; i >= 0; --i) + { + if (isdigit(s[i])) + { + output[outLen++] = s[i]; + while (i-1 >= 0 && isdigit(s[i-1])) + { + output[outLen++] = s[i-1]; + --i; + } + output[outLen++] = ' '; + } + if (s[i]==')') + { + ++top; + stack[top] = s[i]; + } + while (isOperator(s[i])) + { + if (top==0 || stack[top]==')' || priority(s[i]) >= priority(stack[top])) + { + ++top; + stack[top] = s[i]; + break; + } + else + { + output[outLen++] = stack[top]; + output[outLen++] = ' '; + --top; + } + } + if (s[i]=='(') + { + while (stack[top]!=')') + { + output[outLen++] = stack[top]; + output[outLen++] = ' '; + --top; + } + --top; + } + } + while (top!=0) + { + output[outLen++] = stack[top]; + output[outLen++] = ' '; + --top; + } +} +char DstBuf[200]; +char* OP(char* op1,char* op2,char op) +{ + __int64 res = 0; + if (op=='+') + res = _atoi64(op1) + _atoi64(op2); + else if (op=='-') + res = _atoi64(op1) - _atoi64(op2); + else if (op=='*') + res = _atoi64(op1) * _atoi64(op2); + else if (op=='/') + res = _atoi64(op1) / _atoi64(op2); + _i64toa(res,DstBuf,10); + return DstBuf; +} +char cSt1[200][80], cSt2[200][80]; +__int64 calc(char *s) +{ + int top1=0, top2=0, i; + for (i=0; s[i]; ++i) + { + if (s[i] && s[i] != ' ') + { + ++top1; + sscanf(s+i,"%s",cSt1[top1]); + while (s[i] && s[i] != ' ') + ++i; + } + } + while (top1 != 0) + { + if (!isdigit(cSt1[top1][0])) + { + OP(cSt2[top2], cSt2[top2-1], cSt1[top1][0]); + memcpy(cSt2[top2-1],DstBuf,sizeof DstBuf); + --top2; + --top1; + } + else + { + ++top2; + memcpy(cSt2[top2],cSt1[top1],sizeof cSt1[top1]); + --top1; + } + } + return _atoi64(cSt2[1]); +} +int main() +{ + int T = 1; + while (gets(input)) + { + Polish(input, strlen(input)); + reverse(output,output+outLen-1); + output[outLen-1] = '\0'; + printf("Case %d:\n%s\n",T++,output); + printf("%I64d\n",calc(output)); + } + return 0; +} diff --git a/HDOJ/2128_autoAC.cpp b/HDOJ/2128_autoAC.cpp new file mode 100644 index 0000000..ac085cc --- /dev/null +++ b/HDOJ/2128_autoAC.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +using namespace std; +struct node +{ + int x,y,num,step; + char mp[15][15]; + bool friend operator<(node a,node b) + { + return a.step>b.step; + } +} t; +int dir[4][2]= {{1,0},{0,1},{-1,0},{0,-1}}; +char s[15][15]; +int vis[15][15][55]; +int n,m,ex,ey,flag; +int bfs(int x,int y) +{ + priority_queueq; + int i,j; + for(i=0; i=0 && t.x=0 && t.y0) + { + vis[t.x][t.y][t.num]++; + t.step++; + t.num--; + t.mp[t.x][t.y]='.'; + q.push(t); + } + else if(t.mp[t.x][t.y]>='1' && t.mp[t.x][t.y]<='9') + { + vis[t.x][t.y][t.num]++; + t.num+=t.mp[t.x][t.y]-'0'; + t.mp[t.x][t.y]='.'; + q.push(t); + } + } + t=q.top(); + } + q.pop(); + } + return -1; +} +int main() +{ + int i,j,x1,y1; + while(~scanf("%d%d",&n,&m) && n) + { + for(i=0; i +#include +#include +using namespace std; +typedef struct team +{ + string name; + int price[4]; +}team; +typedef struct school +{ + string name; + int price[4]; + team tm[101]; + int nowteamlen; +}school; +typedef struct place +{ + string name; + int price[4]; +}place; +school scl[201]; +place plc[201]; +int tellprice(string price) +{ + if(price=="gold") + return 1; + if(price=="silver") + return 2; + if(price=="copper") + return 3; + return 0; +} +int cmpbyscl(const void *a,const void *b) +{ + school *x=(school *)a; + school *y=(school *)b; + if(x->price[1]price[1]) + return 1; + if(x->price[1]>y->price[1]) + return -1; + if(x->price[2]price[2]) + return 1; + if(x->price[2]>y->price[2]) + return -1; + if(x->price[3]price[3]) + return 1; + if(x->price[3]>y->price[3]) + return -1; + if(x->name>y->name) + return 1; + if(x->namename) + return -1; + return 0; +} +int cmpbytm(const void *a,const void *b) +{ + team *x=(team *)a; + team *y=(team *)b; + if(x->price[1]price[1]) + return 1; + if(x->price[1]>y->price[1]) + return -1; + if(x->price[2]price[2]) + return 1; + if(x->price[2]>y->price[2]) + return -1; + if(x->price[3]price[3]) + return 1; + if(x->price[3]>y->price[3]) + return -1; + if(x->name>y->name) + return 1; + if(x->namename) + return -1; + return 0; +} +int cmpbyplc(const void *a,const void *b) +{ + place *x=(place *)a; + place *y=(place *)b; + if(x->name>y->name) + return 1; + if(x->namename) + return -1; + return 0; +} +int main() +{ + int i, j; + long T,N,t; + long nowplacelen,nowschoollen; + string tschool,tteam,tprice,tplace; + scanf("%d",&T); + for(int pp=1;pp<=T;pp++) + { + scanf("%d",&N); + nowplacelen=0; + nowschoollen=0; + for(i=0;i>tschool>>tteam>>tprice>>tplace; + for(j=0;j +int main () +{ +int a,b,c,n; +while (scanf("%d %d %d",&a,&b,&c)!=EOF) +{ + if (a==-1 && b==-1 && c==-1) return 0; + n=0.125*a*(a+1)*b*(b+1)*c*(c+1); + printf ("%d\n",n); +} +return 0; +} diff --git a/HDOJ/2131_autoAC.cpp b/HDOJ/2131_autoAC.cpp new file mode 100644 index 0000000..aac1a4f --- /dev/null +++ b/HDOJ/2131_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +int main() +{ + double s,n,m; + int i,l; + char h,c[200]; + while(scanf("%c %s",&h,c)==2) + { + getchar(); + l=strlen(c); + if(h<='Z') + h=h+32; + for(i=0,n=0;i +int main() +{ + __int64 sum,n,k; + while(~scanf("%I64d",&n),(n>=0)) + { + k=n/3; + if(n%3==0) + { + if(k&1) + sum=((1+k)>>1)*((1+k)>>1)*k*k*27+3*k*k; + else + sum=(k>>1)*(k>>1)*(1+k)*(1+k)*27+3*k*k; + } + if(n%3==1) + { + if(k&1) + sum=((1+k)>>1)*((1+k)>>1)*k*k*27+n+3*k*k; + else + sum=(k>>1)*(k>>1)*(1+k)*(1+k)*27+n+3*k*k; + } + if(n%3==2) + { + if(k&1) + sum=((1+k)>>1)*((1+k)>>1)*k*k*27+n+n-1+3*k*k; + else + sum=(k>>1)*(k>>1)*(1+k)*(1+k)*27+n+n-1+3*k*k; + } + printf("%I64d\n",sum); + } + return 0; +} diff --git a/HDOJ/2133_autoAC.cpp b/HDOJ/2133_autoAC.cpp new file mode 100644 index 0000000..2e70935 --- /dev/null +++ b/HDOJ/2133_autoAC.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int maxn=100000; +int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; +bool isleap(int x){ + if(x%400==0)return true; + if(x%100!=0&&x%4==0)return true; + return false; +} +int f(int y,int m,int d){ + if(isleap(y))a[2]=29; + int ret=d; + for(int i=1;i12||m<1)return true; + if(d>a[m]||d<1)return true; + a[2]=28; + return false; +} +int main(){ + int y,m,d; + while(cin>>y>>m>>d){ + if(isno(y,m,d)){ + cout<<"illegal"< +int main() +{ + double a=0.57735026918963,b=0.81649658092773; + int r; + while(scanf("%d",&r),r) + printf("%.3f %.3f\n",a*r,b*r); + return 0; +} diff --git a/HDOJ/2135_autoAC.cpp b/HDOJ/2135_autoAC.cpp new file mode 100644 index 0000000..96f88c9 --- /dev/null +++ b/HDOJ/2135_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +int main() +{ + int n,i,j,k; + char a[11][11],b[11][11]; + while((cin>>n>>k)>0) + { + getchar(); + for(i=1; i<=n; i++) + for(j=1; j<=n; j++) + cin>>a[i][j]; + k=k%4; + while(k<=0) + k+=4; + while(k--) + { + for(i=1; i<=n; i++) + for(j=1; j<=n; j++) + b[j][n-i]=a[i][j]; + for(i=1; i<=n; i++) + { + for(j=1; j<=n; j++) + { + a[i][j]=b[i][j-1]; + if(!k) + cout< +#include +#include +#include +const int MAX=1000000; +int x[MAX]; +using namespace std; +int main() +{ + int n,m,i,j,sum; + memset(x,-1,sizeof(x)); + x[1]=0; + sum=0; + for(i=2;i +#include +int main() +{ + char c[80]; + int n,i,j,l; + while(scanf("%s%d",c,&n)==2) + { + getchar(); + l=strlen(c); + if(n<0) + n=-((-n)%8)+8; + n=n%8; + if(n==0) + puts(c); + if(n==1) + { + for(i=strlen(c)-1;i>=0;i--) + { + for(j=0;j=0;i--) + { + for(j=0;j<(l/2);j++) + { + putchar(' '); + } + printf("%c\n",c[i]); + } + } + if(n==3) + { + for(i=strlen(c)-1;i>=0;i--) + { + for(j=0;j=0;i--) + { + putchar(c[i]); + } + putchar('\n'); + } + if(n==5) + { + for(i=0;i +#include +using namespace std; +int prime(int x) +{ + if(x==1) + return 0; + for(int i=2; i<=sqrt(x); i++) + if(x%i==0) + return 0; + return 1; +} +int main() +{ + int n,x; + while((cin>>n)>0) + { + int sum=0; + while(n--) + { + cin>>x; + sum+=prime(x); + } + cout< +__int64 a[2500]; +int main() +{ + __int64 sum,i,n; + a[1]=1; + for(i=3;i<=2500;i+=2) + { + a[i]+=a[i-2]+i*i; + } + while(scanf("%I64d",&n)!=EOF) + { + printf("%I64d\n",a[n]); + } +return 0; +} diff --git a/HDOJ/2140_autoAC.cpp b/HDOJ/2140_autoAC.cpp new file mode 100644 index 0000000..832e8b6 --- /dev/null +++ b/HDOJ/2140_autoAC.cpp @@ -0,0 +1,20 @@ +#include +#include +char a[1000]={'b','q','t','m','i','c','a','e','l'},b[1000]={' ', ',' ,'!','l','e','a','c','i','m'}; +char c[10005]; +int main(){ + int l,n; + while(gets(c)){ + l=strlen(c); + for(int i=0;i +#include +#include +using namespace std; +const int maxn=1000002; +int sum[maxn]; +int a_1[maxn]; +int b_1[maxn]; +int c_1[maxn]; +int main() +{ + int a,b,c; + int i,j,k=0; + while(scanf("%d%d%d",&a,&b,&c)!=EOF) + { + cout<<"Case "<<++k<<":"< +#include +#include +#include +using namespace std; +typedef struct +{ + double score; + string name; +}disney; +bool cmp(disney a,disney b) +{ + if(a.score==b.score) + return a.nameb.score; +} +int sum=0; +void NEW(disney a[],disney b) +{ + int i; + for(i=0;i>s) + { + if(s=="NEW") + { + cin>>b.name>>b.score; + NEW(a,b); + } + else if(s=="AVERAGE") + average(a); + else if(s=="MAX") + Max(a); + else if(s=="DELETE") + { + cin>>str; + Delete(a,str); + } + else if(s=="QUIT") + break; + } + return 0; +} diff --git a/HDOJ/2143_autoAC.cpp b/HDOJ/2143_autoAC.cpp new file mode 100644 index 0000000..41c7762 --- /dev/null +++ b/HDOJ/2143_autoAC.cpp @@ -0,0 +1,19 @@ +#include +int main() +{ + _int64 a,b,c; + int flag; + while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF) + { + flag=0; + if(a+b==c||a+c==b||b+c==a||a*b==c||a*c==b||b*c==a) + flag=1; + else if((a&&(b%a==c||c%a==b))||(b&&(a%b==c||c%b==a))||(c&&(a%c==b||b%c==a))) + flag=1; + if(flag) + puts("oh,lucky!"); + else + puts("what a pity!"); + } + return 0; +} diff --git a/HDOJ/2144_autoAC.cpp b/HDOJ/2144_autoAC.cpp new file mode 100644 index 0000000..1962b5a --- /dev/null +++ b/HDOJ/2144_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +using namespace std; +const int N=111; +int n; +double limit; +char str[N][N]; +int pre[N],len[N],dp[N][N]; +int find(int k) +{ + if(pre[k]==k) return k; + pre[k]=find(pre[k]); + return pre[k]; +} +int cal(int a,int b) +{ + int i,l; + int max=0; + memset(dp[0],0,sizeof(dp[0])); + for(i=1;i<=len[a];i++) + { + dp[i][0]=0; + for(l=1;l<=len[b];l++) + { + if(str[a][i]==str[b][l]) dp[i][l]=dp[i-1][l-1]+1; + else dp[i][l]=0; + if(dp[i][l]>max) max=dp[i][l]; + } + } + return max; +} +int main() +{ + int Case=1; + int i,l; + int f1,f2,cnt,ans; + while(scanf("%d%lf",&n,&limit)!=-1) + { + for(i=0;ilimit && cnt*100.0/len[l]>limit) pre[f1]=f2; + } + } + ans=0; + for(i=0;i +#include +#include +using namespace std; +int n,m,q; +int e; +struct A +{ + int s; + int v; + int num; + int len; + double ans; +}E[333]; +struct B +{ + int dis; + int flag; +}city[333]; +struct node +{ + int num; + int dis; + friend bool operator<(node n1,node n2) + { + return n2.disans>d->ans) return 1; + else if(c->ansans) return -1; + if(c->len!=d->len) return d->len-c->len; + return d->num-c->num; +} +void Dij() +{ + priority_queueq; + node cur,next; + int temp; + cur.num=e; + cur.dis=0; + q.push(cur); + while(!q.empty()) + { + cur=q.top(); + q.pop(); + if(!city[cur.num].flag) continue; + temp=head[cur.num]; + while(temp!=-1) + { + if(city[cur.num].dis+eage[temp].len +#include +#include +#include +using namespace std; +long long p[100000], mi[60], temp; +char v[60]; +int main() +{ + int n,k,i,r,l,num,ans,max; + for(i=0,temp=1;i<60;i++) + { + mi[i]=temp; + temp<<=1; + } + while(scanf("%d%d%d",&n,&l,&k)!=EOF) + { + for(i=num=0;i>=1; + temp+=(v[r]-'0')*mi[k-1]; + p[num++]=temp; + } + } + sort(p,p+num); + ans=1; max=0; + for(i=1;ians?max:ans); + ans=1; + } + } + printf("%d\n",max); + } + return 0; +} diff --git a/HDOJ/2147_autoAC.cpp b/HDOJ/2147_autoAC.cpp new file mode 100644 index 0000000..ad0a93a --- /dev/null +++ b/HDOJ/2147_autoAC.cpp @@ -0,0 +1,14 @@ +#include +int main() +{ + int n,m; + while(scanf("%d%d",&n,&m)!=EOF) + { + if(n==0&&m==0) + break; + if((n*m)%2==0) + printf("Wonderful!\n"); + else + printf("What a pity!\n"); + } +} diff --git a/HDOJ/2148_autoAC.cpp b/HDOJ/2148_autoAC.cpp new file mode 100644 index 0000000..5464629 --- /dev/null +++ b/HDOJ/2148_autoAC.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +int a[1001]; +int main() +{ + int t,n,m,i,j,k; + cin>>t; + while(t--) + { + scanf("%d%d",&n,&m); + for(i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + int sum=0; + for(i=1;i<=n;i++) + { + if(a[i]>a[m]) sum++; + } + cout< +int main() +{ + int n,m,i; + while(scanf("%d%d",&n,&m)!=EOF) + { + if(n<=m) + { + for(i=n;i +#include +#include +#include +using namespace std; +#define MAX 100+5 +typedef long long LL; +const double pi=3.141592653589793; +const int INF=1e9; +const double inf=1e20; +const double eps=1e-6; +const int mod=1000000007; +struct point{ + int x,y; +}p[35][105]; +double circulation(point a,point b,point c){ + return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x); +} +bool cross(point a,point b,point c,point d){ + if(max(a.x,b.x)>=min(c.x,d.x)&& + max(c.x,d.x)>=min(a.x,b.x)&& + max(a.y,b.y)>=min(c.y,d.y)&& + max(c.y,d.y)>=min(a.y,b.y)&& + circulation(a,b,c)*circulation(a,d,b)>=0&& + circulation(a,c,d)*circulation(b,d,c)>=0) return true; + return false; +} +int main(){ + int n,k[35]; + while(cin>>n){ + memset(k,0,sizeof(k)); + memset(p,0,sizeof(p)); + for(int i=0;i>k[i]; + for(int j=0;j +#include +#include +using namespace std; +int main() +{ + int n,p,m,t; + while(cin >> n >> p >> m >> t) + { + long long s[110][110]; + memset(s,0,sizeof(s)); + s[0][p] = 1; + for(int i = 1;i <= m;i++) + { + for(int j = 1;j <= n;j++) + { + s[i][j] = s[i-1][j-1] + s[i-1][j+1]; + } + } + cout << s[m][t] << endl; + } + return 0; +} diff --git a/HDOJ/2152_autoAC.cpp b/HDOJ/2152_autoAC.cpp new file mode 100644 index 0000000..351bfb5 --- /dev/null +++ b/HDOJ/2152_autoAC.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +using namespace std; +#define M 1000 +int num[M],a[M],b[M]; +int c1[M],c2[M]; +#define mod 100 +#define LL long long +int main() +{ + int n,m; + while(scanf("%d %d",&n,&m)!=EOF) + { + for(int i=0;i>a[i]>>b[i]; + memset(c1,0,sizeof(c1)); + memset(c2,0,sizeof(c2)); + for(int i=a[0];i<=b[0];i++) + { + c1[i]=1; + } + for(int i=1;i +#include +int main() +{ + int n,i,j,k,t; + int a[20][20]; + while(scanf("%d",&n)!=EOF&&n) + { t=0; + memset(a,0,sizeof(a)); + i=1;j=1; + while(t<2*n+2*(n-2)) + { + while(j<=n) + { + t++;a[i][j]=t;j++; + } + j=j-1; + while(++i<=n) + { + t++;a[i][j]=t; + } + i=i-1; + while(--j>=1) + { + t++;a[i][j]=t; + } + j=j+1; + while(--i>1) + { + t++;a[i][j]=t; + } + } + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(a[i][j]!=0) + printf("%3d",a[i][j]); + else + printf(" "); + } + printf("\n"); + } + } + return 0; +} diff --git a/HDOJ/2154_autoAC.cpp b/HDOJ/2154_autoAC.cpp new file mode 100644 index 0000000..c98ec62 --- /dev/null +++ b/HDOJ/2154_autoAC.cpp @@ -0,0 +1,25 @@ +#include +#include +using namespace std; +int dp[1001][3]; +int main() +{ + int i,j,k,n; + memset(dp,0,sizeof(dp)); + dp[1][0]=0;dp[1][1]=1;dp[1][2]=1; + for(i=2;i<=1000;i++) + { + dp[i][0]+=dp[i-1][1]+dp[i-1][2]; + dp[i][0]=dp[i][0]%10000; + dp[i][1]+=dp[i-1][0]+dp[i-1][2]; + dp[i][1]=dp[i][1]%10000; + dp[i][2]+=dp[i-1][0]+dp[i-1][1]; + dp[i][2]=dp[i][2]%10000; + } + while(scanf("%d",&n)) + { + if(n==0) break; + cout< +#include +#include +#include +#include +using namespace std; +int bx,bh,n,H,T; +class Board{ +public: + int lt,rt,ht; + Board(){}; + bool operator <(const Board &b)const{ + return this->ht >b.ht; + } + bool in(int x){ + if(lt<=x&&rt>=x) return true; + return false; + } +}; +vector v; +bool dfs(int x,int ind,int cnt){ + if(cnt>T){ + return false; + } + if(ind==n||v[ind].ht==0){ + return true; + } + int lind,rind,k; + for( k=ind+1;k<=n;k++){ + if(v[k].in(v[ind].lt)){ + lind=k; + break; + } + } + for( k=ind+1;k<=n;k++){ + if(v[k].in(v[ind].rt)){ + rind=k; + break; + } + } + int lh=v[ind].ht-v[lind].ht; + int rh=v[ind].ht-v[rind].ht; + int lcnt=lh+x-v[ind].lt; + int rcnt=rh+v[ind].rt-x; + if(lcnt<=rcnt){ + if(lh<=H&&dfs(v[ind].lt,lind,cnt+lcnt)){ + return true; + } + if(rh<=H&&dfs(v[ind].rt,rind,cnt+rcnt)){ + return true; + } + }else{ + if(rh<=H&&dfs(v[ind].rt,rind,cnt+rcnt)){ + return true; + } + if(lh<=H&&dfs(v[ind].lt,lind,cnt+lcnt)){ + return true; + } + } + return false; +} +int main() +{ + int cas,i,ind; + scanf("%d",&cas); + while(cas--){ + if(cas==0){ + puts("YES"); + continue; + } + if(cas==1){ + puts("NO"); + continue; + } + scanf("%d%d%d%d%d",&n,&bx,&bh,&H,&T); + v.clear(); + v.resize(n+1); + for( i=0;i +int main(){ + double m,j,i; + while(scanf("%lf",&m)!=EOF&&m!=0){ + j=0;int k=1; + for(i=m;i>=1;i--) + j=j+1.00/i*k++; + printf("%.2f\n",2*j-m);} + return 0; +} diff --git a/HDOJ/2157_autoAC.cpp b/HDOJ/2157_autoAC.cpp new file mode 100644 index 0000000..c45ed52 --- /dev/null +++ b/HDOJ/2157_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +using namespace std; +const int N=22, M=1000; +int map[N][N],dp[N][N]; +int main() +{ + int i,r,j,n,m,k,s,t,T; + while(scanf("%d%d",&n,&m) && n+m) + { + memset(map,0,sizeof(map)); + for(i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +using namespace std; +const int MAX=100000+10; +int s[MAX],num[MAX],pos[MAX]; +int mark[MAX]; +int main(){ + int n,m,q,a; + while(cin>>n>>m,n+m){ + memset(mark,0,sizeof mark); + memset(pos,-1,sizeof pos); + for(int i=0;ir)r=pos[a]; + if(pos[a]r-l+1)maxlen=r-l+1; + } + cout< +#include +using namespace std; +#define MAX(a,b) (a>b?a:b) +struct Student +{ + int j,r; +}b[110]; +int a[110][110]; +int main() +{ + int i,j,n,m,s,k,t,ji; + while(~scanf("%d %d %d %d",&n,&m,&k,&s)) + { + for(i=1;i<=k;i++) + { + scanf("%d %d",&b[i].j,&b[i].r); + } + memset(a,0,sizeof(a)); + for(i=1;i<=k;i++) + { + for(j=1;j<=s;j++) + { + for(t=b[i].r;t<=m;t++) + { + a[j][t]=MAX(a[j-1][t-b[i].r]+b[i].j,a[j][t]); + } + } + } + ji=n; + for(i=0;i<=m;i++) + { + if(ji<=a[s][i]) + { + break; + } + } + if(i==m+1)printf("-1\n"); + else + { + printf("%d\n",m-i); + } + } + return 0; +} diff --git a/HDOJ/2160_autoAC.cpp b/HDOJ/2160_autoAC.cpp new file mode 100644 index 0000000..82a87a6 --- /dev/null +++ b/HDOJ/2160_autoAC.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +int pig[22]; +int main() +{ + int t,n,i; + pig[1]=1;pig[2]=2;pig[3]=3; + for(i=4;i<=20;i++) + pig[i]=pig[i-1]+pig[i-1]-pig[i-3]; + cin>>t; + while(t--) + { + cin>>n; + cout< +#include +int main(){ + int i, n, m, c = 1, flag; + while(scanf("%d", &n), n > 0){ + m = sqrt(n); + for(i = 2; i <= m + 1; i++){ + if(n % i == 0){flag = 0; break;} + else flag = 1; + } + if(n == 1) flag = 0; + if(flag) printf("%d: yes\n", c++); + else printf("%d: no\n", c++); + } + return 0; +} diff --git a/HDOJ/2162_autoAC.cpp b/HDOJ/2162_autoAC.cpp new file mode 100644 index 0000000..c6a76ad --- /dev/null +++ b/HDOJ/2162_autoAC.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +int main() +{ + int n,k=1; + while((cin>>n)&&n>0) + { + int sum=0,x; + for(int i=0;i>x; + sum+=x; + } + cout<<"Sum of #"< +#include +int main() +{ + char a[100],b[100]; + int cases=0; + while(gets(a)&&strcmp(a,"STOP")!=0) + { + cases++; + strcpy(b,a); + strrev(a); + if (strcmp(a,b)==0) + { + printf("#%d: YES\n",cases); + } + else + { + printf("#%d: NO\n",cases); + } + } +} diff --git a/HDOJ/2164_autoAC.cpp b/HDOJ/2164_autoAC.cpp new file mode 100644 index 0000000..1c5a077 --- /dev/null +++ b/HDOJ/2164_autoAC.cpp @@ -0,0 +1,28 @@ +#include +int main() +{ + int t,n,i,c1,c2; + char a,b,h; + scanf("%d",&t); + while(t--) + { + c1=c2=0; + scanf("%d",&n); + getchar(); + for(i=0;ic2) + printf("Player 1\n"); + else if(c1==c2) + printf("TIE\n"); + else + printf("Player 2\n"); + } +} diff --git a/HDOJ/2167_autoAC.cpp b/HDOJ/2167_autoAC.cpp new file mode 100644 index 0000000..c491d3a --- /dev/null +++ b/HDOJ/2167_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +typedef long long LL; +using namespace std; +const int MAX=1597+10; +int n,nowsize,size; +int dp[MAX],temp[MAX],ans[MAX],now[MAX]; +int w[16][16],head[MAX]; +char s[MAX]; +struct Edge{ + int v,next; + Edge(){} + Edge(int V,int NEXT):v(V),next(NEXT){} +}edge[MAX*MAX/2]; +void Init(int N){ + n=N; + memset(dp,0,sizeof dp); + memset(temp,0,sizeof temp); + memset(head,-1,sizeof head); + size=nowsize=0; +} +void InsertEdge(int u,int v){ + edge[size]=Edge(v,head[u]); + head[u]=size++; +} +void dfs(int k,int p){ + if(k>=n){now[++nowsize]=p;return;} + dfs(k+2,p|(1<>1))continue; + InsertEdge(i,j); + InsertEdge(j,i); + } + } + for(int k=1;k<=n;++k){ + for(int i=1;i<=nowsize;++i){ + ans[i]=cal(k,now[i]); + for(int j=head[i];j != -1;j=edge[j].next){ + dp[i]=max(dp[i],temp[edge[j].v]+ans[i]); + } + } + for(int i=1;i<=nowsize;++i)temp[i]=dp[i],dp[i]=0; + } +} +int main(){ + int k; + while(gets(s)){ + k=1; + do{ + n=0; + stringstream ss(s); + while(ss>>w[k][n])++n; + gets(s); + if(s[0] == '\0')break; + ++k; + }while(true); + Init(k); + DP(); + int sum=0; + for(int i=1;i<=nowsize;++i)sum=max(sum,temp[i]); + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/2169_autoAC.cpp b/HDOJ/2169_autoAC.cpp new file mode 100644 index 0000000..ce0ed96 --- /dev/null +++ b/HDOJ/2169_autoAC.cpp @@ -0,0 +1,49 @@ +#include +#include +int main() +{ + int n,i,j,k,sum,len,q,w = 1,p; + char c,a[16]; + scanf("%d",&n); + while(n--) + { + getchar(); + scanf("%c ",&c); + if(c=='b') + { + k=1; + sum=0; + scanf("%s",a); + len=strlen(a); + for(i=len-1;i>=0;i--) + { + sum=sum+(a[i]-'0')*k; + k=-2*k; + } + printf("From binary: %s is %d\n", a, sum); + } + else if(c=='d') + { + scanf("%d",&p); + i=0; + q=p; + if(p==0){printf("From decimal: 0 is 0\n");continue;} + while(p!=0) + { + a[i++]=p%(-2); + p=p/(-2); + if(a[i-1]==-1) + { + a[i-1]=1; + if(p<0)p--; + else p++; + } + } + printf("From decimal: %d is ",q); + for(j=i-1;j>=0;j--) + printf("%d",a[j]); + printf("\n"); + } + } + return 0; +} diff --git a/HDOJ/2171_autoAC.cpp b/HDOJ/2171_autoAC.cpp new file mode 100644 index 0000000..0815196 --- /dev/null +++ b/HDOJ/2171_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace std; +int main() +{ + int t; + string name[22]; + string s,s1; + char c; + int i,j,k,l,n; + cin>>t; + while(t--) + { + c=getchar(); + i=1; + getline(cin,s); + l=s.length(); + k=0; + for(j=0;j>s1; + cin>>n; + for(j=0;ji) k=1; + } + cout< +int main() +{ + unsigned __int64 temp,m,a[65]={0,1}; + int i,n,res; + for(i=2;i<=64;i++) + { + a[i]=a[i-1]*2+1; + } + while(scanf("%d%I64d",&n,&m)!=EOF&&(n!=0||m!=0)) + { + temp=a[n]+1; + for(i=n;i>=1;i--) + { + temp=temp/2; + if(temp==m) + { + res=i; + break; + } + if(temp +const int MAX=200001; +int s[MAX]; +using namespace std; +int main() +{ + int n,m,i,j,sum; + while(cin>>n,n!=0) + { + sum=0; + cin>>s[0]; + sum=s[0]; + for(i=1;i>s[i]; + sum^=s[i]; + } + if(!sum) + cout<<"No"< +#include +int main() + { + int n,m,j,k; + double i; + while(scanf("%d%d",&n,&m)&&n&&m) + { + k=m-n;i=(1+sqrt(5))/2; + j=k*i; + if(n==j) + printf( "0\n" ); + else + { + printf( "1\n" ); + if(n>j) + printf("%d %d\n",j,j+k ); + for(k=0;k*i<=n;k++) + if(int(k*i)==n-k) + printf("%d %d\n",n-k,n); + for(k=0;k*i<=m;k++) + if((int(k*i+k)==m)&&(m-k +int main() +{ + int t,n,a,b; + while(scanf("%d",&t)!=EOF) + { + while(t--) + { + scanf("%d",&n); + if(n>=1&&n<=30) + { + a=1; + for(b=1;b<=n;b++) + { + a=a*2; + } + a=a-1; + printf("%d\n",a); + } + } + } + return 0; +} diff --git a/HDOJ/2179_autoAC.cpp b/HDOJ/2179_autoAC.cpp new file mode 100644 index 0000000..8cbbba6 --- /dev/null +++ b/HDOJ/2179_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +int main() +{ + int x; + while(scanf("%d",&x)!=EOF&&x){ + float s; + int b,n,c,i,j,d,l,a[20000],sp; + x*=5; + s=0;n=1; + while (s<=x+10){ + s=s+log10((2*n+1)/(1.0*n)); + n++; + } + for(i=0;i<=x+5;i++) a[i]=0; + for(c=1,j=n;j>=1;j--){ + d=2*j+1; + for(i=0;i<=x+4;i++){ + a[i]=c/d; + c=(c%d)*10+a[i+1]; + } + a[x+5]=c/d; + for(b=0,i=x+5;i>=0;i--){ + a[i]=a[i]*j+b; + b=a[i]/10; + a[i]=a[i]%10; + } + a[0]=a[0]+1;c=a[0]; + } + for(b=0,i=x+5;i>=0;i--){ + a[i]=a[i]*2+b; + b=a[i]/10; + a[i]=a[i]%10; + } + puts("3."); + printf(" "); + for(i=1,sp=0;i<=x;++i){ + printf("%d",a[i]); + if(i%5==0) { + sp+=1; + if(i!=x&&(!sp||sp%10!=0)) printf(" "); + } + if(sp&&sp%10==0){ + sp=0; + if(i!=x)puts(""); + if(i!=x) printf(" "); + } + } + puts(""); + } +} diff --git a/HDOJ/2180_autoAC.cpp b/HDOJ/2180_autoAC.cpp new file mode 100644 index 0000000..6477cd1 --- /dev/null +++ b/HDOJ/2180_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +int main() +{ + int a,b,s,t; + int res1, res2, res; + while(1) + { + scanf("%d%d%d%d", &a, &b, &s, &t); + if(a == 0 && b == 0 && s == 0 && t == 0) + break; + a = a%12; + s = s%12; + res1 = (a*60+b)*11; + res2 = (s*60+t)*11; + if(res2 < res1) + res2 += 720*11; + res = res2/720 - res1/720; + if(res1 == 0) + res++; + printf("%d\n", res); + } + return 0; +} diff --git a/HDOJ/2181_autoAC.cpp b/HDOJ/2181_autoAC.cpp new file mode 100644 index 0000000..b1bc07f --- /dev/null +++ b/HDOJ/2181_autoAC.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; +int i,j ,n,m,t,times,p; +char map[21][21]; +char road[21],flag[21]; +void DFS(int n) +{ + int k; + times++; + flag[n]=0; + road[times]=n; + if(times==20&&map[n][t]) + { + printf("%d: ",p++); + for(int kk=1;kk<=20;kk++ ) + printf("%d ",road[kk]); + printf("%d\n",t); + } + for(k=1;k<=20;k++) + { + if(map[n][k]==1&&flag[k]) + { + DFS(k); + flag[k]=k; + times--; + } + } +} +void shuru() +{for(i=1;i<=20;i++) + for(j=1;j<=3;j++) + { + scanf("%d",&t); + map[i][t]=1; + } +} +int main() +{ + shuru(); + while(scanf("%d",&t),t) + {p=1; + times=0; + for(j=1;j<=20;j++) + flag[j]=j; + DFS(t); + } +} diff --git a/HDOJ/2182_autoAC.cpp b/HDOJ/2182_autoAC.cpp new file mode 100644 index 0000000..799aa8e --- /dev/null +++ b/HDOJ/2182_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +using namespace std; +const int N=300; +int n,a,b,k,t,ans; +int ins[N],vis[N][N]; +struct node{ + int x,val,t; + node() {} + node(int a, int b, int c): x(a), val(b), t(c) {} +}; +void bfs() +{ + queue v; + node tmp; + int i,px,pv,pt; + v.push( node(0,ins[0],0) ); + while(!v.empty()) + { + tmp=v.front(); v.pop(); + if(tmp.x>=n || tmp.t==k){ + ans=max(tmp.val,ans); + continue; + } + for(i=a;i<=b;i++) + { + px=tmp.x+i; pv=tmp.val+ins[px]; pt=tmp.t+1; + if(pv>vis[px][pt]){ + v.push( node(px,pv,pt) ); + vis[px][pt]=pv; + } + } + } +} +int main() +{ + scanf("%d",&t); + while(t--) + { + memset(ins,0,sizeof(ins)); + memset(vis,0,sizeof(vis)); + scanf("%d %d %d %d",&n, &a, &b, &k); + for(int i=0;i +#include +int main() +{ int x,y,n,a[25][25],i,j; + while(scanf("%d",&n)&&n!=0) + { x=n/2+1;y=n/2; + i=1; + while(i<=n*n) + {a[x][y]=i; + if(i%n!=0) + {x=x+1;y=y+1;} + else + x=x+2; + if(x>n-1)x=x-n; + if(y>n-1)y=y-n; + i++; + } + for(i=0;i +#include +long long a[70]; +int ans[5][70]; +int x[5]; +void solve(int A,int C,int n,long long m) +{ + if(m==a[n]) + { + for(int i=n;i>=1;i--) + ans[C][x[C]+i]=i; + x[C]+=n; + return ; + } + if(m>a[n]/2) + { + x[C]++; + ans[C][x[C]]=n; + solve( 6-A-C,C,n-1,m-a[n]/2-1); + } + else + { + x[A]++; + ans[A][x[A]]=n; + solve(A,6-A-C,n-1,m); + } + return ; +} +int main() +{ + int T,n; + a[1]=1; + for(int i=2;i<=63;i++) + { + a[i]=2*a[i-1]+1; + } + long long m; + scanf("%d",&T); + while(T--) + { + memset(x,0,sizeof(x)); + scanf("%d%lld",&n,&m); + solve(1,3,n,m); + int tmp; + for(int i=1;i<=3;i++) + { + printf("%d",x[i]); + for(int j=1;j<=x[i];j++) + printf(" %d",ans[i][j]); + printf("\n"); + } + } + return 0; +} diff --git a/HDOJ/2185_autoAC.cpp b/HDOJ/2185_autoAC.cpp new file mode 100644 index 0000000..d7fac59 --- /dev/null +++ b/HDOJ/2185_autoAC.cpp @@ -0,0 +1,28 @@ +#include +#include +using namespace std; +int dp[1005][16][16]; +int main() +{ + int w[1005]; + int b[1005]; + int sum=1; + while (cin>>w[sum]>>b[sum]) + sum++; + memset(dp,0,sizeof(dp)); + for (int i=1;i0&&dp[i][t][k]0&&dp[i][t][k] +using namespace std; +int main() +{ + int n; + cin>>n; + while(n--) + { + int x,t=0,a,b,c; + cin>>x; + a=x/2; + b=(x-a)*2/3; + c=x-a-b; + t+=a/10; + if(a%10) + t++; + t+=b/10; + if(b%10) + t++; + t+=c/10; + if(c%10) + t++; + cout< +#include +using namespace std; +struct rice +{ + int p; + int h; +}; +int cmp(rice x,rice y) +{return x.pst[i].p*st[i].h) + { + sum+=st[i].h; + n-=st[i].h*st[i].p; + } + else + { + sum+=n*1.0/st[i].p; + break; + } + } + printf("%.2lf\n",sum); + } +return 0; +} diff --git a/HDOJ/2188_autoAC.cpp b/HDOJ/2188_autoAC.cpp new file mode 100644 index 0000000..897a0e5 --- /dev/null +++ b/HDOJ/2188_autoAC.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; +int main() +{ + int c,n,m; + cin>>c; + while(c--) + { + cin>>n>>m; + if(n%(m+1)==0) + cout<<"Rabbit"< +#include +#include +#include +#include +#include +using namespace std; +int s[160]; +int a[160]; +void su(void) +{ + int i,j; + for(i=2;i<151;i++) + { + if(!s[i]) + { + for(j=i*2;j<151;j+=i) + { + s[j]=1; + } + } + } +} +int main() +{ + int i,j,t,n; + memset(s,0,sizeof(s)); + su(); + memset(a,0,sizeof(a)); + a[0]=1; + for(i=2;i<151;i++) + { + if(!s[i]) + { + for(j=i;j<151;j++) + { + a[j]+=a[j-i]; + } + } + } + while(~scanf("%d",&t)) + { + while(t--) + { + scanf("%d",&n); + printf("%d\n",a[n]); + } + } + return 0; +} diff --git a/HDOJ/2190_autoAC.cpp b/HDOJ/2190_autoAC.cpp new file mode 100644 index 0000000..4a9b9f2 --- /dev/null +++ b/HDOJ/2190_autoAC.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +const int maxn=32; +int arr[maxn]={0,1,3}; +void func( void ) +{ + for(int i=3;i<=maxn;i++ ) + arr[i]=arr[i-1]+2*arr[i-2]; +} +int main( void ) +{ + int t,n; + func(); + cin>>t; + while(t--) + { + cin>>n; + cout< +#include +#include +#include +using namespace std; +int value[105],weight[105],num[105],dp[1050]; +int n,t,m; +int main(){ + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&m,&n); + memset(dp,0,sizeof(dp)); + for(int i=1;i<=n;i++) + scanf("%d%d%d",&value[i],&weight[i],&num[i]); + for(int i=1;i<=n;i++) + { + for(int j=1;j<=num[i];j*=2) + { + for(int k=m;k>=value[i]*j;k--) + dp[k]=max(dp[k],dp[k-value[i]*j]+weight[i]*j); + num[i]-=j; + } + for(int k=m;k>=value[i]*num[i];k--) + dp[k]=max(dp[k],dp[k-value[i]*num[i]]+weight[i]*num[i]); + } + printf("%d\n",dp[m]); + } + return 0; +} diff --git a/HDOJ/2192_autoAC.cpp b/HDOJ/2192_autoAC.cpp new file mode 100644 index 0000000..d56e42d --- /dev/null +++ b/HDOJ/2192_autoAC.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +using namespace std; +int main() +{ + int t,n,i,a[10010],cun[10010],j,max; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + for(i=0;imax) + max=cun[i]; + } + printf("%d\n",max); + } + return 0; + } diff --git a/HDOJ/2193_autoAC.cpp b/HDOJ/2193_autoAC.cpp new file mode 100644 index 0000000..3ee2fcd --- /dev/null +++ b/HDOJ/2193_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +using namespace std; +#define inf 100000000 +#define max 100 +__int64 a[max]; +int main() +{ + int n; + a[0]=1; + a[1]=2; + int i; + int j; + for(i=2;a[i]<=inf;i++) + { + a[i]=i+1; + for(j=0;j<=i-2;j++) + a[i]+=a[j]; + } + while(1) + { + scanf("%d",&n); + if(n==0) + break; + for(j=0;n>=a[j];j++); + printf("%d\n",j-1); + } + return 0; +} diff --git a/HDOJ/2194_autoAC.cpp b/HDOJ/2194_autoAC.cpp new file mode 100644 index 0000000..55a65ae --- /dev/null +++ b/HDOJ/2194_autoAC.cpp @@ -0,0 +1,49 @@ +#include +int main(void) +{ + int n,k,i,j,flag,m,f[51],s[51],sum,x; + while (scanf("%d%d",&n,&k)!=EOF&&(n&&k)) + { + for(i=0;is[i+1]) + { + flag=1; + x=s[i+1]; + s[i+1]=s[i]; + s[i]=x; + } + } + m++; + } + sum=0; + for(i=0;i +#include +#include +using namespace std; +const int MAX=250; +int L; +char s[MAX]; +int dp[MAX][1010]; +void gs() +{ + int i,j; + int tt=s[1]=='0'?0:1000; + for(i=0;i<=1000;i++) dp[1][i]=(tt-i)*(tt-i); + int small; + for(i=2;i<=L;i++) + { + small=0x5fffffff; + tt=s[i]=='0'?0:1000; + for(j=0;j<=1000;j++) + { + if(small>dp[i-1][j]) small=dp[i-1][j]; + dp[i][j]=small+(tt-j)*(tt-j); + } + } +} +int main() +{ + while(scanf("%s",s+1)==1) + { + L=strlen(s+1); + gs(); + int ans=0x5fffffff; + for(int i=0;i<=1000;i++) ans=min(ans,dp[L][i]); + double aa=(double)ans/1000000; + printf("%.3lf\n",aa); + } + return 0; +} diff --git a/HDOJ/2196_autoAC.cpp b/HDOJ/2196_autoAC.cpp new file mode 100644 index 0000000..dde3ac4 --- /dev/null +++ b/HDOJ/2196_autoAC.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +using namespace std; +const int MAXN=10010; +struct Node +{ + int to; + int next; + int len; +}edge[MAXN*2]; +int head[MAXN]; +int tol; +int maxn[MAXN]; +int smaxn[MAXN]; +int maxid[MAXN]; +int smaxid[MAXN]; +void init() +{ + tol=0; + memset(head,-1,sizeof(head)); +} +void add(int a,int b,int len) +{ + edge[tol].to=b; + edge[tol].len=len; + edge[tol].next=head[a]; + head[a]=tol++; + edge[tol].to=a; + edge[tol].len=len; + edge[tol].next=head[b]; + head[b]=tol++; +} +void dfs1(int u,int p) +{ + maxn[u]=0; + smaxn[u]=0; + for(int i=head[u];i!=-1;i=edge[i].next) + { + int v=edge[i].to; + if(v==p)continue; + dfs1(v,u); + if(smaxn[u]maxn[u]) + { + swap(smaxn[u],maxn[u]); + swap(smaxid[u],maxid[u]); + } + } + } +} +void dfs2(int u,int p) +{ + for(int i=head[u];i!=-1;i=edge[i].next) + { + int v=edge[i].to; + if(v==p)continue; + if(v==maxid[u]) + { + if(edge[i].len+smaxn[u]>smaxn[v]) + { + smaxn[v]=edge[i].len+smaxn[u]; + smaxid[v]=u; + if(smaxn[v]>maxn[v]) + { + swap(smaxn[v],maxn[v]); + swap(smaxid[v],maxid[v]); + } + } + } + else + { + if(edge[i].len+maxn[u]>smaxn[v]) + { + smaxn[v]=edge[i].len+maxn[u]; + smaxid[v]=u; + if(smaxn[v]>maxn[v]) + { + swap(smaxn[v],maxn[v]); + swap(maxid[v],smaxid[v]); + } + } + } + dfs2(v,u); + } +} +int main() +{ + int n; + int v,len; + while(scanf("%d",&n)!=EOF) + { + init(); + for(int i=2;i<=n;i++) + { + scanf("%d%d",&v,&len); + add(i,v,len); + } + dfs1(1,-1); + dfs2(1,-1); + for(int i=1;i<=n;i++) + printf("%d\n",maxn[i]); + } + return 0; +} diff --git a/HDOJ/2197_autoAC.cpp b/HDOJ/2197_autoAC.cpp new file mode 100644 index 0000000..5ac2114 --- /dev/null +++ b/HDOJ/2197_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +using namespace std; +mapmp; +const int MOD=2008; +int fun(int a,int n){ + if(n==1)return a; + int num=fun(a,n/2); + num=num*num%MOD; + if(n%2==1)num=num*a%MOD; + return (num+MOD)%MOD; +} +int cal(int n){ + if(mp[n]!=0)return mp[n]; + mp[n]=fun(2,n)-2; + for(int i=2;i*i<=n;i++){ + if(n%i==0){ + mp[n]=(mp[n]-cal(i)+MOD)%MOD; + if(i*i!=n)mp[n]=(mp[n]-cal(n/i)+MOD)%MOD; + } + } + return mp[n]; +} +int main() +{ + int n; + while(scanf("%d",&n)!=EOF){ + mp[0]=0; + mp[1]=2; + mp[2]=2; + if(n<=2){cout< +#define max(a , b) ((a) > (b) ? (a) : (b)) +int LIS[55]; +int LDS[55]; +long long minlis[55]; +long long data[55]; +int binary(int l, int r , int x){ + int mid; + while(l <= r){ + mid = (l + r) >> 1; + if(minlis[mid] < x) l = mid + 1; + else r = mid -1; + } + return l; +} +int main(){ + int n, maxn, len; + while(~scanf("%d", &n) && n != 0){ + for(int i = 1; i <= n; i++) scanf("%lld", data + i); + minlis[1] = data[1]; LIS[1] = 1; len = 1; + for(int i = 2; i <= n; i++){ + LIS[i] = binary(1, len, data[i]); + minlis[LIS[i]] = data[i]; + if(LIS[i] > len) len++; + } + minlis[1] = data[n]; LDS[n] = 1; len = 1; + for(int i = n-1; i > 0; i--){ + LDS[i] = binary(1, len, data[i]); + minlis[LDS[i]] = data[i]; + if(LDS[i] > len) len++; + } + maxn = 0; + for(int i = 1; i <= n; i++) + maxn = max(maxn , LIS[i] + LDS[i] - 1); + printf("%d\n", n - maxn); + } + return 0; +} diff --git a/HDOJ/2199_autoAC.cpp b/HDOJ/2199_autoAC.cpp new file mode 100644 index 0000000..fce9e4c --- /dev/null +++ b/HDOJ/2199_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#define EPS (1e-6) +using namespace std; +double Y; +double f(double x){return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6-Y;} +double f_(double x){return 32*x*x*x+21*x*x+4*x+3;} +double NewtonIteration(double x,int counter=0) +{ + if(counter>10000)return -1; + double index=f(x)/f_(x); + return (fabs(index)=0&&ans<=100) + printf("%.4lf\n",ans); + else + printf("No solution!\n"); + } + return 0; +}