Powered By HC TECH : AutoACer Engine

2100-2199
This commit is contained in:
KiritoTRw 2016-08-22 00:08:26 +08:00 committed by GitHub
parent ddd34a4f1c
commit 26a72e347d
93 changed files with 4138 additions and 0 deletions

37
HDOJ/2100_autoAC.cpp Normal file
View File

@ -0,0 +1,37 @@
#include<stdio.h>
#include<string.h>
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);
}
}

12
HDOJ/2101_autoAC.cpp Normal file
View File

@ -0,0 +1,12 @@
#include<stdio.h>
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;
}

54
HDOJ/2102_autoAC.cpp Normal file
View File

@ -0,0 +1,54 @@
#include<iostream>
#include<cstring>
#include<algorithm>
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<n;j++)
scanf("%s",map[i][j]);
found=false;
memset(mark,0,sizeof(mark));
mark[0][0][0]=1;
dfs(0,0,0,0);
if(found)
printf("YES\n");
else printf("NO\n");
}
return 0;
}

35
HDOJ/2103_autoAC.cpp Normal file
View File

@ -0,0 +1,35 @@
#include<iostream>
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<m)
sum=10000*(powe(n-i-1)-1);
cout<<sum<<" RMB\n";
}
}
long long powe(int n)
{
long long sum=1;
for(int i=1;i<=n;++i)
sum*=2;
return sum;
}

15
HDOJ/2104_autoAC.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
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;
}

19
HDOJ/2105_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
#include <stdio.h>
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;
}

38
HDOJ/2106_autoAC.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
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;
}

19
HDOJ/2107_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
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;
}

42
HDOJ/2108_autoAC.cpp Normal file
View File

@ -0,0 +1,42 @@
#include<stdio.h>
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<n;i++)
{
scanf("%d %d",&a[i].x,&a[i].y);
}
a[n]=a[0];
a[n+1]=a[1];
for(i=0;i<n;i++)
{
s.x=a[i+1].x-a[i].x;
s.y=a[i+1].y-a[i].y;
t.x=a[i+2].x-a[i+1].x;
t.y=a[i+2].y-a[i+1].y;
if((s.x*t.y-s.y*t.x)<0)
{
flag=0;
break;
}
}
if(flag)
{
printf("convex\n");
}
else
{
printf("concave\n");
}
}
return 0;
}

34
HDOJ/2109_autoAC.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
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;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+n);
for(i=0;i<n;i++)
{
if(a[i]==b[i])
{
sum++;
sum1++;
}
if(a[i]>b[i])
sum+=2;
if(a[i]<b[i])
sum1+=2;
}
printf("%d vs %d\n",sum,sum1);
}
return 0;
}

45
HDOJ/2110_autoAC.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <stdio.h>
#include <memory.h>
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;
}

42
HDOJ/2111_autoAC.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
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;
}

96
HDOJ/2112_autoAC.cpp Normal file
View File

@ -0,0 +1,96 @@
#include<stdio.h>
#include<string.h>
#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]<dist[j])
{
dist[j]=dist[next]+map[next][j];
}
}
}
if(dist[2]==INF)
printf("-1\n");
else
printf("%d\n",dist[2]);
}
return 0;
}

29
HDOJ/2113_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<iostream>
#include<cstdio>
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;
}

11
HDOJ/2114_autoAC.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
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;
}

63
HDOJ/2115_autoAC.cpp Normal file
View File

@ -0,0 +1,63 @@
#include<stdio.h>
#include<string.h>
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;i++)
{
scanf("%s %d:%d",c[i],&a[i],&b[i]);
getchar();
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i])
{
s=a[j];a[j]=a[i];a[i]=s;
s=b[j];b[j]=b[i];b[i]=s;
strncpy(q,c[j],50);strncpy(c[j],c[i],50);strncpy(c[i],q,50);
}
}
}
for(i=0;i<n-1;i++)
{
for(j=i+1;a[j]==a[i];j++)
{
if(b[j]<b[i])
{
s=a[j];a[j]=a[i];a[i]=s;
s=b[j];b[j]=b[i];b[i]=s;
strncpy(q,c[j],50);strncpy(c[j],c[i],50);strncpy(c[i],q,50);
}
if(j>=n)
break;
}
}
if(k!=1)
putchar('\n');
printf("Case #%d\n",k);
k++;
for(i=0;i<n-1;i++)
{
for(j=i+1;a[j]==a[i]&&b[j]==b[i];j++)
{
if(strcmp(c[j],c[i])<0)
{
strncpy(q,c[j],50);strncpy(c[j],c[i],50);strncpy(c[i],q,50);
}
}
}
for(i=0;i<n;i++)
{
if(i>0&&a[i]==a[i-1]&&b[i]==b[i-1])
mc=mc;
else
mc=i+1;
printf("%s %d\n",c[i],mc);
}
}
}

124
HDOJ/2116_autoAC.cpp Normal file
View File

@ -0,0 +1,124 @@
#include <iostream>
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<k;i++)
{
int j;
for(j=70;j>=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"<<endl;
}else
{
cout<<"WaHaHa"<<endl;
}
}
return 0;
}

17
HDOJ/2117_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<stdio.h>
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;
}

52
HDOJ/2118_autoAC.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
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]<f[i][j]-K+energy[xx][yy]))
{
f[xx][yy]=f[i][j]-K+energy[xx][yy];
}
}
}
}
int ans=-1;
for(i=1;i<=(n-1)*m+1;i++)
{
if(f[n][i]>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;
}

60
HDOJ/2119_autoAC.cpp Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
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<<ans1<<endl;
}
return 0;
}

38
HDOJ/2120_autoAC.cpp Normal file
View File

@ -0,0 +1,38 @@
#include<stdio.h>
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<m;i++)
{
scanf("%d%d",&a,&b);
a=yxc(a);
b=yxc(b);
if(a==b)
{
num++;
}
else
{
parent[a]=b;
}
}
printf("%d\n",num);
}
return 0;
}

108
HDOJ/2121_autoAC.cpp Normal file
View File

@ -0,0 +1,108 @@
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#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;
}

81
HDOJ/2122_autoAC.cpp Normal file
View File

@ -0,0 +1,81 @@
#include<stdio.h>
#include<string.h>
#include<algorithm>
#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.money<b.money;
}
int find(int p)
{
int child=p;
int t;
while(p!=set[p])
p=set[p];
while(child!=p)
{
t=set[child];
set[child]=p;
child=t;
}
return p;
}
void merge(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
set[fx]=fy;
}
int main()
{
int i,j,x,y,c,t,need,exist;
while(scanf("%d%d",&city,&road)!=EOF)
{
for(i=0;i<city;i++)
set[i]=i;
t=0;
while(road--)
{
scanf("%d%d%d",&x,&y,&c);
num[t].start=x;
num[t].end=y;
num[t].money=c;
t++;
}
sort(num,num+t,cmp);
need=0;
for(i=0;i<t;i++)
{
if(find(num[i].start)!=find(num[i].end))
{
merge(num[i].start,num[i].end);
need+=num[i].money;
}
}
exist=0;
for(i=0;i<city;i++)
{
if(set[i]==i)
{
exist++;
if(exist>1)
break;
}
}
if(exist>1)
printf("impossible\n\n");
else
printf("%d\n\n",need);
}
return 0;
}

17
HDOJ/2123_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<stdio.h>
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<a;j++)
printf("%d ",i*j);
printf("%d\n",i*a);
}
}
return 0;
}

45
HDOJ/2124_autoAC.cpp Normal file
View File

@ -0,0 +1,45 @@
#include<iostream>
#include<string>
#include <cstdio>
#include <cmath>
#include<vector>
#include<algorithm>
#include<sstream>
#include<cstdlib>
using namespace std;
typedef __int64 ll;
bool comp(ll a,ll b){
return a>b;
}
int main()
{
int n;
ll L,ai;
vector<ll> buf;
while(cin>>L>>n)
{
for(int i=0;i<n;i++)
{
cin>>ai;
buf.push_back(ai);
}
sort(buf.begin(),buf.end(),comp);
int min=0;
ll sum=0;
for(vector<ll>::size_ i=0;i!=buf.size()&&sum<L;i++)
{
if(sum+buf[i]<L){
sum+=buf[i];
min++;
}
else {
sum=L;
min++;
}
}
if(sum<L)cout<<"impossible"<<endl;
else cout<<min<<endl;
buf.clear();
}
return 0;
}

51
HDOJ/2125_autoAC.cpp Normal file
View File

@ -0,0 +1,51 @@
#include<stdio.h>
#include<string.h>
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<m;l++)
{
if(x==0 && l==y)dp[0][l]=0;
else dp[0][l]=dp[0][l-1];
}
for(i=1;i<n;i++)
{
for(l=0;l<m;l++)
{
if(i==x && l==y)
{
if(l!=0)
{
if(flag==-1) dp[i][l]=dp[i][l-1];
else dp[i][l]=dp[i-1][l];
}
else
{
if(flag==-1) dp[i][l]=0;
else dp[i][l]=dp[i-1][l];
}
}
else
{
if(l==0) dp[i][l]=dp[i-1][l];
else dp[i][l]=dp[i-1][l]+dp[i][l-1];
}
}
}
printf("%d\n",dp[n-1][m-1]);
}
return 0;
}

33
HDOJ/2126_autoAC.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <iostream>
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;
}

135
HDOJ/2127_autoAC.cpp Normal file
View File

@ -0,0 +1,135 @@
#include <iostream>
#include <string>
#include <algorithm>
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;
}

94
HDOJ/2128_autoAC.cpp Normal file
View File

@ -0,0 +1,94 @@
#include <stdio.h>
#include <string.h>
#include <queue>
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_queue<node>q;
int i,j;
for(i=0; i<n; i++)
for(j=0; j<m; j++)
t.mp[i][j]=s[i][j];
t.step=0;
t.num=0;
t.x=x;
t.y=y;
vis[t.x][t.y][0]++;
q.push(t);
while(!q.empty())
{
t=q.top();
if(t.x==ex && t.y==ey)
return t.step;
for(i=0; i<4; i++)
{
t.step++;
t.x+=dir[i][1];
t.y+=dir[i][0];
if(t.x>=0 && t.x<n && t.y>=0 && t.y<m && vis[t.x][t.y][t.num]<50)
{
if(t.mp[t.x][t.y]=='.')
{
vis[t.x][t.y][t.num]++;
q.push(t);
}
else if(t.mp[t.x][t.y]=='X' && t.num>0)
{
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<n; i++)
scanf("%s",s[i]);
for(i=0; i<n; i++)
for(j=0; j<m; j++)
{
if(s[i][j]=='S')
{
s[i][j]='.';
x1=i,y1=j;
}
else if(s[i][j]=='D')
{
s[i][j]='.';
ex=i,ey=j;
}
}
memset(vis,0,sizeof vis);
printf("%d\n",bfs(x1,y1));
}
}

208
HDOJ/2129_autoAC.cpp Normal file
View File

@ -0,0 +1,208 @@
#include<iostream>
#include<string.h>
#include<algorithm>
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]<y->price[1])
return 1;
if(x->price[1]>y->price[1])
return -1;
if(x->price[2]<y->price[2])
return 1;
if(x->price[2]>y->price[2])
return -1;
if(x->price[3]<y->price[3])
return 1;
if(x->price[3]>y->price[3])
return -1;
if(x->name>y->name)
return 1;
if(x->name<y->name)
return -1;
return 0;
}
int cmpbytm(const void *a,const void *b)
{
team *x=(team *)a;
team *y=(team *)b;
if(x->price[1]<y->price[1])
return 1;
if(x->price[1]>y->price[1])
return -1;
if(x->price[2]<y->price[2])
return 1;
if(x->price[2]>y->price[2])
return -1;
if(x->price[3]<y->price[3])
return 1;
if(x->price[3]>y->price[3])
return -1;
if(x->name>y->name)
return 1;
if(x->name<y->name)
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->name<y->name)
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<N;i++)
{
cin>>tschool>>tteam>>tprice>>tplace;
for(j=0;j<nowplacelen;j++)
{
if(plc[j].name==tplace)
break;
}
if(j==nowplacelen)
{
plc[j].name=tplace;
plc[j].price[1]=0;
plc[j].price[2]=0;
plc[j].price[3]=0;
plc[j].price[tellprice(tprice)]=1;
nowplacelen++;
}
else
{
plc[j].price[tellprice(tprice)]++;
}
for(j=0;j<nowschoollen;j++)
{
if(scl[j].name==tschool)
break;
}
if(j==nowschoollen)
{
scl[j].name=tschool;
scl[j].price[1]=0;
scl[j].price[2]=0;
scl[j].price[3]=0;
scl[j].price[tellprice(tprice)]=1;
nowschoollen++;
scl[j].tm[0].name=tteam;
scl[j].tm[0].price[1]=0;
scl[j].tm[0].price[2]=0;
scl[j].tm[0].price[3]=0;
scl[j].tm[0].price[tellprice(tprice)]=1;
scl[j].nowteamlen=1;
}
else
{
scl[j].price[tellprice(tprice)]++;
for(t=0;t<scl[j].nowteamlen;t++)
{
if(tteam==scl[j].tm[t].name)
break;
}
if(t==scl[j].nowteamlen)
{
scl[j].tm[t].name=tteam;
scl[j].tm[t].price[1]=0;
scl[j].tm[t].price[2]=0;
scl[j].tm[t].price[3]=0;
scl[j].tm[t].price[tellprice(tprice)]=1;
scl[j].nowteamlen++;
}
else
{
scl[j].tm[t].price[tellprice(tprice)]++;
}
}
}
printf("Case %d:\n****************\n",pp);
printf("school number: %d\n",nowschoollen);
qsort(scl,nowschoollen,sizeof(scl[0]),cmpbyscl);
for(i=0;i<nowschoollen;i++)
{
qsort(scl[i].tm,scl[i].nowteamlen,sizeof(scl[i].tm[0]),cmpbytm);
}
qsort(plc,nowplacelen,sizeof(plc[0]),cmpbyplc);
cout<<scl[0].name<<" "<<1<<" "<<scl[0].price[1]<<" "<<scl[0].price[2]<<" "<<scl[0].price[3]<<endl;
printf(" team number: %d\n",scl[0].nowteamlen);
cout<<" "<<scl[0].tm[0].name<<" "<<1<<" "<<scl[0].tm[0].price[1]
<<" "<<scl[0].tm[0].price[2]<<" "<<scl[0].tm[0].price[3]<<endl;
for(int j=1,tt=1;j<scl[0].nowteamlen;j++)
{
if((scl[0].tm[j].price[1]!=scl[0].tm[j-1].price[1])||(scl[0].tm[j].price[2]!=scl[0].tm[j-1].price[2])||(scl[0].tm[j].price[3]!=scl[0].tm[j-1].price[3]))
tt=j+1;
cout<<" "<<scl[0].tm[j].name<<" "<<tt<<" "<<scl[0].tm[j].price[1]
<<" "<<scl[0].tm[j].price[2]<<" "<<scl[0].tm[j].price[3]<<endl;
}
for(i=1,t=1;i<nowschoollen;i++)
{
if((scl[i].price[1]!=scl[i-1].price[1])||(scl[i].price[2]!=scl[i-1].price[2])||(scl[i].price[3]!=scl[i-1].price[3]))
t=i+1;
cout<<scl[i].name<<" "<<t<<" "<<scl[i].price[1]<<" "<<scl[i].price[2]<<" "<<scl[i].price[3]<<endl;
printf(" team number: %d\n",scl[i].nowteamlen);
cout<<" "<<scl[i].tm[0].name<<" "<<1<<" "<<scl[i].tm[0].price[1]
<<" "<<scl[i].tm[0].price[2]<<" "<<scl[i].tm[0].price[3]<<endl;
for(int j=1,tt=1;j<scl[i].nowteamlen;j++)
{
if((scl[i].tm[j].price[1]!=scl[i].tm[j-1].price[1])||(scl[i].tm[j].price[2]!=scl[i].tm[j-1].price[2])||(scl[i].tm[j].price[3]!=scl[i].tm[j-1].price[3]))
tt=j+1;
cout<<" "<<scl[i].tm[j].name<<" "<<tt<<" "<<scl[i].tm[j].price[1]
<<" "<<scl[i].tm[j].price[2]<<" "<<scl[i].tm[j].price[3]<<endl;
}
}
printf("****************\n\n");
printf("contest number: %d\n",nowplacelen);
for(i=0;i<nowplacelen;i++)
{
cout<<plc[i].name<<" "<<plc[i].price[1]<<" "<<plc[i].price[2]<<" "<<plc[i].price[3]<<endl;
}
printf("****************\n");
}
return 0;
}

12
HDOJ/2130_autoAC.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
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;
}

24
HDOJ/2131_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include<stdio.h>
#include<string.h>
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<l;i++)
{
if(c[i]<='Z')
c[i]+=32;
if(c[i]==h)
n++;
}
s=n/l;
printf("%.5lf\n",s);
}
}

32
HDOJ/2132_autoAC.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <cstdio>
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;
}

63
HDOJ/2133_autoAC.cpp Normal file
View File

@ -0,0 +1,63 @@
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<iomanip>
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;i<m;++i)
ret+=a[i];
a[2]=28;
return ret;
}
bool isno(int y,int m,int d){
if(isleap(y))a[2]=29;
if(m>12||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"<<endl;
continue;
}
int x=f(y,m,d)%7-1;
if(y<2008){
for(int i=y;i<2008;++i)
if(isleap(i))x+=5;
else x+=6;
}
else {
for(int i=2008;i<y;++i)
if(isleap(i))x+=2;
else x+=1;
}
x%=7;
if(x<0)x+=7;
switch(x){
case 0:cout<<"Tuesday"<<endl;break;
case 1:cout<<"Wednesday"<<endl;break;
case 2:cout<<"Thursday"<<endl;break;
case 3:cout<<"Friday"<<endl;break;
case 4:cout<<"Saturday"<<endl;break;
case 5:cout<<"Sunday"<<endl;break;
case 6:cout<<"Monday"<<endl;break;
}
}
return 0;
}

9
HDOJ/2134_autoAC.cpp Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
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;
}

36
HDOJ/2135_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include <cstdio>
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<<a[i][j];
}
if(!k)
cout<<endl;
}
}
}
return 0;
}

26
HDOJ/2136_autoAC.cpp Normal file
View File

@ -0,0 +1,26 @@
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
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<MAX;i++)
{
if(x[i]==-1)
{
sum+=1;
for(j=i;j<MAX;j+=i)
x[j]=sum;
}
}
while(scanf("%d",&n)!=EOF)
printf("%d\n",x[n]);
return 0;
}

91
HDOJ/2137_autoAC.cpp Normal file
View File

@ -0,0 +1,91 @@
#include<stdio.h>
#include<string.h>
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<i;j++)
{
putchar(' ');
}
printf("%c\n",c[i]);
}
}
if(n==2)
{
for(i=strlen(c)-1;i>=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<strlen(c)-1-i;j++)
{
putchar(' ');
}
printf("%c\n",c[i]);
}
}
if(n==4)
{
for(i=strlen(c)-1;i>=0;i--)
{
putchar(c[i]);
}
putchar('\n');
}
if(n==5)
{
for(i=0;i<strlen(c);i++)
{
for(j=0;j<strlen(c)-1-i;j++)
{
putchar(' ');
}
printf("%c\n",c[i]);
}
}
if(n==6)
{
for(i=0;i<strlen(c);i++)
{
for(j=0;j<l/2;j++)
{
putchar(' ');
}
printf("%c\n",c[i]);
}
}
if(n==7)
{
for(i=0;i<strlen(c);i++)
{
for(j=0;j<i;j++)
{
putchar(' ');
}
printf("%c\n",c[i]);
}
}
}
}

27
HDOJ/2138_autoAC.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <iostream>
#include <cmath>
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<<sum<<endl;
}
return 0;
}

16
HDOJ/2139_autoAC.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<stdio.h>
__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;
}

20
HDOJ/2140_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <string.h>
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<l;i++){
n=0;
for(int j=0;j<=9;j++)
if(c[i]==a[j]){
printf("%c",b[j]);
n=1;}
if(n!=1) printf("%c",c[i]);
}
printf("\n");
}
return 0;
}

60
HDOJ/2141_autoAC.cpp Normal file
View File

@ -0,0 +1,60 @@
#include<cstdio>
#include<iostream>
#include<algorithm>
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<<":"<<endl;
for(i=0;i<a;i++)
{
scanf("%d",&a_1[i]);
}
for(i=0;i<b;i++)
{
scanf("%d",&b_1[i]);
}
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
sum[b*i+j]=a_1[i]+b_1[j];
}
}
sort(sum,sum+a*b);
for(i=0;i<c;i++)
{
scanf("%d",&c_1[i]);
}
int t,x,n;
scanf("%d",&t);
int flag;
while(t--)
{
scanf("%d",&x);
flag=0;
for(i=0;i<c;i++)
{
if((binary_search(sum,sum+a*b,x-c_1[i])!=0))
{
flag=1;
}
}
if(flag==1)
cout<<"YES"<<endl;
else
{
cout<<"NO"<<endl;
}
}
}
return 0;
}

112
HDOJ/2142_autoAC.cpp Normal file
View File

@ -0,0 +1,112 @@
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef struct
{
double score;
string name;
}disney;
bool cmp(disney a,disney b)
{
if(a.score==b.score)
return a.name<b.name;
else
return a.score>b.score;
}
int sum=0;
void NEW(disney a[],disney b)
{
int i;
for(i=0;i<sum;i++)
if(a[i].name==b.name)
break;
if(i==sum&&sum<=100)
{
a[sum].name=b.name;
a[sum].score=b.score;
sum++;
cout<<"A new record"<<endl;
}
else
{
a[i].score=b.score;
cout<<"update succeed"<<endl;
}
}
void average(disney a[])
{
if(sum==0)
{
cout<<"0.00"<<endl;
return ;
}
int i;
double s=0,t;
for(i=0;i<sum;i++)
s+=a[i].score;
t=s/sum;
printf("%.2lf\n",t);
}
void Max(disney a[])
{
if(sum==0)
{
cout<<"0 0"<<endl;
return ;
}
int i,num=0;
sort(a,a+sum,cmp);
for(i=1;i<sum;i++)
{
if(a[i].score==a[i-1].score)
num++;
else
break;
}
cout<<a[0].score<<" "<<num+1<<endl;
for(i=0;i<=num;i++)
cout<<a[i].name<<endl;
}
void Delete(disney a[],string s)
{
int i;
for(i=0;i<sum;i++)
if(a[i].name==s)
break;
if(i==sum)
cout<<"no such record"<<endl;
else
{cout<<"delete succeed"<<endl;
a[i].score=0;
sort(a,a+sum,cmp);
sum--;
}
}
int main()
{
disney a[100];
disney b;
string s,str;
while(cin>>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;
}

19
HDOJ/2143_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
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;
}

61
HDOJ/2144_autoAC.cpp Normal file
View File

@ -0,0 +1,61 @@
#include<iostream>
#include<cstdio>
#include<cstring>
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;i<n;i++) pre[i]=i;
for(i=0;i<n;i++)
{
scanf("%s",str[i]+1);
str[i][0]=' ';
len[i]=strlen(str[i])-1;
for(l=0;l<i;l++)
{
f1=find(i);
f2=find(l);
if(f1==f2) continue;
cnt=cal(i,l);
if(cnt*100.0/len[i]>limit && cnt*100.0/len[l]>limit) pre[f1]=f2;
}
}
ans=0;
for(i=0;i<n;i++) if(pre[i]==i) ans++;
printf("Case %d:\n",Case++);
cout<<ans<<endl;
}
return 0;
}

108
HDOJ/2145_autoAC.cpp Normal file
View File

@ -0,0 +1,108 @@
#include<stdio.h>
#include<string.h>
#include<queue>
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.dis<n1.dis;
}
};
struct Eage
{
int from;
int to;
int len;
int next;
}eage[5055];
int tot;
int head[333];
void add(int a,int b,int c)
{
eage[tot].from=a;
eage[tot].to=b;
eage[tot].len=c;
eage[tot].next=head[a];
head[a]=tot++;
}
int cmp(const void *a,const void *b)
{
struct A *c,*d;
c=(struct A *)a;
d=(struct A *)b;
if(c->ans>d->ans) return 1;
else if(c->ans<d->ans) return -1;
if(c->len!=d->len) return d->len-c->len;
return d->num-c->num;
}
void Dij()
{
priority_queue<node>q;
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<city[eage[temp].to].dis)
{
city[eage[temp].to].dis=city[cur.num].dis+eage[temp].len;
next.num=eage[temp].to;
next.dis=city[eage[temp].to].dis;
q.push(next);
}
temp=eage[temp].next;
}
}
}
int main()
{
int a,b,c;
int i;
while(scanf("%d%d%d",&n,&m,&q)!=-1)
{
tot=0;
memset(head,-1,sizeof(head));
while(q--)
{
scanf("%d%d%d",&a,&b,&c);
add(b,a,c);
}
scanf("%d",&e);
for(i=0;i<m;i++) scanf("%d",&E[i].s);
for(i=0;i<m;i++) {scanf("%d",&E[i].v);E[i].num=i+1;}
for(i=1;i<=n;i++) {city[i].dis=11111111;city[i].flag=1;}
city[e].dis=0;
Dij();
for(i=0;i<m;i++) {E[i].len=city[E[i].s].dis;E[i].ans=1.0*E[i].len/E[i].v;}
qsort(E,m,sizeof(E[0]),cmp);
if(E[0].len==11111111) printf("No one\n");
else printf("%d\n",E[0].num);
}
return 0;
}

46
HDOJ/2146_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
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<n;i++)
{
scanf("%s",v);
temp=0;
for(r=0;r<k;r++)
temp+=(v[r]-'0')*mi[r];
p[num++]=temp;
for(r=k;r<l;r++)
{
temp>>=1;
temp+=(v[r]-'0')*mi[k-1];
p[num++]=temp;
}
}
sort(p,p+num);
ans=1; max=0;
for(i=1;i<num;i++)
{
if(p[i]==p[i-1]) ans++;
else
{
max=(max>ans?max:ans);
ans=1;
}
}
printf("%d\n",max);
}
return 0;
}

14
HDOJ/2147_autoAC.cpp Normal file
View File

@ -0,0 +1,14 @@
#include<stdio.h>
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");
}
}

23
HDOJ/2148_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include<iostream>
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<<sum<<endl;
}
return 0;
}

25
HDOJ/2149_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n<=m)
{
for(i=n;i<m;i++)
{
printf("%d ",i);
}
printf("%d\n",i);
}
else
{
if(n%(m+1))
{
printf("%d\n",n%(m+1));
}
else
printf("none\n");
}
}
}

58
HDOJ/2150_autoAC.cpp Normal file
View File

@ -0,0 +1,58 @@
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
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<n;i++){
cin>>k[i];
for(int j=0;j<k[i];j++) scanf("%d%d",&p[i][j].x,&p[i][j].y);
}
if(n==1){
printf("No\n");
continue;
}
int flag=0;
for(int i=0;i<n-1;i++){
for(int j=1;j<k[i];j++){
for(int t=i+1;t<n;t++){
for(int h=1;h<k[t];h++){
if(cross(p[i][j-1],p[i][j],p[t][h-1],p[t][h])){
flag=1;
break;
}
}
}
}
}
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}

23
HDOJ/2151_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include<iostream>
#include<algorithm>
#include<cstring>
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;
}

41
HDOJ/2152_autoAC.cpp Normal file
View File

@ -0,0 +1,41 @@
#include<iostream>
#include<string.h>
#include<cstdio>
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<n;i++)
cin>>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<n;i++)
{
for(int j=0;j<=m;j++)
{
for(int k=a[i];k+j<=m&&k<=b[i];k++)
{
c2[j+k]+=c1[j];
}
}
for(int j=0;j<=m;j++)
{
c1[j]=c2[j];
c2[j]=0;
}
}
cout<<c1[m]<<endl;
}
return 0;
}

46
HDOJ/2153_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<stdio.h>
#include<string.h>
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;
}

25
HDOJ/2154_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<iostream>
#include<string.h>
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<<dp[n][0]<<endl;
}
return 0;
}

98
HDOJ/2155_autoAC.cpp Normal file
View File

@ -0,0 +1,98 @@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
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<Board> 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<n;i++){
scanf("%d%d%d",&v[i].lt,&v[i].rt,&v[i].ht);
}
v[n].lt=-1;
v[n].rt=1001;
v[n].ht=0;
sort(v.begin(),v.end());
for(i=0;i<=n;i++){
if(v[i].in(bx)){
ind=i;
break;
}
}
if(dfs(bx,ind,bh-v[ind].ht)){
puts("NO");
}else{
puts("YES");
};
}
return 0;
}

10
HDOJ/2156_autoAC.cpp Normal file
View File

@ -0,0 +1,10 @@
#include<stdio.h>
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;
}

36
HDOJ/2157_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
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<m;i++){
scanf("%d%d",&s,&t);
map[s+1][t+1]=1;
}
scanf("%d",&T);
while( T-- )
{
memset(dp,0,sizeof(dp));
scanf("%d%d%d",&s,&t,&k);
s++; t++;
dp[0][s]=1;
for(i=1;i<=k;i++)
for(r=1;r<=n;r++)
for(j=1;j<=n;j++)
if( map[r][j] ){
dp[i][j]+=dp[i-1][r];
dp[i][j]%=M;
}
printf("%d\n",dp[k][t]);
}
}
return 0;
}

50
HDOJ/2158_autoAC.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#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;i<n;++i){
scanf("%d",&s[i]);
if(pos[s[i]] == -1)pos[s[i]]=i;
}
s[n]=n;
for(int i=1;i<=m;++i){
scanf("%d",&q);
int l=n,r=-1,maxlen=INF;
for(int j=0;j<q;++j){
scanf("%d",&a);
num[a]=0;
mark[a]=i;
if(pos[a]>r)r=pos[a];
if(pos[a]<l)l=pos[a];
}
for(int j=l;j<=r;++j)++num[s[j]];
maxlen=r-l+1;
while(r<n){
--num[s[l]];
if(num[s[l]] == 0){
while(++r<n && s[r] != s[l])++num[s[r]];
num[s[r]]=1;
}
while(++l<=r && mark[s[l]] != i);
if(r<n && maxlen>r-l+1)maxlen=r-l+1;
}
cout<<maxlen<<endl;
}
}
return 0;
}

45
HDOJ/2159_autoAC.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
#include <string.h>
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;
}

17
HDOJ/2160_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<iostream>
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<<pig[n]<<endl;
}
return 0;
}

16
HDOJ/2161_autoAC.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <math.h>
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;
}

17
HDOJ/2162_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <iostream>
using namespace std;
int main()
{
int n,k=1;
while((cin>>n)&&n>0)
{
int sum=0,x;
for(int i=0;i<n;i++)
{
cin>>x;
sum+=x;
}
cout<<"Sum of #"<<k++<<" is "<<sum<<endl;
}
return 0;
}

21
HDOJ/2163_autoAC.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
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);
}
}
}

28
HDOJ/2164_autoAC.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<stdio.h>
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;i<n;i++)
{
scanf("%c%c%c",&a,&h,&b);
getchar();
if((a=='R'&&b=='S')||(a=='S'&&b=='P')||(a=='P'&&b=='R'))
c1++;
else if((b=='R'&&a=='S')||(b=='S'&&a=='P')||(b=='P'&&a=='R'))
c2++;
}
if(c1>c2)
printf("Player 1\n");
else if(c1==c2)
printf("TIE\n");
else
printf("Player 2\n");
}
}

88
HDOJ/2167_autoAC.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#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<<k));
dfs(k+1,p);
}
int cal(int k,int p){
int sum=0;
for(int i=0;i<15;++i){
if(p & (1<<i))sum+=w[k][i];
}
return sum;
}
void DP(){
dfs(0,0);
for(int i=1;i<=nowsize;++i){
for(int j=i+1;j<=nowsize;++j){
if(now[i] & now[j])continue;
if(now[i] & (now[j]<<1))continue;
if(now[i] & (now[j]>>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;
}

49
HDOJ/2169_autoAC.cpp Normal file
View File

@ -0,0 +1,49 @@
#include<stdio.h>
#include<string.h>
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;
}

46
HDOJ/2171_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<iostream>
#include<string>
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<l;j++)
{
if(s[j]==' ')
{
name[i]=s.substr(k,j-k);
i++;
k=j+1;
}
if(j==l-1)
{
name[i]=s.substr(k,j-k+1);
i++;
k=j+1;
}
}
cin>>s1;
cin>>n;
for(j=0;j<i;j++)
if(name[j]==s1) {k=j;break;}
i--;
for(j=1;j<n;j++)
{
k++;
if(k>i) k=1;
}
cout<<name[k]<<endl;
}
}

29
HDOJ/2175_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<stdio.h>
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<m)
m=m-temp;
else
m=temp-m;
}
printf("%d\n",res);
}
return 0;
}

32
HDOJ/2176_autoAC.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<iostream>
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<n;i++)
{
cin>>s[i];
sum^=s[i];
}
if(!sum)
cout<<"No"<<endl;
else
{
cout<<"Yes"<<endl;
for(i=0;i<n;i++)
{
j=sum^s[i];
if(j<s[i])
cout<<s[i]<<" "<<j<<endl;
}
}
}
return 0;
}

30
HDOJ/2177_autoAC.cpp Normal file
View File

@ -0,0 +1,30 @@
#include<stdio.h>
#include<math.h>
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<n))
printf("%d %d\n",m-k,m);
for(k=0;k*i<=n+1;k++)
if((int(k*i)==n)&&(n+k<m))
printf("%d %d\n",n,n+k);
}
}
return 0;
}

23
HDOJ/2178_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include<stdio.h>
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;
}

51
HDOJ/2179_autoAC.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <math.h>
#include<stdio.h>
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("");
}
}

24
HDOJ/2180_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
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;
}

47
HDOJ/2181_autoAC.cpp Normal file
View File

@ -0,0 +1,47 @@
#include<iostream>
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);
}
}

52
HDOJ/2182_autoAC.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
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<node> 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<n;i++)
scanf("%d",&ins[i]);
ans=0;
bfs();
printf("%d\n",ans);
}
return 0;
}

25
HDOJ/2183_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<stdio.h>
#include<math.h>
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<n;i++)
{for(j=0;j<n;j++)
printf("%4d",a[i][j]);
printf("\n");
}
}
return 0;
}

54
HDOJ/2184_autoAC.cpp Normal file
View File

@ -0,0 +1,54 @@
#include<stdio.h>
#include<string.h>
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;
}

28
HDOJ/2185_autoAC.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <iostream>
#include <string.h>
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;i<sum;i++)
{
for (int t=0;t<=i&&t<=15;t++)
{
for (int k=0;k<=15&&k<=i-t;k++)
{
dp[i][t][k]=dp[i-1][t][k];
if (t>0&&dp[i][t][k]<dp[i-1][t-1][k]+w[i])
dp[i][t][k]=dp[i-1][t-1][k]+w[i];
if (k>0&&dp[i][t][k]<dp[i-1][t][k-1]+b[i])
dp[i][t][k]=dp[i-1][t][k-1]+b[i];
}
}
}
cout<<dp[sum-1][15][15]<<endl;
}

25
HDOJ/2186_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<iostream>
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<<t<<endl;
}
}

43
HDOJ/2187_autoAC.cpp Normal file
View File

@ -0,0 +1,43 @@
#include<stdio.h>
#include<algorithm>
using namespace std;
struct rice
{
int p;
int h;
};
int cmp(rice x,rice y)
{return x.p<y.p;}
int main()
{
int c,n,m,i;
double sum;
rice st[1001];
scanf("%d",&c);
while(c--)
{
scanf("%d%d",&n,&m);
sum=0;
for(i=0;i<m;i++)
{
scanf("%d",&st[i].p);
scanf("%d",&st[i].h);
}
sort(st,st+m,cmp);
for(i=0;i<m;i++)
{
if(n>st[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;
}

15
HDOJ/2188_autoAC.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <iostream>
using namespace std;
int main()
{
int c,n,m;
cin>>c;
while(c--)
{
cin>>n>>m;
if(n%(m+1)==0)
cout<<"Rabbit"<<endl;
else
cout<<"Grass"<<endl;
}
}

50
HDOJ/2189_autoAC.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<iostream>
#include<string.h>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
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;
}

21
HDOJ/2190_autoAC.cpp Normal file
View File

@ -0,0 +1,21 @@
#include<iostream>
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<<arr[n]<<endl;
}
return 0;
}

30
HDOJ/2191_autoAC.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
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;
}

34
HDOJ/2192_autoAC.cpp Normal file
View File

@ -0,0 +1,34 @@
#include<stdio.h>
#include<iostream>
#include<algorithm>
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;i<n;i++)
{
scanf("%d",&a[i]);
cun[i]=1;
}
sort(a,a+n);j=0;
for(i=0;i<n;i++)
{
if(a[i]==a[i+1])
cun[j]++;
else
j++;
}
max=cun[0];
for(i=1;i<=j;i++)
{
if(cun[i]>max)
max=cun[i];
}
printf("%d\n",max);
}
return 0;
}

29
HDOJ/2193_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<iostream>
#include<cstdio>
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;
}

49
HDOJ/2194_autoAC.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <stdio.h>
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;i<n;i++)
{
f[i]=1;
scanf("%d",&s[i]);
}
flag=1;m=1;
while (flag)
{
flag=0;
for(i=0;i<n-m;i++)
{
if(s[i]>s[i+1])
{
flag=1;
x=s[i+1];
s[i+1]=s[i];
s[i]=x;
}
}
m++;
}
sum=0;
for(i=0;i<n;i++)
{
if(f[i]==0)
{
continue;
}
for(j=i+1;j<n;j++)
{
if(f[j]==0) continue;
if(s[i]*k==s[j])
{
f[j]=0;
f[i]=0;
sum++;
break;
}
}
}
printf("%d\n",sum);
}
}

38
HDOJ/2195_autoAC.cpp Normal file
View File

@ -0,0 +1,38 @@
#include<iostream>
#include<algorithm>
#include<cstring>
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;
}

109
HDOJ/2196_autoAC.cpp Normal file
View File

@ -0,0 +1,109 @@
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
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[v]+edge[i].len)
{
smaxn[u]=maxn[v]+edge[i].len;
smaxid[u]=v;
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;
}

39
HDOJ/2197_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;
map<int,int>mp;
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<<mp[n]<<endl;continue;}
int ans=cal(n);
cout<<ans<<endl;
}
return 0;
}

38
HDOJ/2198_autoAC.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <cstdio>
#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;
}

31
HDOJ/2199_autoAC.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#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)<EPS)?(x-index):NewtonIteration(x-index,counter+1);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf",&Y);
double ans=NewtonIteration(0);
if(ans>=0&&ans<=100)
printf("%.4lf\n",ans);
else
printf("No solution!\n");
}
return 0;
}