From 1c7c39b791e9e1bed07e4a61b62eada77deb80a0 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sun, 4 Sep 2016 15:25:29 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine 4200-4299 --- HDOJ/4200_autoAC.cpp | 123 ++++++++++++++++++ HDOJ/4203_autoAC.cpp | 24 ++++ HDOJ/4205_autoAC.cpp | 64 ++++++++++ HDOJ/4206_autoAC.cpp | 40 ++++++ HDOJ/4207_autoAC.cpp | 9 ++ HDOJ/4209_autoAC.cpp | 33 +++++ HDOJ/4210_autoAC.cpp | 156 +++++++++++++++++++++++ HDOJ/4211_autoAC.cpp | 30 +++++ HDOJ/4212_autoAC.cpp | 91 +++++++++++++ HDOJ/4213_autoAC.cpp | 103 +++++++++++++++ HDOJ/4215_autoAC.cpp | 18 +++ HDOJ/4216_autoAC.cpp | 56 ++++++++ HDOJ/4217_autoAC.cpp | 48 +++++++ HDOJ/4218_autoAC.cpp | 27 ++++ HDOJ/4219_autoAC.cpp | 86 +++++++++++++ HDOJ/4221_autoAC.cpp | 33 +++++ HDOJ/4223_autoAC.cpp | 31 +++++ HDOJ/4224_autoAC.cpp | 31 +++++ HDOJ/4225_autoAC.cpp | 226 +++++++++++++++++++++++++++++++++ HDOJ/4226_autoAC.cpp | 70 ++++++++++ HDOJ/4227_autoAC.cpp | 73 +++++++++++ HDOJ/4228_autoAC.cpp | 49 +++++++ HDOJ/4229_autoAC.cpp | 33 +++++ HDOJ/4230_autoAC.cpp | 115 +++++++++++++++++ HDOJ/4231_autoAC.cpp | 189 +++++++++++++++++++++++++++ HDOJ/4233_autoAC.cpp | 93 ++++++++++++++ HDOJ/4234_autoAC.cpp | 80 ++++++++++++ HDOJ/4235_autoAC.cpp | 16 +++ HDOJ/4236_autoAC.cpp | 22 ++++ HDOJ/4237_autoAC.cpp | 13 ++ HDOJ/4238_autoAC.cpp | 80 ++++++++++++ HDOJ/4239_autoAC.cpp | 83 ++++++++++++ HDOJ/4240_autoAC.cpp | 112 ++++++++++++++++ HDOJ/4242_autoAC.cpp | 54 ++++++++ HDOJ/4243_autoAC.cpp | 48 +++++++ HDOJ/4244_autoAC.cpp | 295 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/4245_autoAC.cpp | 38 ++++++ HDOJ/4246_autoAC.cpp | 38 ++++++ HDOJ/4247_autoAC.cpp | 15 +++ HDOJ/4248_autoAC.cpp | 48 +++++++ HDOJ/4249_autoAC.cpp | 85 +++++++++++++ HDOJ/4251_autoAC.cpp | 82 ++++++++++++ HDOJ/4252_autoAC.cpp | 37 ++++++ HDOJ/4253_autoAC.cpp | 114 +++++++++++++++++ HDOJ/4254_autoAC.cpp | 24 ++++ HDOJ/4255_autoAC.cpp | 110 ++++++++++++++++ HDOJ/4256_autoAC.cpp | 21 +++ HDOJ/4258_autoAC.cpp | 51 ++++++++ HDOJ/4259_autoAC.cpp | 81 ++++++++++++ HDOJ/4260_autoAC.cpp | 19 +++ HDOJ/4261_autoAC.cpp | 82 ++++++++++++ HDOJ/4262_autoAC.cpp | 60 +++++++++ HDOJ/4263_autoAC.cpp | 55 ++++++++ HDOJ/4264_autoAC.cpp | 163 ++++++++++++++++++++++++ HDOJ/4265_autoAC.cpp | 185 +++++++++++++++++++++++++++ HDOJ/4266_autoAC.cpp | 179 ++++++++++++++++++++++++++ HDOJ/4267_autoAC.cpp | 52 ++++++++ HDOJ/4268_autoAC.cpp | 51 ++++++++ HDOJ/4269_autoAC.cpp | 163 ++++++++++++++++++++++++ HDOJ/4270_autoAC.cpp | 97 ++++++++++++++ HDOJ/4271_autoAC.cpp | 88 +++++++++++++ HDOJ/4272_autoAC.cpp | 95 ++++++++++++++ HDOJ/4273_autoAC.cpp | 255 +++++++++++++++++++++++++++++++++++++ HDOJ/4274_autoAC.cpp | 74 +++++++++++ HDOJ/4275_autoAC.cpp | 187 +++++++++++++++++++++++++++ HDOJ/4276_autoAC.cpp | 99 +++++++++++++++ HDOJ/4277_autoAC.cpp | 71 +++++++++++ HDOJ/4278_autoAC.cpp | 28 ++++ HDOJ/4279_autoAC.cpp | 50 ++++++++ HDOJ/4280_autoAC.cpp | 105 +++++++++++++++ HDOJ/4281_autoAC.cpp | 86 +++++++++++++ HDOJ/4282_autoAC.cpp | 65 ++++++++++ HDOJ/4283_autoAC.cpp | 38 ++++++ HDOJ/4284_autoAC.cpp | 78 ++++++++++++ HDOJ/4285_autoAC.cpp | 190 ++++++++++++++++++++++++++++ HDOJ/4286_autoAC.cpp | 218 ++++++++++++++++++++++++++++++++ HDOJ/4287_autoAC.cpp | 88 +++++++++++++ HDOJ/4288_autoAC.cpp | 50 ++++++++ HDOJ/4289_autoAC.cpp | 116 +++++++++++++++++ HDOJ/4290_autoAC.cpp | 79 ++++++++++++ HDOJ/4292_autoAC.cpp | 102 +++++++++++++++ HDOJ/4293_autoAC.cpp | 29 +++++ HDOJ/4294_autoAC.cpp | 81 ++++++++++++ HDOJ/4295_autoAC.cpp | 47 +++++++ HDOJ/4296_autoAC.cpp | 20 +++ HDOJ/4297_autoAC.cpp | 199 +++++++++++++++++++++++++++++ 86 files changed, 7042 insertions(+) create mode 100644 HDOJ/4200_autoAC.cpp create mode 100644 HDOJ/4203_autoAC.cpp create mode 100644 HDOJ/4205_autoAC.cpp create mode 100644 HDOJ/4206_autoAC.cpp create mode 100644 HDOJ/4207_autoAC.cpp create mode 100644 HDOJ/4209_autoAC.cpp create mode 100644 HDOJ/4210_autoAC.cpp create mode 100644 HDOJ/4211_autoAC.cpp create mode 100644 HDOJ/4212_autoAC.cpp create mode 100644 HDOJ/4213_autoAC.cpp create mode 100644 HDOJ/4215_autoAC.cpp create mode 100644 HDOJ/4216_autoAC.cpp create mode 100644 HDOJ/4217_autoAC.cpp create mode 100644 HDOJ/4218_autoAC.cpp create mode 100644 HDOJ/4219_autoAC.cpp create mode 100644 HDOJ/4221_autoAC.cpp create mode 100644 HDOJ/4223_autoAC.cpp create mode 100644 HDOJ/4224_autoAC.cpp create mode 100644 HDOJ/4225_autoAC.cpp create mode 100644 HDOJ/4226_autoAC.cpp create mode 100644 HDOJ/4227_autoAC.cpp create mode 100644 HDOJ/4228_autoAC.cpp create mode 100644 HDOJ/4229_autoAC.cpp create mode 100644 HDOJ/4230_autoAC.cpp create mode 100644 HDOJ/4231_autoAC.cpp create mode 100644 HDOJ/4233_autoAC.cpp create mode 100644 HDOJ/4234_autoAC.cpp create mode 100644 HDOJ/4235_autoAC.cpp create mode 100644 HDOJ/4236_autoAC.cpp create mode 100644 HDOJ/4237_autoAC.cpp create mode 100644 HDOJ/4238_autoAC.cpp create mode 100644 HDOJ/4239_autoAC.cpp create mode 100644 HDOJ/4240_autoAC.cpp create mode 100644 HDOJ/4242_autoAC.cpp create mode 100644 HDOJ/4243_autoAC.cpp create mode 100644 HDOJ/4244_autoAC.cpp create mode 100644 HDOJ/4245_autoAC.cpp create mode 100644 HDOJ/4246_autoAC.cpp create mode 100644 HDOJ/4247_autoAC.cpp create mode 100644 HDOJ/4248_autoAC.cpp create mode 100644 HDOJ/4249_autoAC.cpp create mode 100644 HDOJ/4251_autoAC.cpp create mode 100644 HDOJ/4252_autoAC.cpp create mode 100644 HDOJ/4253_autoAC.cpp create mode 100644 HDOJ/4254_autoAC.cpp create mode 100644 HDOJ/4255_autoAC.cpp create mode 100644 HDOJ/4256_autoAC.cpp create mode 100644 HDOJ/4258_autoAC.cpp create mode 100644 HDOJ/4259_autoAC.cpp create mode 100644 HDOJ/4260_autoAC.cpp create mode 100644 HDOJ/4261_autoAC.cpp create mode 100644 HDOJ/4262_autoAC.cpp create mode 100644 HDOJ/4263_autoAC.cpp create mode 100644 HDOJ/4264_autoAC.cpp create mode 100644 HDOJ/4265_autoAC.cpp create mode 100644 HDOJ/4266_autoAC.cpp create mode 100644 HDOJ/4267_autoAC.cpp create mode 100644 HDOJ/4268_autoAC.cpp create mode 100644 HDOJ/4269_autoAC.cpp create mode 100644 HDOJ/4270_autoAC.cpp create mode 100644 HDOJ/4271_autoAC.cpp create mode 100644 HDOJ/4272_autoAC.cpp create mode 100644 HDOJ/4273_autoAC.cpp create mode 100644 HDOJ/4274_autoAC.cpp create mode 100644 HDOJ/4275_autoAC.cpp create mode 100644 HDOJ/4276_autoAC.cpp create mode 100644 HDOJ/4277_autoAC.cpp create mode 100644 HDOJ/4278_autoAC.cpp create mode 100644 HDOJ/4279_autoAC.cpp create mode 100644 HDOJ/4280_autoAC.cpp create mode 100644 HDOJ/4281_autoAC.cpp create mode 100644 HDOJ/4282_autoAC.cpp create mode 100644 HDOJ/4283_autoAC.cpp create mode 100644 HDOJ/4284_autoAC.cpp create mode 100644 HDOJ/4285_autoAC.cpp create mode 100644 HDOJ/4286_autoAC.cpp create mode 100644 HDOJ/4287_autoAC.cpp create mode 100644 HDOJ/4288_autoAC.cpp create mode 100644 HDOJ/4289_autoAC.cpp create mode 100644 HDOJ/4290_autoAC.cpp create mode 100644 HDOJ/4292_autoAC.cpp create mode 100644 HDOJ/4293_autoAC.cpp create mode 100644 HDOJ/4294_autoAC.cpp create mode 100644 HDOJ/4295_autoAC.cpp create mode 100644 HDOJ/4296_autoAC.cpp create mode 100644 HDOJ/4297_autoAC.cpp diff --git a/HDOJ/4200_autoAC.cpp b/HDOJ/4200_autoAC.cpp new file mode 100644 index 0000000..3890841 --- /dev/null +++ b/HDOJ/4200_autoAC.cpp @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include +using namespace std; +#define INF 1000000000 +#define N 110 +#define M 210 +int n, d; +bool mat[N][N], val[N]; +void print(bool a[N][N], int n) +{ + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= n+1; j++) + { + printf("%d ", a[i][j]); + } + printf("\n"); + } + printf("\n"); +} +int dfs(int col, int cnt) +{ + if(col == n+1) + { + int res = cnt; + for(int i = 1; i <= n; i++) + { + if(val[i] ^ mat[i][n+1]) res++; + } + return res; + } + int res = 0; + for(int i = 1; i <= n; i++) + val[i] ^= mat[i][col]; + res = dfs(col+1, cnt+1); + for(int i = 1; i <= n; i++) + val[i] ^= mat[i][col]; + res = min(dfs(col+1, cnt), res); + return res; +} +int gauss() +{ + int row = 1; + int r = n; + for(int i = 1; i <= r; i++, row++) + { + int p = -1; + for(int j = row; j <= n; j++) + { + if(mat[j][i] == 1) + { + p = j; + break; + } + } + if(p == -1) + { + for(int j = 1; j <= n; j++) + { + swap(mat[j][i], mat[j][r]); + } + //print(mat, n); + r--; + i--; + row--; + continue; + } + if(p != row) + { + for(int j = i; j <= n+1; j++) + { + swap(mat[row][j], mat[p][j]); + } + } + for(int j = 1; j <= n; j++) + { + if(mat[j][i] == 1 && j != row) + for(int k = i; k <= n+1; k++) + { + mat[j][k] ^= mat[row][k]; + } + } + } + for(int i = row; i <= n; i++) + { + if(mat[i][n+1] == 1) + { + return -1; + } + } + memset(val, 0, sizeof(val)); + int ans = dfs(row, 0); + return ans; +} +int main() +{ + int t; scanf("%d", &t); + while(t--) + { + scanf("%d%d", &n, &d); + memset(mat, 0, sizeof(mat)); + for(int i = 1; i <= n; i++) + { + scanf("%d", &mat[i][n+1]); + } + for(int i = 1; i <= n; i++) + { + int st = max(1, i-d), ed = min(n, i+d); + for(int j = st; j <= ed; j++) + { + mat[i][j] = 1; + } + } + int ans = gauss(); + if(ans != -1) + printf("%d\n", ans); + else printf("impossible\n"); + } + return 0; +} diff --git a/HDOJ/4203_autoAC.cpp b/HDOJ/4203_autoAC.cpp new file mode 100644 index 0000000..c71ce6b --- /dev/null +++ b/HDOJ/4203_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +using namespace std; +int main(){ + int i,t,T,k,s; + scanf("%d",&T); + for(t=1;t<=T;t++){ + scanf("%d %d",&s,&k); + if(k&1){ + if(s&1)printf("1\n"); + else printf("0\n"); + } + else{ + int tem=s%(k+1); + if(tem==k)printf("%d\n",k); + else{ + if(tem&1)printf("1\n"); + else printf("0\n"); + } + } + } +} diff --git a/HDOJ/4205_autoAC.cpp b/HDOJ/4205_autoAC.cpp new file mode 100644 index 0000000..7652a3e --- /dev/null +++ b/HDOJ/4205_autoAC.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +using namespace std; +#define N 1010 +#define inf 2000000010 +struct node{ + int x,li,id; +}w[N]; +bool cmp(const node &a,const node &b){ + if(a.x!=b.x) return a.xb.li; +} +int dp[N][N]; +int main(){ + int T,n,id; + scanf("%d",&T); + while(T--){ + scanf("%d",&n); + int Min=-inf; + for(int i=0;i>1); + for(int i=1;i>1); + int r=w[i].x+(w[i].li+1>>1); + for(int j=0;j<=i;++j) + if(dp[i-1][j]<=l) + dp[i][j+1]=r; + continue; + } + for(int j=0;j<=i;++j){ + dp[i][j]=min(dp[i][j],dp[i-1][j]); + if(dp[i-1][j]!=inf){ + if(dp[i-1][j]<=w[i].x){ + int temp=max(dp[i-1][j]+w[i].li,w[i].x); + dp[i][j+1]=min(dp[i][j+1],temp); + } + } + } + } + for(int i=n;i;--i) + if(dp[n-1][i]!=inf){ + printf("%d\n",i); + break; + } + } + return 0; +} diff --git a/HDOJ/4206_autoAC.cpp b/HDOJ/4206_autoAC.cpp new file mode 100644 index 0000000..771bf8d --- /dev/null +++ b/HDOJ/4206_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +using namespace std; +int main(void) +{ + int cas; + scanf("%d", &cas); + while(cas--) + { + int n, a, b, z, y; + scanf("%d", &n); + int tempn = (int)sqrt((double)n); + int ansY, ansZ; + ansY = ansZ = INT_MAX; + for(int i = 1; i <= tempn; i++) + { + if(n % i == 0) + { + a = n / i; + b = i; + if((a + b) % 2 == 0) + { + z = (a + b) / 2; + y = z - min(a, b); + if(z < ansZ || y < ansY) + { + ansY = y, ansZ = z; + } + } + } + } + if(ansZ == INT_MAX) + { + printf("IMPOSSIBLE\n"); + } + else + printf("%d %d\n", ansY, ansZ); + } + return 0; +} diff --git a/HDOJ/4207_autoAC.cpp b/HDOJ/4207_autoAC.cpp new file mode 100644 index 0000000..4827f7b --- /dev/null +++ b/HDOJ/4207_autoAC.cpp @@ -0,0 +1,9 @@ + 432 + 5678 +------- + 3456 + 3024 + 2592 +2160 +------- +2452896 diff --git a/HDOJ/4209_autoAC.cpp b/HDOJ/4209_autoAC.cpp new file mode 100644 index 0000000..bc3e76a --- /dev/null +++ b/HDOJ/4209_autoAC.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +struct node +{ + int d; + int p; +}; +typedef int Case; +node nod[10]; +const double PI=3.1415926; +int main() +{ + int n; + Case cas=1; + while(cin>>n,n) + { + double min=1000000,area,sq; + int rem; + for(int i=0;i>nod[i].d>>nod[i].p; + area=PI*(nod[i].d/2.0)*(nod[i].d/2.0); + sq=nod[i].p/area; + if(min>sq) + { + min=sq; + rem=nod[i].d; + } + } + cout<<"Menu "< +#include +#include +using namespace std; +const int N = 10; +struct Domino +{ + int x,y; +}d[40]; +struct Uncover +{ + int x,y; +}u[N*N]; +int map[N][N],st[3][9],t,num; +int dir[2][2]={{0,1},{1,0}}; +bool vis[N][N],flag; +void init() +{ + for(int i=1;i<=8;i++) + for(int j=i+1;j<=9;j++) + { + d[t].x=i,d[t].y=j; + t++; + } +} +bool isfinish() +{ + for(int i=0;i<3;i++) + for(int j=0;j<9;j++) + if(st[i][j]!=((1<<9)-1)) + return false; + return true; +} +bool check(int x,int y,int xx,int yy,int first,int second) +{ + int ss1=(x/3)*3+y/3,ss2=(xx/3)*3+yy/3; + first--,second--; + if((st[0][x]&(1<=9 || yy<0 || yy>=9 || map[xx][yy]!=0) + continue; + if(!check(x,y,xx,yy,first,second)) + continue; + map[x][y]=first,map[xx][yy]=second; + if(map[u[temp+1].x][u[temp+1].y]==0) + dfs(temp+1); + else { + while(temp +#include +#include +using namespace std; +int main() +{ + char str[100]; + int a[200]; + while(gets(str) != NULL) + { + if(strcmp(str, "END") == 0) + break; + int l=strlen(str); + int i; + memset(a, 0, sizeof(a)); + for( i=0; i < l; i++ ) + { + if(str[i] >= 'A' && str[i] <= 'Z') + a[str[i]]++; + } + for( i='A'; i <= 'Z'; i++ ) + { + if(a[i] > 1) + break; + } + if(i > 'Z') + puts(str); + } + return 0; +} diff --git a/HDOJ/4212_autoAC.cpp b/HDOJ/4212_autoAC.cpp new file mode 100644 index 0000000..a34c3ca --- /dev/null +++ b/HDOJ/4212_autoAC.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include +using namespace std; +vector a[23]; +int ans,nn; +int b[22]; +int tp=1<<22; +void init() +{ + for(int i=1;i22) break; + } + tmp>>=1; + } + if(!tmp) a[sum].push_back(i); + } +} +inline int total_one(int p) +{ + int c=0; + while(p) + { + p&=p-1; + c++; + } + return c; +} +int main() +{ + int T=0; + int n,m; + init(); + while(scanf("%d%d",&n,&m)!=EOF) + { + if(n+m==0) break; + nn=1< now; + now.insert(0); + for(int i=0;i next; + for(set::iterator it=now.begin();it!=now.end();it++) + { + int temp=a[b[i]].size(); + int sign=0; + int tmp=*it; + for(int j=0;j=nn) continue; + if((tmp & a[b[i]][j]) ==0) + { + sign=1; + next.insert(tmp | a[b[i]][j]); + } + } + if(!sign) + { + int _tmp=total_one(tmp); + ans=ans>_tmp?ans:_tmp; + } + } + now=next; + if(now.size()==0) break; + } + for(set::iterator it=now.begin();it!=now.end();it++) + { + int _tmp=total_one(*it); + ans=ans>_tmp?ans:_tmp; + } + printf("Game %d: %d\n",T,ans); + } + return 0; +} diff --git a/HDOJ/4213_autoAC.cpp b/HDOJ/4213_autoAC.cpp new file mode 100644 index 0000000..a458c20 --- /dev/null +++ b/HDOJ/4213_autoAC.cpp @@ -0,0 +1,103 @@ +#include +#include +#define maxn 20 +char map[maxn][maxn]; +bool aim[maxn][maxn]; +bool complete; +int dirx[4]={-1,1,0,0},diry[4]={0,0,-1,1}; +int startx,starty; +int n,m; +void run(char *s) +{ + for(;*s;s++) + { + int dir; + if(*s=='U') dir=0; + else if(*s=='D') dir=1; + else if(*s=='L') dir=2; + else dir=3; + int tx=startx+dirx[dir],ty=starty+diry[dir]; + if(map[tx][ty]!='#') + { + int nextx=tx+dirx[dir],nexty=ty+diry[dir]; + bool flag=false; + if(map[tx][ty]=='b'&&map[nextx][nexty]!='b'&&map[nextx][nexty]!='#') + { + map[tx][ty]='w'; + map[nextx][nexty]='b'; + map[startx][starty]='.'; + startx=tx,starty=ty; + flag=true; + } + else if(map[tx][ty]=='.'||map[tx][ty]=='+') + { + map[tx][ty]='w'; + map[startx][starty]='.'; + startx=tx,starty=ty; + } + if(flag) + { + int t1=0,t2=0; + for(int i=0;i +#include +using namespace std; +int main() +{ + int answer[31]={0,1,1,2,2,4,5,5,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,9,9,9,9,9,9,10}; + int n,c; + scanf("%d",&c); + for(int t=1;t<=c;t++) + { + scanf("%d",&n); + if(n<30) + printf("Case %d: %d\n",t,answer[n]); + else + printf("Case %d: 10\n",t); + } + return 0; +} diff --git a/HDOJ/4216_autoAC.cpp b/HDOJ/4216_autoAC.cpp new file mode 100644 index 0000000..ba19b07 --- /dev/null +++ b/HDOJ/4216_autoAC.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +using namespace std; +#define D 10000 +#define max(a,b) ((a)>(b)?(a):(b)) +#define min(a,b) ((a)<(b)?(a):(b)) +int num[105][2]; +int dp[2][20005][2]; +int T,n,x,y; +double dis(int a,int b) +{ + double c=(double)a,d=(double)b; + return sqrt((c-x)*(c-x)+(d-y)*(d-y)); +} +int main() +{ + scanf("%d",&T); + for(int cas=1; cas<=T; ++cas) + { + scanf("%d%d%d",&n,&x,&y); + x+=D; + y+=D; + for(int i=1; i<=n; ++i) + { + scanf("%d%d",&num[i][0],&num[i][1]); + } + memset(dp,-1,sizeof(dp)); + dp[0][D][0]=dp[0][D][1]=D; + for(int i=1; i<=n; ++i) + { + for(int j=0; j<=20000; ++j) + for(int k=0; k<2; ++k) + { + if(dp[(i-1)&1][j][k]!=-1) + { + if(dp[i&1][j+num[i][1]][0]==-1||dp[i&1][j+num[i][1]][0]>dp[(i-1)&1][j][k]+num[i][0]) + dp[i&1][j+num[i][1]][0]=dp[(i-1)&1][j][k]+num[i][0]; + if(dp[i&1][j-num[i][1]][0]==-1||dp[i&1][j-num[i][1]][0]>dp[(i-1)&1][j][k]-num[i][0]) + dp[i&1][j-num[i][1]][0]=dp[(i-1)&1][j][k]-num[i][0]; + if(dp[i&1][j+num[i][1]][1]==-1||dp[i&1][j+num[i][1]][1]>1; + if(l==r) {T[k].sum=1;return ;} + build(l,T[k].mid,2*k); + build(T[k].mid+1,r,2*k+1); + T[k].sum=T[2*k].sum+T[2*k+1].sum; +} +int find(int tot,int k) +{ + int ans; + if(T[k].l==T[k].r) {T[k].sum=0;return T[k].l;} + if(tot<=T[2*k].sum) ans=find(tot,2*k); + else ans=find(tot-T[2*k].sum,2*k+1); + T[k].sum=T[2*k].sum+T[2*k+1].sum; + return ans; +} +int main() +{ + int T,Case; + int n,m; + int t,temp; + __int64 ans; + scanf("%d",&T); + for(Case=1;Case<=T;Case++) + { + scanf("%d%d",&n,&m); + build(1,n,1); + ans=0; + while(m--) + { + scanf("%d",&t); + ans+=find(t,1); + } + printf("Case %d: %I64d\n",Case,ans); + } + return 0; +} diff --git a/HDOJ/4218_autoAC.cpp b/HDOJ/4218_autoAC.cpp new file mode 100644 index 0000000..436cd89 --- /dev/null +++ b/HDOJ/4218_autoAC.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + int n,r; + scanf("%d",&n); + for(int i=1; i<=n; i++) + { + scanf("%d",&r); + printf("Case %d:\n",i); + for(int j=0; j <2 * r+1; j++) + { + for(int k=0; k<2 * r + 1; k++) + { + if( abs((j-r)*(j-r)+(k-r)*(k-r)-r*r+0.0)<=3 ) + putchar('*'); + else + putchar(' '); + } + puts(""); + } + } + return 0; +} diff --git a/HDOJ/4219_autoAC.cpp b/HDOJ/4219_autoAC.cpp new file mode 100644 index 0000000..4ce23cf --- /dev/null +++ b/HDOJ/4219_autoAC.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#define N 70 +#define S 600 +using namespace std; +int n,l,s,vis[N],fa[N]; +vectorgra[N]; +double dp[N][S]; +void dfs(int d,int p) +{ + vis[d]=1;fa[d]=p; + int len=gra[d].size(); + if(p!=-1&&len==1) + { + dp[d][0]=1; + for(int i=1;i<=s;i++)dp[d][i]=0; + return ; + } + for(int i=0;i0)dp[d][i]-=sum[i-1],sum[i]=dp[d][i]+sum[i-1]; + else sum[i]=dp[d][i]; + } + else + { + int op=s-i; + dp[d][i]=0; + for(int j=0;j +#include +using namespace std; +struct TT +{ + int c,d; + bool operator < (const TT& s)const + { + return d < s.d; + } +}A[100002]; +int main() +{ + int z,n; + __int64 t,ans; + scanf("%d",&z); + for(int k=1;k<=z;k++) + { + scanf("%d",&n); + for(int i=0;i +int abs(int s) +{ + if(s<0) + return -s; + return s; +} +int main() +{ + int t,n,i,j,a[1010],sum,min,k=1; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + for(i=1;i<=n;i++) + scanf("%d",&a[i]); + min=abs(a[1]); + for(i=2;i<=n;i++) + { + sum=0; + for(j=i;j>=1;j--) + { + sum+=a[j]; + if(min>abs(sum)) + min=abs(sum); + } + } + printf("Case %d: %d\n",k++,min); + } + return 0; +} diff --git a/HDOJ/4224_autoAC.cpp b/HDOJ/4224_autoAC.cpp new file mode 100644 index 0000000..604f7c9 --- /dev/null +++ b/HDOJ/4224_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +using namespace std; +int main() +{ + int t; + scanf("%d",&t); + for(int k=1;k<=t;k++) + { + int u1,d1,u2,d2,u3,d3; + scanf("%d %d %d %d %d %d",&u1,&d1,&u2,&d2,&u3,&d3); + int a=0,b=0,c=0; + if(u1d1) + a=1; + if(u2d2) + b=1; + if(u3d3) + c=1; + if( ((a+b+c)==3)||((a+b+c)==-3)||((a*b*c==0)&&((a+b+c==1)||(a+b+c==-1)))||(a+b+c==2)||(a+b+c)==-2) + printf("Case %d: No\n",k); + else + printf("Case %d: Yes\n",k); + } + return 0; +} diff --git a/HDOJ/4225_autoAC.cpp b/HDOJ/4225_autoAC.cpp new file mode 100644 index 0000000..69de799 --- /dev/null +++ b/HDOJ/4225_autoAC.cpp @@ -0,0 +1,226 @@ +#include +#include +#include +#include +#include +using namespace std; +typedef vector Vx; +char str[100000],len = 0; +int idx = 0; +Vx getexp(int &f); +Vx getval(int &f); +bool Isnumber(char x){ + return x >= '0' && x <= '9'; +} +int getnum(){ + int num = 0; + int tt = 0; + if(str[idx] == '-'){ + idx++; + Vx tmp = getval(tt); + return -tmp[0]; + } + if(str[idx] == '+'){ + idx++; + Vx tmp = getval(tt); + return tmp[0]; + } + while(Isnumber(str[idx])){ + num = num * 10 + str[idx] - '0'; + idx++; + } + return num; +} +int op(int a,int b,char opt){ + int Ret = 0; + if(opt == '+') Ret = a + b; + if(opt == '-') Ret = a - b; + if(opt == '*') Ret = a * b; + return Ret; +} +void display(Vx x){ +} +Vx cal(Vx a,Vx b,char opt){ + Vx Ret; + int i; + if(a.size() == 1 && b.size() == 1){ + Ret.push_back(op(a[0],b[0],opt)); + return Ret; + } + if(a.size() == 1) { + for(i = 0;i < b.size();i++){ + Ret.push_back(op(a[0],b[i],opt)); + } + return Ret; + } + if(b.size() == 1) { + for(i = 0;i < a.size();i++) { + Ret.push_back(op(a[i],b[0],opt)); + } + return Ret; + } + for(i = 0;i < a.size();i++) { + Ret.push_back(op(a[i],b[i],opt)); + } + return Ret; +} +Vx vary(int val){ + int i; + Vx Ret; + Ret.clear(); + if(val == 0) return Ret; + if(val > 0) { + for(i = 1;i <= val;i++) Ret.push_back(i); + }else{ + for(i = -val;i >= 1;i--) Ret.push_back(i); + } + return Ret; +} +Vx getval(int &f){ + Vx Ret; + int i; + if(Isnumber(str[idx]) || str[idx] == '-'){ + Ret.push_back(getnum()); + f = 0; + return Ret; + } + if(str[idx] == 'v'){ + idx = idx + 5; + int tt = 0; + Vx tmp = getexp(tt); + idx++; + Ret = vary(tmp[0]); + f = 1; + return Ret; + } + if(str[idx] == 'b'){ + idx = idx + 6; + while(str[idx] != ')'){ + int tt = 0; + Vx tmp = getexp(tt); + Ret.push_back(tmp[0]); + if(str[idx] == ')') break; + idx++; + } + f = 1; + idx++; + return Ret; + } + if(str[idx] == 'd' && str[idx+1] == 'a'){ + idx = idx + 6; + int tt = 0; + Vx tmp = getexp(tt); + idx++; + if(tt == 1){ + int ans = tmp[tmp.size() - 1],p; + if(tmp.size() % 2 == 0) p = -1; + else p = 1; + for(i = tmp.size() - 2;i >= 0;i--){ + if(p == 1) ans = tmp[i] + ans; + else ans = tmp[i] - ans; + p = -p; + } + f = 0; + Ret.push_back(ans); + }else{ + int p = 1,num = tmp[0]; + if(num > 0) { + for(i = num;i >= 1;i--) { + Ret.push_back(i * p); + p = -p; + } + }else if(num < 0){ + for(i = num;i <= -1;i++){ + Ret.push_back(i * p); + p = -p; + } + } + f = 1; + } + return Ret; + } + if(str[idx] == 'd' && str[idx+1] == 'u'){ + idx = idx + 5; + int tt = 0; + Vx tmp = getexp(tt); + idx++; + int ans = tmp[tmp.size() - 1]; + for(i = tmp.size() - 2;i >= 0;i--){ + ans = tmp[i] - ans; + } + Ret.push_back(ans); + f = 0; + return Ret; + } + if(str[idx] == 's'){ + //sum() + idx = idx + 4; + int tt = 0; + Vx tmp = getexp(tt); + idx++; + int ans = 0; + for(i = 0;i < tmp.size();i++) { + ans += tmp[i]; + } + Ret.push_back(ans); + f = 0; + return Ret; + } + return Ret; +} +bool isop(char x){ + if(x == '+' || x == '-' || x == '*') return true; + else return false; +} +Vx getexp(int &f){ + int i; + int tmp = 0; + Vx beg = getval(tmp); + f = tmp; + vector >E;E.clear(); + while(idx < len && str[idx] == ' '){ + if(isop(str[idx+1]) == false || str[idx+2] != ' ') break; + while(str[idx] == ' ')idx++; + char op = str[idx]; + idx++; + while(str[idx] == ' ')idx++; + int t = 0; + Vx tmp = getval(t); + f = (f|t); + E.push_back(make_pair(tmp,op)); + } + if(E.size() == 0) return beg; + Vx Ret = E[E.size() - 1].first; + for(i = E.size() - 1;i >= 0;i--){ + if(i > 0){ + Ret = cal(E[i-1].first,Ret,E[i].second); + }else Ret = cal(beg,Ret,E[i].second); + } + return Ret; +} +int main(){ + int i,j,k,cas = 0; + int t; + scanf("%d",&t); + getchar(); + while(t--){ + gets(str); + idx = 0; + int f = 0; + len = strlen(str); + Vx ans = getexp(f); + if(f == 0) { + printf("Case %d: %d\n",++cas,ans[0]); + }else{ + printf("Case %d: ",++cas); + printf("{"); + for(i = 0;i < ans.size();i++){ + printf("%d",ans[i]); + if(i != ans.size() - 1) + printf(", "); + } + printf("}\n"); + } + } + return 0; +} diff --git a/HDOJ/4226_autoAC.cpp b/HDOJ/4226_autoAC.cpp new file mode 100644 index 0000000..4ab5a08 --- /dev/null +++ b/HDOJ/4226_autoAC.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +using namespace std; +const int maxn = 1111; +const double PI = 3.14159265358979323846; +const double oo = (1 << 30) * 1.0; +char kind[maxn]; +double len[maxn]; +double dp[maxn][12]; +int n, m; +double calc(int a, int b, int c) +{ + if (kind[a] == 'R' || kind[a] == 'L') + { + if (b == c) + { + double r; + if (kind[a] == 'R') + r = (b - 1) * 10.0 + 5 + len[a]; + else r = (m - b) * 10.0 + 5 + len[a]; + return (PI / 2.0 * r); + } + else return oo; + } + else + { + if (len[a] < abs((c - b)) * 100.0) + return oo; + else + return (sqrt(len[a] * len[a] + (b - c) * 10 * (b - c) * 10)); + } +} +double DP() +{ + for (int i = 0; i <= m; ++i) + dp[0][i] = 0.0; + for (int i = 1; i <= n; ++i) + { + for (int j = 1; j <= m; ++j) + { + dp[i][j] = oo; + for (int k = 1; k <= m; ++k) + { + dp[i][j] = min(dp[i][j], dp[i-1][k] + calc(i, k, j)); + } + } + } + double ans = oo; + for (int i = 1; i <= m; ++i) + ans = min(ans, dp[n][i]); + return ans; +} +int main() +{ + while (scanf("%d %d", &n, &m)) + { + if (n == 0 && m == 0) + break; + char ch; + for (int i = 1; i <= n; ++i) + { + scanf("\n%c %lf", &kind[i], &len[i]); + } + printf("%.2lf\n", DP()); + } + return 0; +} diff --git a/HDOJ/4227_autoAC.cpp b/HDOJ/4227_autoAC.cpp new file mode 100644 index 0000000..211cede --- /dev/null +++ b/HDOJ/4227_autoAC.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +using namespace std; +int a[13], p[13]; +int sum, i, ans; +bool use[13]; +void dfs(int k) { + int i; + if (k == 12) { + ans++; + return; + } + for (i = 0; i < 12; i++) { + if (i > 0 && !use[i - 1] && p[k - 1] == a[i]) + continue; + if (!use[i]) { + p[k] = a[i]; + if (k == 3) { + if (p[0] + p[1] + p[2] + p[3] != sum) { + continue; + } + } + if (k == 6) { + if (p[3] + p[4] + p[5] + p[6] != sum) { + continue; + } + } + if (k == 8) { + if (p[0] + p[8] + p[7] + p[6] != sum) { + continue; + } + } + if (k == 10) { + if (p[10] + p[1] + p[8] + p[9] != sum) { + continue; + } + } + if (k == 11) { + if (p[10] + p[2] + p[4] + p[11] != sum) { + continue; + } + if (p[9] + p[7] + p[5] + p[11] != sum) { + continue; + } + } + use[i] = 1; + dfs(k + 1); + use[i] = 0; + } + } +} +int main() { + while (1) { + sum = 0; + for (i = 0; i < 12; i++) { + scanf("%d", &a[i]); + sum += a[i]; + } + sort(a, a + 12); + if (!sum) + break; + if (sum % 3) { + printf("0\n"); + continue; + } + ans = 0; + sum /= 3; + dfs(0); + printf("%d\n", ans / 12); + } + return 0; +} diff --git a/HDOJ/4228_autoAC.cpp b/HDOJ/4228_autoAC.cpp new file mode 100644 index 0000000..12fc2cf --- /dev/null +++ b/HDOJ/4228_autoAC.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define mem(a,b) memset(a,b,sizeof(a)) +#define lson i<<1,l,mid +#define rson i<<1|1,mid+1,r +#define INF 510010 +#define maxn 400010 +using namespace std; +typedef long long ll; +typedef unsigned long long ull; +ll p[1010]; +ll prime[30]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; +void getartprime(ll cur,int cnt,int limit,int k) +{ + if(cur>(1LL<<60) || cnt>150) return ; + if(p[cnt]!=0 && p[cnt]>cur) + p[cnt]=cur; + if(p[cnt]==0) + p[cnt]=cur; + ll temp=cur; + for(int i=1; i<=limit; i++) + { + temp=temp*prime[k]; + if(temp>(1LL<<60)) return; + getartprime(temp,cnt*(i+1),i,k+1); + } +} +int main() +{ + int n; + getartprime(1,1,75,0); + for(int i=1; i<=75; i++) + { + if(p[i*2-1]!=0 && p[i*2]!=0) + p[i]=min(p[i*2-1],p[i*2]); + else if(p[i*2]!=0) p[i]=p[i*2]; + else p[i]=p[i*2-1]; + } + while(scanf("%d",&n),n) + printf("%I64d\n",p[n]); + return 0; +} diff --git a/HDOJ/4229_autoAC.cpp b/HDOJ/4229_autoAC.cpp new file mode 100644 index 0000000..c03cd80 --- /dev/null +++ b/HDOJ/4229_autoAC.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; +int main() +{ + int a,b,c,d,i,j,k,h,t; + while(cin>>a>>b>>c>>d) + { + if(a==0&& b==0&& c==0&& d==0) + break; + else + { + if(a==b&& b==c&& c==d) + t=0; + else + { + t=0; + while(a|| b || c|| d) + { + i=abs(a-b); + j=abs(b-c); + k=abs(c-d); + h=abs(d-a); + a=i,b=j,c=k,d=h; + t++; + } + t-=1; + } + cout<q; + now.x=s_x; + now.y=s_y; + now.step=0; + now.face=s_face; + step[now.x][now.y][now.face]=0; + cnt[now.x][now.y][now.face]=1; + memset(flag,0,sizeof(flag)); + q.push(now); + while(!q.empty()) + { + now=q.front(); + q.pop(); + if(flag[now.x][now.y][now.face]) continue; + flag[now.x][now.y][now.face]=1; + for(i=0;i<4;i++) if(step[now.x][now.y][now.step]<=step[e_x][e_y][i]) break; + if(i>=4) return ; + next.x=now.x+dir[now.face][0]; + next.y=now.y+dir[now.face][1]; + next.step=now.step+1; + next.face=now.face; + while(0<=next.x && next.x +#include +#include +#include +using namespace std; +#define M 105 +struct info +{ + char side; + int sou; + int v; +}; +info fold[30]; +int w,h,n; +int we,he; +int x,y; +void getdata(void); +int cal(int ws,int hs,int px,int py,int step); +int main() +{ + while (scanf("%d%d%d",&w,&h,&n),w+h+n) + { + getdata(); + printf("%d\n",cal(we,he,x,y,n)); + } + return 0; +} +void getdata(void) +{ + int i; + we=w; + he=h; + for (i=1;i<=n;i++) + { + scanf(" %c%d",&fold[i].side,&fold[i].v); + switch(fold[i].side) + { + case 'T': + case 'B': + fold[i].sou=he; + if (he-fold[i].v>=fold[i].v) + he-=fold[i].v; + else + { + he=fold[i].v; + /*fold[i].v=he-fold[i].v; + fold[i].side=fold[i].side=='B'?'T':'B'; + he-=fold[i].v;*/ + } + break; + case 'L': + case 'R': + fold[i].sou=we; + if (we-fold[i].v>=fold[i].v) + we-=fold[i].v; + else + { + we=fold[i].v; + /*fold[i].v=we-fold[i].v; + fold[i].side=fold[i].side=='R'?'L':'R'; + we-=fold[i].v;*/ + } + break; + } + } + scanf("%d%d",&x,&y); +} +int cal(int ws,int hs,int px,int py,int step) +{ + int ans=0; + int line; + if (step<1) + return 1; + else + { + switch (fold[step].side) + { + case 'T': + if (hs>fold[step].v) + { + if (pyline) + { + ans+=cal(ws,fold[step].sou,px,hs+(hs-py)-line,step-1); + ans+=cal(ws,fold[step].sou,px,py-line,step-1); + } + else + { + ans+=cal(ws,fold[step].sou,px,hs+(hs-py)-line,step-1); + } + } + break; + case 'B': + if (hs>fold[step].v) + { + if (py>fold[step].v) + { + ans+=cal(ws,hs+fold[step].v,px,py+fold[step].v,step-1); + } + else + { + ans+=cal(ws,hs+fold[step].v,px,py+fold[step].v,step-1); + ans+=cal(ws,hs+fold[step].v,px,fold[step].v-py,step-1); + } + } + else + { + line=2*fold[step].v-fold[step].sou; + if (pyfold[step].v) + { + if (px>fold[step].v) + { + ans+=cal(ws+fold[step].v,hs,px+fold[step].v,py,step-1); + } + else + { + ans+=cal(ws+fold[step].v,hs,px+fold[step].v,py,step-1); + ans+=cal(ws+fold[step].v,hs,fold[step].v-px,py,step-1); + } + } + else + { + line=2*fold[step].v-fold[step].sou; + if (pxfold[step].v) + { + if (pxline) + { + ans+=cal(fold[step].sou,hs,px-line,py,step-1); + ans+=cal(fold[step].sou,hs,ws+(ws-px)-line,py,step-1); + } + else + { + ans+=cal(fold[step].sou,hs,ws+(ws-px)-line,py,step-1); + } + } + break; + } + } + return ans; +} diff --git a/HDOJ/4233_autoAC.cpp b/HDOJ/4233_autoAC.cpp new file mode 100644 index 0000000..7ba5075 --- /dev/null +++ b/HDOJ/4233_autoAC.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const double eps(1e-8); +typedef long long lint; +#define maxn 100010 +int N, K, root; +int w[maxn]; +bool select[maxn]; +vector G[maxn]; +int f[maxn]; +void dfs(int now) +{ + int nex; + int mx = -1e9; + for(int i = 0, sz = G[now].size(); i < sz; i++) + { + nex = G[now][i]; + dfs(G[now][i]); + f[now] = max(f[now], max(f[nex], w[nex] + mx)); + w[now] = max(w[now], w[nex]); + mx = max(mx, w[nex]); + } + return; +} +void solve() +{ + memset(select, 0, sizeof(select)); + priority_queue > Q; + Q.push(make_pair(w[root], root)); + int ret = 0; + while(K) + { + if(Q.empty()) + { + puts("0"); + return; + } + int u = Q.top().second; + Q.pop(); + if(select[u]) + { + K++; + select[u] = 0; + ret -= w[u]; + for(int i = 0, sz = G[u].size(); i < sz; i++) Q.push(make_pair(w[G[u][i]], G[u][i])); + } + else + { + K--; + select[u] = 1; + ret += w[u]; + Q.push(make_pair(f[u] - w[u], u)); + } + } + printf("%d\n", ret); + return; +} +int main() +{ + while(scanf("%d %d", &N, &K), N || K) + { + for(int i = 1; i <= N; i++) G[i].clear(); + int p; + for(int i = 1; i <= N; i++) + { + f[i] = -1e9; + scanf("%d %d", &p, w + i); + if(p == 0) root = i; + else G[p].push_back(i); + } + dfs(root); + solve(); + } + return 0; +} diff --git a/HDOJ/4234_autoAC.cpp b/HDOJ/4234_autoAC.cpp new file mode 100644 index 0000000..0a2da91 --- /dev/null +++ b/HDOJ/4234_autoAC.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +using namespace std; +#define for if(0); else for +const double PI=acos(-1.0); +struct Point{ + double x,y,vx,vy,t; + Point(){} + Point(double x,double y){ + this->x=x; + this->y=y; + } + Point(double x,double y,double d,double v){ + this->x=x; + this->y=y; + this->vx=v*cos(d*PI/180.0); + this->vy=v*sin(d*PI/180.0); + this->t=0; + } + Point go(double t) const{ + Point ret=*this; + ret.x+=vx*t; + ret.y+=vy*t; + return ret; + } +}; +int n; +Point p[16]; +double spd; +double dp[16][1<<15]; +bool vis[16][1<<15]; +double dis(const Point &a,const Point &b){ + double dx=a.x-b.x; + double dy=a.y-b.y; + return sqrt(dx*dx+dy*dy); +} +double cost(const Point &a,const Point &b){ + Point ta=Point(b.x-a.x,b.y-a.y); + Point v=Point(b.vx,b.vy); + double V=dis(v,Point(0,0)); + double D=dis(ta,Point(0,0)); + double A=V*V-spd*spd; + double C=D*D; + double B=-2.0*(ta.x*v.x+ta.y*v.y); + return (B-sqrt(B*B-4*A*C))/2.0/A; +} +int main() { + setbuf(stdout,NULL); + while(scanf("%d%lf",&n,&spd) &&(n!=0&&spd!=0)){ + p[0]=Point(0,0,0,0); + for(int i=1;i<=n;i++){ + double x,y,d,v; + scanf("%lf%lf%lf%lf",&x,&y,&d,&v); + p[i]=Point(x,y,d,v); + } + memset(vis,0,sizeof(vis)); + vis[0][0]=1; + for(int stat=1;stat<1< +int a[591]={126,153,688,1206,1255,1260,1395,1435,1503,1530,1827,2187,3159,3784,6880,10251,10255,10426,10521,10525,10575,11259,11844,11848,12006,12060,12384,12505,12546,12550,12595,12600,12762,12843,12955,12964,13243,13545,13950,14035,14350,15003,15030,15246,15300,15435,15624,15795,16272,17325,17428,17437,17482,18225,18265,18270,19026,19215,21375,21586,21753,21870,25105,25375,25474,25510,28476,29632,31509,31590,33655,33696,36855,37840,37845,39784,41665,42898,44676,45684,45760,45864,47538,48672,49855,51759,52168,53865,56295,56875,62968,63895,67149,67392,67950,68800,71199,78975,100255,100525,101299,102051,102505,102510,102541,102550,102595,102942,102955,103968,104026,104260,104368,105021,105025,105075,105210,105250,105264,105295,105723,105750,107163,107329,108126,108135,108216,108612,108864,109525,110758,112468,112509,112590,114268,115672,115699,116478,116496,116725,116928,117067,118408,118440,118480,118575,118926,119848,120006,120060,120384,120600,120762,120843,121086,121576,121815,122746,122764,123084,123354,123538,123840,123894,124483,124488,124542,124978,125005,125050,125095,125248,125433,125460,125500,125950,125995,126000,126027,126108,126846,127417,127620,128403,128430,128943,129438,129505,129514,129550,129564,129595,129640,129775,129955,131242,132430,132565,132615,132655,133245,134275,134725,135045,135450,135828,135837,136525,136854,136948,138784,139500,139824,140035,140350,141345,142978,143500,143739,143793,145273,145314,145345,145683,146137,146520,146952,149364,149782,150003,150030,150246,150300,150435,150624,150826,152271,152406,152460,152608,152685,152946,153000,153436,154350,155277,156024,156240,156289,156325,156915,157950,158193,162072,162526,162720,162976,163255,163795,163854,163944,164583,165208,168520,171598,172246,172386,172822,173250,173925,174028,174082,174208,174280,174298,174370,174793,174802,174820,174982,175329,176215,178294,178942,179325,179428,179482,180225,180297,180621,182065,182250,182650,182700,182974,184126,186624,187029,189702,189742,190260,190827,191205,192150,192375,192685,192717,193257,193945,194229,197428,197482,197725,201852,205785,207391,208624,210375,210681,210753,211896,212868,213075,213466,213750,213759,214506,215086,215424,215455,215860,216733,217503,217530,217638,217854,218488,218700,223524,226498,226872,226876,227448,229648,231579,231673,233896,236754,236758,236925,238968,241506,241564,243175,245182,245448,246150,246928,250105,250510,251005,251050,251095,251896,253750,254740,255010,255100,256315,256410,256414,258795,259510,260338,261378,261783,262984,263074,263155,263736,267034,268398,279328,281736,283198,283648,284598,284760,285376,286416,286974,287356,289674,291375,291753,293625,295105,295510,296320,297463,297832,304717,307183,312475,312565,312655,312975,314199,314743,315009,315090,315490,315594,315625,315900,316255,319059,319536,325615,326155,326452,328419,328864,329346,329656,336195,336550,336960,338296,341284,341653,342688,346288,346725,346968,347913,352966,355995,361989,362992,365638,368104,368550,368784,369189,371893,373864,375156,375615,376992,378400,378418,378450,381429,384912,384925,386415,390847,392566,393246,393417,394875,397840,399784,404932,404968,414895,415575,416065,416259,416650,416988,419287,428980,429664,435784,439582,442975,446760,446976,447916,449676,449955,450688,451768,456840,457168,457600,458640,462672,465088,465984,468535,475380,475893,476892,486720,488592,489159,489955,490176,491688,493857,495328,497682,498550,515907,516879,517509,517590,519745,520168,520816,521608,521680,526792,529672,530379,531297,535968,536539,538650,549765,559188,562950,564912,567648,568750,571648,573768,588676,611793,611878,612598,614965,617728,618759,623758,629680,632875,638950,649638,661288,665919,667876,671409,671490,671944,673920,678892,679500,687919,688000,692712,697248,702189,702918,710496,711099,711909,711990,715959,719199,729688,736695,738468,741928,769792,773896,778936,782896,785295,789250,789525,789750,791289,792585,794088,798682,809919,809937,809964,815958,829696,841995,859968,899019,936985,939658,960988,1000255}; +int main() +{ + int x; + while (scanf("%d", &x)){ + if (x == 0) break; + for (int i = 0; i < 591; ++i){ + if (a[i] >= x){ + printf("%d\n", a[i]); + break; + } + } + } + return 0; +} diff --git a/HDOJ/4236_autoAC.cpp b/HDOJ/4236_autoAC.cpp new file mode 100644 index 0000000..7693c18 --- /dev/null +++ b/HDOJ/4236_autoAC.cpp @@ -0,0 +1,22 @@ +#include +#include +using namespace std; +char ch[25]; +int main() +{ + int n, i, j; + scanf("%d", &n); + while(n--) + { + int a, b; + scanf("%d%d%*c%s", &a, &b, ch); + printf("%d ", a); + for(i = 0; ch[i] != '\0'; i++) + { + for(j = 0; j < b; j++) + printf("%c", ch[i]); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/4237_autoAC.cpp b/HDOJ/4237_autoAC.cpp new file mode 100644 index 0000000..0a02736 --- /dev/null +++ b/HDOJ/4237_autoAC.cpp @@ -0,0 +1,13 @@ +#include +#include +using namespace std; +int main(){ + int t,r; + long long n,m,k; + scanf("%d",&t); + while(t--){ + scanf("%d%lld%lld",&r,&k,&m); + printf("%d %lld\n",r,1+(k-m)*m); + } + return 0; +} diff --git a/HDOJ/4238_autoAC.cpp b/HDOJ/4238_autoAC.cpp new file mode 100644 index 0000000..4ac3bbd --- /dev/null +++ b/HDOJ/4238_autoAC.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define oo 1<<29 +#define pi acos(-1.0) +#define esp 1e-30 +using namespace std; +char s[45]={"PQWERTYUIOJ#SZK*?F@D!HNM&LXGABCV"},c,Q[30]; +int A[30],C[30]; +int main() +{ + int cases,id,t,x,i,len; + scanf("%d",&cases); + while (cases--) + { + scanf("%d%s",&id,Q),len=strlen(Q); + if (Q[0]=='-') x=Q[1]-'0'; + else x=Q[0]-'0'; + if (x) + { + if (x>1) { printf("%d INVALID VALUE\n",id); continue; } + for (i=3;i<=19;i++) + if (Q[i]>='1' && Q[i]<='9') break; + if (i<=19) { printf("%d INVALID VALUE\n",id); continue; } + } + if (Q[0]=='-') + { + A[1]=1; + C[x=1]=1; + for (i=2;i='0' && Q[i]<='9') + C[++x]=0-(Q[i]-'0'); + len=x; + for (i=len;i>=1;i--) + if (C[i]<0) C[i-1]--,C[i]+=10; + C[1]=0; + } + else + { + A[1]=0; + x=0; + for (i=0;i='0' && Q[i]<='9') + C[++x]=Q[i]-'0'; + len=x; + } + for (i=2;i<=17;i++) + { + for (x=2;x<=len;x++) C[x]*=2; + for (x=1;x<=len;x++) C[x-1]+=C[x]/10,C[x]%=10; + if (C[1]) A[i]=1; + else A[i]=0; + C[1]=0; + while (len && !C[len]) len--; + } + if (len && A[1]) A[17]++; + for (x=20;x>=1;x--) A[x-1]+=A[x]/2,A[x]%=2; + x=0; + for (i=1;i<=5;i++) + if (A[i]) x+=1<<(5-i); + printf("%d %c",id,s[x]); + x=0,t=10; + for (i=6;i<=16;i++) + { + if (A[i]) x+=1< +#include +char map[33] = {'P' , 'Q' , 'W' , 'E' , 'R' , 'T' , 'Y' , 'U' , 'I' , 'O' , 'J' , '#' , 'S' , 'Z' , 'K' , '*' , '?' , 'F' , '@' , 'D' , '!' , 'H' , 'N' , 'M' , '&' , 'L' , 'X' , 'G' , 'A','B','C','V'}; +char a[3] , b[3]; +int n , num; +double ans; +char tans[10000]; +char str[30]; +void f(char t){ + int d = 4; + for(int i = 0 ; i < 32 ; i ++){ + if(t == map[i]){ + while(i != 0){ + str[d --] = i % 2 + '0'; + i /= 2; + } + break; + } + } + while(d >= 0){ + str[d --] = '0'; + } + return ; +} +void ff(int t){ + int d = 15; + while(t != 0){ + str[d --] = t % 2 + '0'; + t /= 2; + } + while(d >= 5){ + str[d --] = '0'; + } + return ; +} +void fff(char t){ + if(t == 'F') str[16] = '0'; + if(t == 'D') str[16] = '1'; +} +int main(){ + scanf("%d" , &n); + for(int i = 1 ; i <= n ; i ++){ + ans = 0; + double c = 0.5; + scanf("%*d%s%d%s" , a , &num , b); + f(a[0]); + ff(num); + fff(b[0]); + str[17] = '\0'; + printf("%d " , i); + if(str[0] == '0'){ + for(int i = 1 ; i < 17 ; i ++){ + ans += (str[i] - '0') * c; + c /= 2; + } + sprintf(tans , "%.16lf" , ans); + } + else{ + for(int i = 1 ; i < 17 ; i ++){ + ans += (str[i] - '0') * c; + c /= 2; + } + ans += -1.0; + sprintf(tans , "%.16lf" , ans); + } + if(ans == 0.0){ + printf("0.0\n"); + } + else if(ans == -1.0){ + printf("-1.0\n"); + } + else{ + int di; + for(di = strlen(tans) - 1 ; di >= 0 ; di --){ + if(tans[di] != '0') break; + } + tans[di + 1] = '\0'; + printf("%s" , tans); + printf("\n"); + } + } + return 0; +} diff --git a/HDOJ/4240_autoAC.cpp b/HDOJ/4240_autoAC.cpp new file mode 100644 index 0000000..9f599c4 --- /dev/null +++ b/HDOJ/4240_autoAC.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +using namespace std; +const int maxn = 1010; +const int INF = 0x3f3f3f3f; +struct Edge +{ + int from, to, cap, flow; + Edge(int from, int to, int cap, int flow): from(from), to(to), cap(cap), flow(flow) {} +}; +int high, low; +struct EK +{ + int n, m, s, t; + vector edges; + vector G[maxn]; + int p[maxn]; + int a[maxn]; + void init(int n) + { + this->n = n; + edges.clear(); + for(int i = 0; i <= n; i++) G[i].clear(); + } + void AddEdge(int from, int to, int cap) + { + edges.push_back(Edge (from, to, cap, 0)); + edges.push_back(Edge (to, from, 0, 0)); + m = edges.size(); + G[from].push_back(m-2); + G[to].push_back(m-1); + } + bool BFS(int s, int t, int &flow) + { + memset(a, 0, sizeof(a)); + queue Q; + Q.push(s); + a[s] = INF; + while(!Q.empty()) + { + int u = Q.front(); Q.pop(); + for(int i = 0; i < G[u].size(); i++) + { + Edge &e = edges[G[u][i]]; + if(!a[e.to] && e.cap > e.flow) + { + p[e.to] = G[u][i]; + Q.push(e.to); + a[e.to] = min(a[u], e.cap-e.flow); + } + } + } + if(a[t] == 0) return 0; + flow += a[t]; + low = INF; + int u = t; + while(u != s) + { + edges[p[u]].flow += a[t]; + edges[p[u]^1].flow -= a[t]; + low = min(low, edges[p[u]].cap); + u = edges[p[u]].from; + } + high = max(high, low); + return 1; + } + int Maxflow(int s, int t) + { + this->s = s; this->t = t; + int flow = 0; + while(BFS(s, t, flow)) ; + return flow; + } +}; +void readint(int &x) +{ + char c; + while(!isdigit(c)) c = getchar(); + x = 0; + while(isdigit(c)) { x = x*10 + c-'0'; c = getchar(); } +} +void writeint(int x) +{ + if(x > 9) writeint(x/10); + putchar(x%10+'0'); +} +EK solver; +int n, m, s, t; +int kase; +void solve() +{ + scanf("%d%d%d%d%d", &kase, &n, &m, &s, &t); + solver.init(n+3); + high = -INF; + while(m--) + { + int x, y, z; + readint(x), readint(y), readint(z); + solver.AddEdge(x, y, z); + } + int ans = solver.Maxflow(s, t); + printf("%d %.3lf\n", kase, ans*1.0/high); +} +int main() +{ + int T; + for(readint(T); T > 0; T--) solve(); + return 0; +} diff --git a/HDOJ/4242_autoAC.cpp b/HDOJ/4242_autoAC.cpp new file mode 100644 index 0000000..fbdb628 --- /dev/null +++ b/HDOJ/4242_autoAC.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +using namespace std; +char a[20]; +double funx(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){ + return (y4-y2+(y1-y2)*x2/(x1-x2)-(y3-y4)*x4/(x3-x4))/((y1-y2)/(x1-x2)-(y3-y4)/(x3-x4)); +} +double funy(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){ + return y2+(y1-y2)*(funx(x1,y1,x2,y2,x3,y3,x4,y4)-x2)/(x1-x2); +} +double area(double x0,double y0,double x1,double y1,double x2,double y2){ + return fabs(x0*y1+x2*y0+x1*y2-x2*y1-x0*y2-x1*y0); +} +double dis(double x1,double y1,double x2,double y2){ + return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); +} +int main(){ + double ax=0.0,ay=0.0,bx,by=0.0,cx,cy,dx,dy; + double aax,aay,bbx,bby,ccx,ccy,ddx,ddy; + int t,n; + while(~scanf("%d",&t)){ + while(t--){ + scanf("%d%lf%lf%lf%lf%lf",&n,&bx,&cx,&cy,&dx,&dy); + aax=(bx+cx)/2; + aay=(by+cy)/2; + bbx=(cx+dx)/2; + bby=(cy+dy)/2; + ccx=(ax+dx)/2; + ccy=(ay+dy)/2; + ddx=(ax+bx)/2; + ddy=(ay+by)/2; + double x1=funx(ax,ay,aax,aay,bx,by,bbx,bby); + double y1=funy(ax,ay,aax,aay,bx,by,bbx,bby); + double x2=funx(bx,by,bbx,bby,cx,cy,ccx,ccy); + double y2=funy(bx,by,bbx,bby,cx,cy,ccx,ccy); + double x3=funx(cx,cy,ccx,ccy,dx,dy,ddx,ddy); + double y3=funy(cx,cy,ccx,ccy,dx,dy,ddx,ddy); + double x4=funx(ax,ay,aax,aay,dx,dy,ddx,ddy); + double y4=funy(ax,ay,aax,aay,dx,dy,ddx,ddy); + double al,bob,chas,dave,emily; + al =area(ax,ay,bx,by,x1,y1)/2/160; + bob =area(bx,by,cx,cy,x2,y2)/2/160; + chas=area(cx,cy,dx,dy,x3,y3)/2/160; + dave=area(dx,dy,ax,ay,x4,y4)/2/160; + double all=(area(ax,ay,bx,by,cx,cy)+area(ax,ay,cx,cy,dx,dy))/2/160; + emily=all-al-bob-chas-dave; + int d=(int)ceil((dis(x1,y1,x2,y2)+dis(x2,y2,x3,y3)+dis(x3,y3,x4,y4)+dis(x4,y4,x1,y1))*16.5); + printf("%d %.3f %.3f %.3f %.3f %.3f %d\n",n,al,bob,chas,dave,emily,d); + } + } + return 0; +} diff --git a/HDOJ/4243_autoAC.cpp b/HDOJ/4243_autoAC.cpp new file mode 100644 index 0000000..d5d46bd --- /dev/null +++ b/HDOJ/4243_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#define mem(a,b) memset(a,b,sizeof(a)) +using namespace std; +const int maxn=500; +const int inf=0x7fffff; +double A(double x) +{ + double r=1; + for(double i=1;i<=x;i++) + r*=i; + return r; +} +double C(double m,double n) +{ + double r=1; + for(double i=n-m+1;i<=n;i++) + r*=i; + for(double i=m;i>=1;i--) + r/=i; + return r; +} +int main() +{ + int t,a; + double n,m; + scanf("%d",&t); + while(t--) + { + scanf("%d%lf%lf",&a,&n,&m); + double ans=0; + if(m==1) ans+=A(n-1); + else + for(double i=1;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +template< class T > T _abs(T n) { return (n < 0 ? -n : n); } +template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); } +template< class T > T _min(T a, T b) { return (a < b ? a : b); } +template< class T > T sq(T x) { return x * x; } +#define ALL(p) p.begin(),p.end() +#define MP(x, y) make_pair(x, y) +#define SET(p) memset(p, -1, sizeof(p)) +#define CLR(p) memset(p, 0, sizeof(p)) +#define MEM(p, v) memset(p, v, sizeof(p)) +#define CPY(d, s) memcpy(d, s, sizeof(s)) +#define SZ(c) (int)c.size() +#define PB(x) push_back(x) +#define ff first +#define ss second +#define ld long double +#define pii pair< int, int > +#define psi pair< string, int > +const double EPS = 1e-9; +const int INF = 0x7f7f7f7f; +struct point { + double x,y,z; +}; +bool eql(point &a,point &b) { + return fabs(a.x-b.x)>T; + while(T--) { + cin>>I>>g[0][1]>>g[1][1]>>g[2][1]>>a>>b>>c>>d; + vector < pair < point , point > > r,tr; + for(i=0;i<2;i++) { + cn=0; + x=g[0][i]; + for(j=0;j<2;j++) { + y=g[1][j]; + z=(d-b*y-a*x)/c; + if(z>=0 && z<=g[2][1]) { + tt[cn].x=x; + tt[cn].y=y; + tt[cn].z=z; + cn++; + } + } + if(cn==2) { + r.PB(make_pair(tt[0],tt[1])); + continue; + } + for(j=0;j<2;j++) { + z=g[2][j]; + y=(d-c*z-a*x)/b; + if(y>=0 && y<=g[1][1]) { + tt[cn].x=x; + tt[cn].y=y; + tt[cn].z=z; + cn++; + } + } + if(cn==2) r.PB(make_pair(tt[0],tt[1])); + else if(cn==3) { + bool f=1; + for(j=0;j<3 && f;j++) for(l=0;l=0 && z<=g[2][1]) { + tt[cn].x=x; + tt[cn].y=y; + tt[cn].z=z; + cn++; + } + } + if(cn==2) { + r.PB(make_pair(tt[0],tt[1])); + continue; + } + for(j=0;j<2;j++) { + z=g[2][j]; + x=(d-c*z-b*y)/a; + if(x>=0 && x<=g[0][1]) { + tt[cn].x=x; + tt[cn].y=y; + tt[cn].z=z; + cn++; + } + } + if(cn==2) r.PB(make_pair(tt[0],tt[1])); + else if(cn==3) { + bool f=1; + for(j=0;j<3 && f;j++) for(l=0;l=0 && x<=g[0][1]) { + tt[cn].x=x; + tt[cn].y=y; + tt[cn].z=z; + cn++; + } + } + if(cn==2) { + r.PB(make_pair(tt[0],tt[1])); + continue; + } + for(j=0;j<2;j++) { + x=g[0][j]; + y=(d-c*z-a*x)/b; + if(y>=0 && y<=g[1][1]) { + tt[cn].x=x; + tt[cn].y=y; + tt[cn].z=z; + cn++; + } + } + if(cn==2) r.PB(make_pair(tt[0],tt[1])); + else if(cn==3) { + bool f=1; + for(j=0;j<3 && f;j++) for(l=0;l ls; + j=0; + ls.push_back(r[0].first); + j=0; + for(i=0;i ls; + j=0; + ls.push_back(r[0].first); + j=0; + for(i=0;i +#include +#include +using namespace std; +char str[100]; +int cas = 1; +int main() +{ + while(gets(str)) + { + printf("Case %d: ",cas++); + int i,j,len; + len = strlen(str); + if(str[1] == ' ') + printf("UNIQUE\n"); + else + { + if(str[1] == '#') + { + if(str[0] == 'G') + printf("Ab"); + else + printf("%cb",str[0]+1); + } + else if(str[1] == 'b') + { + if(str[0] == 'A') + printf("G#"); + else + printf("%c#",str[0]-1); + } + for(i = 2;i +#include +#include +using namespace std; +char str[100]; +int cas = 1; +int main() +{ + while(gets(str)) + { + printf("Case %d: ",cas++); + int i,j,len; + len = strlen(str); + if(str[1] == ' ') + printf("UNIQUE\n"); + else + { + if(str[1] == '#') + { + if(str[0] == 'G') + printf("Ab"); + else + printf("%cb",str[0]+1); + } + else if(str[1] == 'b') + { + if(str[0] == 'A') + printf("G#"); + else + printf("%c#",str[0]-1); + } + for(i = 2;i +#include +#include +using namespace std; +int main() +{ + int a[4],cas = 1; + int x,y,ans; + while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])) + { + sort(a,a+4); + printf("Case %d: %d\n",cas++,a[2]+a[3]); + } + return 0; +} diff --git a/HDOJ/4248_autoAC.cpp b/HDOJ/4248_autoAC.cpp new file mode 100644 index 0000000..d1da434 --- /dev/null +++ b/HDOJ/4248_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +typedef long long Long; +const int MOD = 1000000007; +int C[11111][111]; +void init() { + C[0][0] = C[1][0] = C[1][1] = 1; + for (int i = 2; i <= 10101; i++) { + for (int j = 0; j <= i && j <= 100; j++) { + if (j == 0) C[i][j] = 1; + else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD; + } + } +} +int dp[111][11111]; +int a[111]; +int main() { + init(); + for (int ii = 1;;ii++) { + int n; if (scanf("%d",&n) == -1) break; + memset(dp,0,sizeof(dp)); + memset(a,0,sizeof(a)); + for (int i = 0; i < n; i++) { + scanf("%d",a + i); + } + for (int i = 0; i <= a[0]; i++) dp[0][i] = 1; + int maxlen = a[0]; + for (int now = 0; now < n - 1; now ++) { + int next = now + 1; + for (int len = 0; len <= maxlen; len++) { + if (dp[now][len] == 0) continue; + dp[next][len] += dp[now][len]; + if (dp[next][len] >= MOD) dp[next][len] -= MOD; + Long tmp = dp[now][len]; + for (int put = 1; put <= a[next]; put++) { + Long tt = tmp * C[len + put][put] % MOD; + dp[next][len + put] += tt; + if (dp[next][len + put] >= MOD) dp[next][len + put] -= MOD; + } + } + maxlen += a[next]; + } + int ans = 0; + for (int i = 1; i <= maxlen; i++) ans = (ans + dp[n - 1][i]) % MOD; + printf("Case %d: %d\n",ii,ans); + } + return 0; +} diff --git a/HDOJ/4249_autoAC.cpp b/HDOJ/4249_autoAC.cpp new file mode 100644 index 0000000..7699edf --- /dev/null +++ b/HDOJ/4249_autoAC.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +using namespace std; +char str[105]; +int a[15]; +int b[15]; +int c[15]; +long long dp[10][2]; +int main() +{ + int i,j,n,tag,t,aup,bup,cup,cnt=1,x,y,z,p,q,r; + while(scanf("%s",str)!=EOF) + { + memset(dp,0,sizeof(dp)); + n=strlen(str); + tag=0; + aup=bup=cup=0; + for (i=n-1;i>=0;i--) + { + if (str[i]=='=' || str[i]=='+') tag++; + else + { + t=str[i]=='?'?-1:(str[i]-'0'); + if (tag==0) c[cup++]=t; + if (tag==1) b[bup++]=t; + if (tag==2) a[aup++]=t; + } + } + if (cup=1) continue; + for (y=0;y<=9;y++) + { + if (i==bup-1 && bup!=1 && y==0 && b[i]==-1) continue; + if (b[i]!=-1 && y>=1) continue; + for (z=0;z<=9;z++) + { + if (i==cup-1 && cup!=1 && z==0 && c[i]==-1) continue; + if (c[i]!=-1 && z>=1) continue; + p=a[i]==-1?x:a[i]; + q=b[i]==-1?y:b[i]; + r=c[i]==-1?z:c[i]; + if (p+q==r) + { + if (i==0) dp[i][0]++; + else dp[i][0]+=dp[i-1][0]; + } + if (p+q==10+r) + { + if (i==0) dp[i][1]++; + else dp[i][1]+=dp[i-1][0]; + } + if (p+q+1==r && i!=0) + { + dp[i][0]+=dp[i-1][1]; + } + if (p+q+1==r+10 && i!=0) + { + dp[i][1]+=dp[i-1][1]; + } + } + } + } + } + printf("Case %d: %I64d\n",cnt++,dp[cup-1][0]); + } + return 0; +} diff --git a/HDOJ/4251_autoAC.cpp b/HDOJ/4251_autoAC.cpp new file mode 100644 index 0000000..635dccf --- /dev/null +++ b/HDOJ/4251_autoAC.cpp @@ -0,0 +1,82 @@ +#include +#include +using namespace std; +const int N=100010; +int srted[N]; +struct node +{ + int num[N]; + int val[N]; +}t[40]; +int n,m; +void build(int l,int r,int d) +{ + if(l==r) return; + int mid=(l+r)>>1; + int midd=srted[mid]; + int same=mid-l+1,samed=0,zn=l-1,yn=mid,i; + for(i=l;i<=r;++i) + if(t[d].val[i]midd) + { + t[d+1].val[++yn]=t[d].val[i]; + }else + { + if(samed>1; + int sx=t[d].num[a-1],sy=t[d].num[b]; + if(a-1=k) + return query(l+sx,l+sy-1,k,l,mid,d+1); + else + { + int s1=(a==1?0:a-l-sx); + int s2=(b-a+1)-(sy-sx); + int nk=k-(sy-sx); + return query(mid+1+s1,mid+s1+s2,nk,mid+1,r,d+1); + } +} +int main() +{ + int cas=1; + int i,a,b; + while(cin>>n) + { + cout<<"Case "<>srted[i]; + t[0].val[i]=srted[i]; + } + sort(srted+1,srted+1+n); + build(1,n,0); + cin>>m; + for(i=1;i<=m;++i) + { + cin>>a>>b; + cout< +#include +#include +using namespace std; +int a[1000005],x,len; +int main() +{ + int n,i,cas = 1,ans,j; + while(~scanf("%d",&n)) + { + ans = 0; + for(i = 0; i=0; j--) + { + if(a[i]>a[j]) + break; + else if(a[i]==a[j]) + { + ans++; + break; + } + } + } + } + printf("Case %d: %d\n",cas++,n-ans); + } + return 0; +} diff --git a/HDOJ/4253_autoAC.cpp b/HDOJ/4253_autoAC.cpp new file mode 100644 index 0000000..1ef8c83 --- /dev/null +++ b/HDOJ/4253_autoAC.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +using namespace std; +struct node +{ + int v1,v2; + int w; +} s[100005],t[100005]; +int n,m,k,cnts,cntt; +int father[100005],sum; +int cmp(const node a,const node b) +{ + if(a.w=k) return 1; + else return 0; +} +int main() +{ + int text=0; + while(scanf("%d%d%d",&n,&m,&k)>0) + { + cnts=0,cntt=0; + for(int i=0; i +#include +int N, P, Q; +double f[200005]; +double logC(int n, int m) { + return f[n]-f[m]-f[n-m]; +} +int main() { + int test = 0; + for(int i=1; i<=200000; i++) + f[i] = f[i-1] + log(0.0+i); + while(scanf("%d%d%d", &N, &P, &Q) != EOF) { + double a = 0, b = 0; + for(int red=Q; red<=N-(P-Q); red++) { + int blue = N - red; + double p = exp(logC(red, Q) + logC(N-red, P - Q) - logC(N, P)); + double q = (red - Q + 0.0) / (N - P); + a += p * q; + b += p; + } + printf("Case %d: %.4lf\n", ++test, a/b); + } + return 0; +} diff --git a/HDOJ/4255_autoAC.cpp b/HDOJ/4255_autoAC.cpp new file mode 100644 index 0000000..2a4af7e --- /dev/null +++ b/HDOJ/4255_autoAC.cpp @@ -0,0 +1,110 @@ +#include +#include +#include +#include +#define N 40400 +#define MAX 210 +#define CNT 4000 +using namespace std; +bool isprime[N]; +int prime[CNT],cnt; +int map[MAX][MAX]; +bool visited[MAX][MAX]; +struct point{int x,y,step;}; +void find_prime() +{ + int i,j; + cnt=0; + memset(isprime,true,sizeof(isprime)); + isprime[1]=false; + for(i=2;iq;i--) map[p+c-1][i]=s--; + for(i=p+c-1;i>p;i--) map[i][q]=s--; + build_map(p+1,q+1,s,c-2); +} +int t_i,t_j; +void find(int u) +{ + int i,j; + for(i=1;i<=200;i++) + { + for(j=1;j<=200;j++) + { + if(u==map[i][j]) + { + t_i=i;t_j=j; + return ; + } + } + } +} +int BFS(int u,int v) +{ + find(u); + point t,tt; + t.x=t_i;t.y=t_j;t.step=0; + queueQ; + while(!Q.empty()) Q.pop(); + Q.push(t); + visited[t.x][t.y]=true; + while(!Q.empty()) + { + t=Q.front();Q.pop(); + if(map[t.x][t.y]==v) return t.step; + if(t.x-1>=1&&!visited[t.x-1][t.y]&&!isprime[map[t.x-1][t.y]]) + { + tt.x=t.x-1;tt.y=t.y;tt.step=t.step+1; + Q.push(tt); + visited[tt.x][tt.y]=true; + } + if(t.x+1<=200&&!visited[t.x+1][t.y]&&!isprime[map[t.x+1][t.y]]) + { + tt.x=t.x+1;tt.y=t.y;tt.step=t.step+1; + Q.push(tt); + visited[tt.x][tt.y]=true; + } + if(t.y-1>=1&&!visited[t.x][t.y-1]&&!isprime[map[t.x][t.y-1]]) + { + tt.x=t.x;tt.y=t.y-1;tt.step=t.step+1; + Q.push(tt); + visited[tt.x][tt.y]=true; + } + if(t.y+1<=200&&!visited[t.x][t.y+1]&&!isprime[map[t.x][t.y+1]]) + { + tt.x=t.x;tt.y=t.y+1;tt.step=t.step+1; + Q.push(tt); + visited[tt.x][tt.y]=true; + } + } + return 0; +} +int main() +{ + int u,v,k=1; + memset(map,0,sizeof(map)); + find_prime(); + build_map(1,1,40000,200); + while(scanf("%d%d",&u,&v)!=EOF) + { + memset(visited,false,sizeof(visited)); + int ans; + ans=BFS(u,v); + if(ans) printf("Case %d: %d\n",k++,ans); + else printf("Case %d: impossible\n",k++); + } + return 0; +} diff --git a/HDOJ/4256_autoAC.cpp b/HDOJ/4256_autoAC.cpp new file mode 100644 index 0000000..90a6249 --- /dev/null +++ b/HDOJ/4256_autoAC.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +using namespace std; +int main() +{ + char str[20][10] = {"#","I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"}; + char s[10]; + int i,cas = 1; + while(~scanf("%s",s)) + { + for(i = 1;i<=12;i++) + { + if(strcmp(s,str[i])==0) + { + printf("Case %d: %d\n",cas++,i); + } + } + } + return 0; +} diff --git a/HDOJ/4258_autoAC.cpp b/HDOJ/4258_autoAC.cpp new file mode 100644 index 0000000..87cd7b0 --- /dev/null +++ b/HDOJ/4258_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +using namespace std; +int N,C; +long long a[1000010]; +long long f[1000010]; +struct point +{ + int id; + long long x,y; + point(int a,long long b,long long c) + { + id = a;x = b;y = c; + } + point(){}; +}; +long long solve() +{ + static point s[1000010]; + int head = 1,tail = 0; + long long temp; + for (int i = 1;i <= N;i++) + { + point p(i-1,a[i],f[i-1]+ a[i]*a[i]); + while(tail-1 >= head && (s[tail].x - s[tail-1].x)*(p.y - s[tail].y) - (s[tail].y - s[tail-1].y) *(p.x - s[tail].x) <0) + tail --; + s[++tail] = p; + while (head <= tail && (temp = s[head].y - 2*a[i]*s[head].x+a[i]*a[i] + C,temp < f[i]||f[i] == -1)) + { + f[i] = temp; + head++; + } + head--; + } + return f[N]; +} +int main() +{ + while(scanf("%d%d",&N,&C),N+C) + { + a[0] = 0; + for(int i = 1;i <= N;i++) + scanf("%d",&a[i]); + memset(f,-1,sizeof(f)); + f[0] = 0; + printf("%I64d\n",solve()); + } + return 0; +} diff --git a/HDOJ/4259_autoAC.cpp b/HDOJ/4259_autoAC.cpp new file mode 100644 index 0000000..a27a01f --- /dev/null +++ b/HDOJ/4259_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +using namespace std; +const int MAXN = 1805; +int a[2][MAXN], vst[MAXN], cnt; +int myS[MAXN][MAXN], top[MAXN]; +void init() +{ + memset(vst, 0, sizeof(vst)); +} +void dfs(int x) +{ + cnt++; + vst[x] = 1; + int nx = a[1][x]; + if(!vst[nx]) + { + dfs(nx); + } +} +__int64 gcd1(__int64 a, __int64 b) +{ + __int64 r = b, t; + while(r) + { + t = r; + r = a % r; + a = t; + } + return a; +} +__int64 gcd2(__int64 a, __int64 b) +{ + return b == 0 ? a : gcd2(b, a % b); +} +int main(void) +{ + int n, k; + while(scanf("%d %d", &n, &k), n || k) + { + init(); + for(int i = 0; i < n; i++) + { + int in = i % k; + myS[in][top[in]++] = i; + } + int s = 0; + for(int i = 0; i < n; i++) + a[0][i] = i; + for(int in = 0; in < k; in++) + { + while(top[in]) + { + a[1][s++] = myS[in][--top[in]]; + } + } + int c = 0; + __int64 res[MAXN]; + for(int i = 0; i < n; i++) + { + if(!vst[i]) + { + cnt = 0; + dfs(i); + res[c++] = cnt; + } + } + __int64 tmp; + if(c >= 2) + { + tmp = res[0] / gcd2(res[0], res[1]) * res[1]; + for(int i = 2; i < c; i++) + tmp = tmp / gcd2(tmp, res[i]) * res[i]; + } + else if(c == 1) + tmp = res[0]; + printf("%I64d\n", tmp); + } + return 0; +} diff --git a/HDOJ/4260_autoAC.cpp b/HDOJ/4260_autoAC.cpp new file mode 100644 index 0000000..790d64c --- /dev/null +++ b/HDOJ/4260_autoAC.cpp @@ -0,0 +1,19 @@ +#include +#include +using namespace std; +string s; +long long cal(long long x,char goal) +{ + for(long long i=x;i>=0;i--) + if(s[i]!=goal) return cal(i-1,'A'^'B'^'C'^goal^s[i])+(1LL<>s,s!="X") + { + long long ans=cal(s.length()-1,'B'); + cout< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#pragma comment (linker,"/STACK:102400000,102400000") +#define maxn 70 +#define MAXN 31290 +#define OO (1<<31)-1 +#define mod 100000000 +#define INF 0x3f3f3f3f +#define pi acos(-1.0) +#define eps 1e-6 +typedef long long ll; +using namespace std; +int n,m,ans,cnt,tot,flag; +int a[2005],dp[30][2005],w[2005][2005]; +int main() +{ + int i,j,k,t,num1,num2,sum; + while(scanf("%d%d",&n,&m),n|m) + { + for(i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + for(i=1;i<=n;i++) + { + priority_queuelower; + priority_queue,greater >upper; + sum=0; + for(j=i;j<=n;j++) + { + if(upper.empty()||a[j]>=upper.top()) + { + upper.push(a[j]); + sum+=a[j]; + } + else + { + lower.push(a[j]); + sum-=a[j]; + } + num1=(j-i+1)/2; num2=j-i+1-num1; + if(lower.size()>num1) + { + upper.push(lower.top()); + sum+=2*lower.top(); + lower.pop(); + } + else if(upper.size()>num2) + { + lower.push(upper.top()); + sum-=2*upper.top(); + upper.pop(); + } + if(num2>num1) w[i][j]=sum-upper.top(); + else w[i][j]=sum; + } + } + for(i=0;i<=m;i++) for(j=0;j<=n;j++) dp[i][j]=INF; + dp[0][0]=0; + for(i=1;i<=m;i++) + { + for(j=i;j<=n;j++) + { + for(k=0;k +#include +#include +#include +using namespace std; +#define lson u<<1 +#define rson u<<1|1 +#define MAXN 100005 +int map[MAXN]; +struct Node{ + int lef,rig; + int sum; +}T[MAXN<<2]; +void PushUp(int u){ + T[u].sum=T[lson].sum+T[rson].sum; +} +void Build(int u,int l,int r){ + T[u].lef=l; + T[u].rig=r; + if(l==r){T[u].sum=1;return;} + int mid=(l+r)>>1; + Build(lson,l,mid); + Build(rson,mid+1,r); + PushUp(u); +} +void Update(int u,int pos,int val){ + if(T[u].lef==T[u].rig){T[u].sum=val;return;} + if(pos<=T[lson].rig)Update(lson,pos,val); + else Update(rson,pos,val); + PushUp(u); +} +int Query(int u,int l,int r){ + if(l<=T[u].lef&&T[u].rig<=r)return T[u].sum; + if(r<=T[lson].rig)return Query(lson,l,r); + if(l>=T[rson].lef)return Query(rson,l,r); + return Query(lson,l,T[lson].rig)+Query(rson,T[rson].lef,r); +} +int main(){ + int n; + while(scanf("%d",&n)&&n){ + int tmp; + for(int i=1;i<=n;i++){ + scanf("%d",&tmp); + map[tmp]=i; + } + Build(1,1,n); + int cur=1; + __int64 ans=n; + for(int i=1;icur)tmp=Query(1,cur+1,map[i])-1; + else tmp=Query(1,map[i],cur-1); + ans+=min(tmp,n-i+1-tmp); + Update(1,map[i],0); + cur=map[i]; + } + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/4263_autoAC.cpp b/HDOJ/4263_autoAC.cpp new file mode 100644 index 0000000..a141783 --- /dev/null +++ b/HDOJ/4263_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +using namespace std; +const int maxx = 1010; +int Find(int x,int father[]) +{ + while(x!=father[x]) x = father[x]; + return x; +} +void Union(int r1, int r2, int& counter,int father[]) +{ + int a = Find(r1,father); + int b = Find(r2,father); + if(a!=b) + { + counter++; + father[a] = b; + } +} +void ini(int n,int father[]) +{ + for(int i=1; i<=n; i++) + father[i] = i; +} +int main() +{ + int n,m,k; + int father_r[maxx]; + int father_b[maxx]; + while(scanf("%d %d %d",&n,&m,&k),n||m||k) + { + ini(n,father_r); + ini(n,father_b); + int counter_r,counter_b; + counter_r = counter_b = 0; + for(int i=1; i<=m; i++) + { + char ch=0; + while(ch!='B'&&ch!='R') + ch=getchar(); + int u,v; + scanf("%d%d",&u,&v); + if(ch=='B') + Union(u,v,counter_b,father_b); + else + Union(u,v,counter_r,father_r); + } + if(k<=counter_b && k>=n-counter_r-1) + printf("1\n"); + else + printf("0\n"); + } + return 0; +} diff --git a/HDOJ/4264_autoAC.cpp b/HDOJ/4264_autoAC.cpp new file mode 100644 index 0000000..6f96a40 --- /dev/null +++ b/HDOJ/4264_autoAC.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#define eps 1e-8 +#define N 200 +using namespace std; +const double PI=acos(-1.0); +int dlcmp(double x) +{ + return x<-eps?-1:x>eps; +} +struct Point +{ + double x,y; + Point(){} + Point(double a,double b):x(a),y(b){} + Point operator + (const Point a) const {return Point(x+a.x,y+a.y);} + Point operator - (const Point a) const {return Point(x-a.x,y-a.y);} + Point operator * (const double a) const {return Point(x*a,y*a);} + Point operator / (const double a) const {return Point(x/a,y/a);} + bool operator == (const Point a) + { + return !dlcmp(x-a.x)&&!dlcmp(y-a.y); + } + Point trunc(double d) const + { + double dis(Point,Point); + double len=dis(*this,Point(0,0)); + return Point(x*d/len,y*d/len); + } + Point rotate(double a) + { + return Point(x*cos(a)-y*sin(a),y*cos(a)+x*sin(a)); + } +}; +struct Circle +{ + Point o; + double r; + Circle(){} + Circle(Point a,double l):o(a),r(l){} +}; +struct node +{ + double s,e; + node(){} + node(double a,double b):s(a),e(b){} +}; +Circle c[N],red,purple; +vectorarc; +double sqr(double x) +{ + return x*x; +} +double fix(double x) +{ + if (dlcmp(x-1)>=0) + return 1; + if (dlcmp(x+1)<=0) + return -1; + return x; +} +double dis(Point a,Point b) +{ + return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); +} +void get_InCommonTangent(Circle c1,Circle c2,Point &s1,Point &e1,Point &s2,Point &e2) +{ + double l=dis(c1.o,c2.o); + double d=l*c1.r/(c1.r+c2.r); + double tmp=c1.r/d; + tmp=fix(tmp); + double theta=acos(tmp); + Point vec=c2.o-c1.o; + vec=vec.trunc(c1.r); + s1=c1.o+vec.rotate(theta); + s2=c1.o+vec.rotate(-theta); + vec=c1.o-c2.o; + vec=vec.trunc(c2.r); + e1=c2.o+vec.rotate(theta); + e2=c2.o+vec.rotate(-theta); +} +void inter_circle_ray(Circle c,Point s,Point e,Point &p) +{ + Point vec=e-s; + double A=sqr(vec.x)+sqr(vec.y); + double B=2*(vec.x*(s.x-c.o.x)+vec.y*(s.y-c.o.y)); + double C=sqr(s.x-c.o.x)+sqr(s.y-c.o.y)-sqr(c.r); + double delta=sqr(B)-4*A*C; + delta=fabs(delta); + double k=(-B+sqrt(delta))/(2*A); + p=s+vec*k; +} +double get_angle(Point a) +{ + return atan2(a.y,a.x); +} +double cmp(node a,node b) +{ + if (dlcmp(a.s-b.s)==0) + return dlcmp(a.e-b.e)<0; + else + return dlcmp(a.s-b.s)<0; +} +int main() +{ + int n,p,x,y,r,i,j; + double ans,sum,cur; + node u,v; + Point s1,e1,s2,e2,vec,p1,p2; + while (scanf("%d%d%d%d%d",&n,&p,&x,&y,&r),n||p||x||y||r) + { + purple.o=Point(0,0); + purple.r=(double)p; + red.o.x=(double)x; + red.o.y=(double)y; + red.r=(double)r; + arc.clear(); + for (i=0;iu.e) + { + arc.push_back(node(u.s,PI)); + arc.push_back(node(-PI,u.e)); + } + else + arc.push_back(u); + } + sort(arc.begin(),arc.end(),cmp); + sum=arc[0].e-arc[0].s; + cur=arc[0].e; + for (i=1;i0) + sum+=arc[i].e-arc[i].s; + else + sum+=arc[i].e-cur; + cur=arc[i].e; + } + ans=(2*PI-sum)/(2*PI); + if (ans<0) + ans=0; + printf("%.4f\n",ans); + } + return 0; +} diff --git a/HDOJ/4265_autoAC.cpp b/HDOJ/4265_autoAC.cpp new file mode 100644 index 0000000..5364a46 --- /dev/null +++ b/HDOJ/4265_autoAC.cpp @@ -0,0 +1,185 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const int MAXN=1e+3; +const int MAXM=1e+5; +const int INF = numeric_limits::max(); +const LL LL_INF= numeric_limits::max(); +struct Edge +{ + int from,to; + LL ci;int next; + Edge(){} + Edge(int _from,int _to,LL _ci,int _next):from(_from),to(_to),ci(_ci),next(_next){} +}e[MAXM],e1[MAXM]; +int head[MAXN],tot; +int dis[MAXN]; +int top,sta[MAXN],cur[MAXN],tmp[MAXN]; +int vis1[100],vis2[MAXM]; +int n; +inline void init(){ + memset(head,-1,sizeof(head)); + tot=0; +} +inline void AddEdge(int u,int v,LL ci0,LL ci1=0){ + e[tot]=Edge(u,v,ci0,head[u]); + head[u]=tot++; + e[tot]=Edge(v,u,ci1,head[v]); + head[v]=tot++; +} +inline bool bfs(int st,int et){ + memset(dis,0,sizeof(dis)); + dis[st]=1; + queue q; + q.push(st); + while(!q.empty()){ + int now=q.front(); + q.pop(); + for(int i=head[now];i!=-1;i=e[i].next){ + int next=e[i].to; + if(vis2[i])continue; + if(e[i].ci&&!dis[next]){ + dis[next]=dis[now]+1; + if(next==et)return true; + q.push(next); + } + } + } + return false; +} +LL Dinic(int st,int et){ + LL ans=0; + while(bfs(st,et)){ + top=0; + memcpy(cur,head,sizeof(head)); + int u=st,i; + while(1){ + if(u==et){ + int pos; + LL minn=LL_INF; + for(i=0;ie[sta[i]].ci){ + minn=e[sta[i]].ci; + pos=i; + } + } + for(i=0;i>1; + for(int i=1;i<=n;i++){ + AddEdge(st,i,mid); + AddEdge(i+n,et,mid); + } + if(Dinic(st,et)==(LL)n*mid){ + ans=mid; + //if(ans +#include +#include +#include +#include +using namespace std; +#define PR 1e-9 +#define N 1100 +struct TPoint +{ + double x,y,z; + TPoint(){} + TPoint(double _x,double _y,double _z):x(_x),y(_y),z(_z){} + TPoint operator-(const TPoint p) {return TPoint(x-p.x,y-p.y,z-p.z);} + TPoint operator*(const TPoint p) {return TPoint(y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x);} + double operator^(const TPoint p) {return x*p.x+y*p.y+z*p.z;} +}; +TPoint dd; +struct fac +{ + int a,b,c; + bool ok; +}; +TPoint xmult(TPoint u,TPoint v) +{ + return TPoint(u.y*v.z-v.y*u.z,u.z*v.x-u.x*v.z,u.x*v.y-u.y*v.x); +} +double dmult(TPoint u,TPoint v) +{ + return u.x*v.x+u.y*v.y+u.z*v.z; +} +TPoint subt(TPoint u,TPoint v) +{ + return TPoint(u.x-v.x,u.y-v.y,u.z-v.z); +} +double vlen(TPoint u) +{ + return sqrt(u.x*u.x+u.y*u.y+u.z*u.z); +} +TPoint pvec(TPoint a,TPoint b,TPoint c) +{ + return xmult(subt(a,b),subt(b,c)); +} +double Dis(TPoint a,TPoint b,TPoint c,TPoint d) +{ + return fabs(dmult(pvec(a,b,c),subt(d,a)))/vlen(pvec(a,b,c)); +} +struct T3dhull +{ + int n; + TPoint ply[N]; + int trianglecnt; + fac tri[N]; + int vis[N][N]; + double dist(TPoint a){return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);} + double area(TPoint a,TPoint b,TPoint c){return dist((b-a)*(c-a));} + double volume(TPoint a,TPoint b,TPoint c,TPoint d){return (b-a)*(c-a)^(d-a);} + double ptoplane(TPoint &p,fac &f) + { + TPoint m=ply[f.b]-ply[f.a],n=ply[f.c]-ply[f.a],t=p-ply[f.a]; + return (m*n)^t; + } + void deal(int p,int a,int b) + { + int f=vis[a][b]; + fac add; + if(tri[f].ok) + { + if((ptoplane(ply[p],tri[f]))>PR) dfs(p,f); + else + { + add.a=b,add.b=a,add.c=p,add.ok=1; + vis[p][b]=vis[a][p]=vis[b][a]=trianglecnt; + tri[trianglecnt++]=add; + } + } + } + void dfs(int p,int cnt) + { + tri[cnt].ok=0; + deal(p,tri[cnt].b,tri[cnt].a); + deal(p,tri[cnt].c,tri[cnt].b); + deal(p,tri[cnt].a,tri[cnt].c); + } + bool same(int s,int e) + { + TPoint a=ply[tri[s].a],b=ply[tri[s].b],c=ply[tri[s].c]; + return fabs(volume(a,b,c,ply[tri[e].a]))PR) + { + swap(ply[1],ply[i]); tmp=false; break; + } + } + if(tmp) return; + tmp=true; + for(i=2;iPR) + { + swap(ply[2],ply[i]); tmp=false; break; + } + } + if(tmp) return ; + tmp=true; + for(i=3;iPR) + { + swap(ply[3],ply[i]); tmp=false; break; + } + } + if(tmp) return ; + fac add; + for(i=0;i<4;i++) + { + add.a=(i+1)%4,add.b=(i+2)%4,add.c=(i+3)%4,add.ok=1; + if((ptoplane(ply[i],add))>0) swap(add.b,add.c); + vis[add.a][add.b]=vis[add.b][add.c]=vis[add.c][add.a]=trianglecnt; + tri[trianglecnt++]=add; + } + for(i=4;iPR) + { + dfs(i,j); break; + } + } + } + int cnt=trianglecnt; + trianglecnt=0; + for(i=0;inow) _min=now; + } + return _min; + } +}hull; +int main() +{ + double now,_min; + while(scanf("%d",&hull.n)!=EOF) + { + if(hull.n==0) break; + int i,j,q; + for(i=0;i +#include +#include +#include +using namespace std; +const int N = 50010; +int cnt[N][11][11]; +int num[N]; +int inline lowbit(int x){ + return x & (-x); +} +void inline update(int x,int k,int mod,int add){ + while(x > 0){ + cnt[x][k][mod] += add; + x -= lowbit(x); + } +} +int inline sum(int x,int a){ + int s = 0; + while(x < N){ + for(int i = 1; i <= 10; ++i){ + s += cnt[x][i][a%i]; + } + x += lowbit(x); + } + return s; +} +int main(){ + int n; + while(scanf("%d",&n) != EOF){ + for(int i = 1; i <= n; ++i) + scanf("%d",&num[i]); + memset(cnt,0,sizeof(cnt)); + int m; + scanf("%d",&m); + while(m--){ + int op,a,b,k,add; + scanf("%d",&op); + if(op == 1){ + scanf("%d%d%d%d",&a,&b,&k,&add); + update(b,k,a%k,add); + update(a-1,k,a%k,-add); + } + else{ + scanf("%d",&a); + int ans = sum(a,a); + printf("%d\n",ans + num[a]); + } + } + } + return 0; +} diff --git a/HDOJ/4268_autoAC.cpp b/HDOJ/4268_autoAC.cpp new file mode 100644 index 0000000..8c5cf43 --- /dev/null +++ b/HDOJ/4268_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +using namespace std; +multiset myset; +multiset::iterator it; +const int maxn=200000; +struct node +{ + int x,y; + bool operator<(const node& b)const + { + return x0&&it!=myset.begin())it--; + if(myset.size()>0&&(*it)<=a[i].y) + { + ans++; + myset.erase(it); + } + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/4269_autoAC.cpp b/HDOJ/4269_autoAC.cpp new file mode 100644 index 0000000..fa4a100 --- /dev/null +++ b/HDOJ/4269_autoAC.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct Item { + int prz, typ, num; + int tn; + int us[65][2]; +}a[110]; +struct Name { + char name[20]; + bool operator < (const Name &b) const { + return strcmp(name, b.name) == -1; + } +}b; +map mmap; +map ::iterator it; +int id, fg; +int n; +char s[10000], ch, bf[1000]; +int cnt, gold, p; +int main(void) { + int cas = 0; + while (~scanf("%d", &n)) { + mmap.clear(); + cnt = gold = 0; + fg = 0; + cas++; + while (n--) { + scanf("%s", b.name); + it = mmap.find(b); + if (it == mmap.end()) { + mmap.insert(pair(b, fg++)); + id = fg - 1; + } else + id = it->second; + scanf("%d", &a[id].prz); + a[id].typ = 0; + a[id].num = a[id].tn = 0; + } + scanf("%d", &n); + while (n--) { + scanf("%s", b.name); + it = mmap.find(b); + if (it == mmap.end()) { + mmap.insert(pair(b, fg++)); + id = fg - 1; + } else + id = it->second; + scanf("%d", &a[id].prz); + a[id].typ = 1; + a[id].num = a[id].tn = 0; + getchar(); + cin.getline(s, 10000); + stringstream ss(s); + while (ss >> b.name) { + it = mmap.find(b); + if (it == mmap.end()) { + mmap.insert(pair(b, fg++)); + it = mmap.find(b); + } + a[id].us[a[id].tn][0] = it->second; + ss >> a[id].us[a[id].tn][1] >> bf; + a[id].tn++; + } + } + scanf("%d", &n); + while (n--) { + scanf("%s", b.name); + it = mmap.find(b); + if (it == mmap.end()) { + mmap.insert(pair(b, fg++)); + id = fg - 1; + } else + id = it->second; + scanf("%d", &a[id].prz); + a[id].typ = 2; + a[id].num = a[id].tn = 0; + } + scanf("%d", &n); + while (n--) { + //cout << "Gold = " << gold << endl; + scanf("%s", s); + if (isdigit(s[1])) { + p = 0; + for (int i = 1; s[i] != 0; i++) + p = p*10 + s[i] - 48; + if (s[0] == '+') + gold += p; + else if (gold >= p) + gold -= p; + } else { + sscanf(s+1, "%s", b.name); + it = mmap.find(b); + if (it == mmap.end()) + continue; + id = it->second; + if (s[0] == '+') { + if (a[id].typ == 0 && cnt < 6 && gold >= a[id].prz) { + a[id].num++; + cnt++; + gold -= a[id].prz; + } else if (a[id].typ == 2 && cnt < 6 && gold >= a[id].prz) { + if (a[id].num == 0) cnt++; + a[id].num++; + gold -= a[id].prz; + } else if (a[id].typ == 1 && gold >= a[id].prz) { + bool flag = 1; + int grid = 1; + for (int i = 0; i < a[id].tn && flag; i++) { + if (a[a[id].us[i][0]].num < a[id].us[i][1]) + flag = 0; + else + grid -= a[id].us[i][1]; + } + if (flag && cnt + grid <= 6) { + gold -= a[id].prz; + cnt += grid; + a[id].num++; + for (int i = 0; i < a[id].tn; i++) + a[a[id].us[i][0]].num -= a[id].us[i][1]; + } + } + } else if (a[id].num != 0) { + if (a[id].typ == 0) { + cnt--; + a[id].num--; + gold += a[id].prz; + } else if (a[id].typ == 1) { + cnt--; + a[id].num--; + int cost = a[id].prz; + for (int i = 0; i < a[id].tn; i++) + cost += a[id].us[i][1] * a[a[id].us[i][0]].prz; + gold += cost; + } else { + cnt--; + gold += a[id].prz * a[id].num; + a[id].num = 0; + } + } + } + } + printf("Case %d:\n%d\n%d\n", cas, gold, cnt); + for (it = mmap.begin(); it != mmap.end(); it++) { + for (int i = 0; i < a[it->second].num; i++) { + if (a[it->second].typ != 2) + printf("%s: 1\n", (it->first).name); + else { + printf("%s: %d\n", (it->first).name, a[it->second].num); + break; + } + } + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/4270_autoAC.cpp b/HDOJ/4270_autoAC.cpp new file mode 100644 index 0000000..c090976 --- /dev/null +++ b/HDOJ/4270_autoAC.cpp @@ -0,0 +1,97 @@ +#include +#include +const int MAXN = 200005; +struct SAMNode { + SAMNode *f, *ch[26]; + int len; + bool *d; + int pos; + int v; +}; +SAMNode *root, *last; +int p_cnt, d_cnt, seq_len, v_id; +SAMNode pool[MAXN*2]; +bool is_d[MAXN*2]; +char str[MAXN]; +SAMNode *seq[MAXN]; +bool is_del(SAMNode *x) { + return x == NULL || *x->d; +} +void append(char ch) { + int c = ch - 'a'; + SAMNode *p = last, *np = pool + p_cnt++; + memset(np, 0, sizeof(*np)); + np->pos = np->len = p->len + 1; + np->d = is_d + d_cnt++; + *np->d = false; + seq[seq_len = np->len] = np; + last = np; + for (; NULL != p && is_del(p->ch[c]); p = p->f) p->ch[c] = np; + if (NULL == p) { + np->f = root; + } else { + if (p->ch[c]->len == p->len + 1) { + np->f = p->ch[c]; + } else { + SAMNode *q = p->ch[c], *nq = pool + p_cnt++; + *nq = *q; + nq->len = p->len + 1; + q->f = np->f = nq; + for (; NULL != p && p->ch[c] == q; p = p->f) p->ch[c] = nq; + } + } +} +void del(int len) { + while (len--) *seq[seq_len--]->d = true; + last = seq[seq_len]; +} +int dfs_len; +int dfs(SAMNode *x, int l) { + if (l == dfs_len) return x->pos - l + 1; + if (x->v == v_id) return seq_len - l + 1; + for (int i = 0; i < 26; ++i) { + if (!is_del(x->ch[i])) { + return dfs(x->ch[i], l+1); + } + } + return x->len - l + 1; +} +int query(int len) { + ++v_id; + for (SAMNode *p = last; p != root; p = p->f) p->v = v_id; + dfs_len = len; + int ret = dfs(root, 0); + return ret; +} +int main() { + while (EOF != scanf("%s", str)) { + root = last = pool; + memset(root, 0, sizeof(*root)); + root->d = is_d; + is_d[0] = false; + p_cnt = 1; + d_cnt = 1; + v_id = 0; + seq[0] = root; + for (char *c = str; *c; ++c) append(*c); + int m, q, len; + scanf("%d", &m); + while (m--) { + scanf("%d", &q); + if (1 == q) { + scanf("%s", str); + for (char *c = str; *c; ++c) append(*c); + } else if (2 == q) { + scanf("%d", &len); + printf("%d\n", query(len)); + } else if (3 == q) { + scanf("%d", &len); + del(len); + } else { + for(;;); + fprintf(stderr, "error cmd %d\n", q); + } + } + } + return 0; +} diff --git a/HDOJ/4271_autoAC.cpp b/HDOJ/4271_autoAC.cpp new file mode 100644 index 0000000..798e560 --- /dev/null +++ b/HDOJ/4271_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#define MIN(a , b) ((a) < (b) ? (a) : (b)) +using namespace std; +const int inf = 1 << 29; +const int maxn = 100002; +const int maxm = 12; +char str[maxn],dtr[maxn + maxm],dic[maxm][maxm],huan[maxm]; +int dp[maxn + maxm][maxm]; +int m,len,llen; +int CompareString(char *s1,char *s2,int l1,int l2) +{ + memset(dp,0,sizeof(dp)); + for(int i=0;i<=l2;i++) + { + dp[0][i] = i; + } + for(int i=1;i<=l1;i++) + { + for(int j=1;j<=l2;j++) + { + int cost = (s1[i-1] == s2[j-1]) ? 0 : 1; + dp[i][j] = MIN(dp[i-1][j-1] + cost , MIN(dp[i-1][j] + 1 , dp[i][j-1] + 1)); + } + } + int res = inf; + for(int i=0;i<=l1;i++) + { + res = MIN(res , dp[i][l2]); + } + return res; +} +void solve() +{ + len = strlen(str); + strcpy(dtr , str); + for(int i=0;i 0)) + { + ans = tmp; + pos = i; + } + } + else + { + for(int s=0;s 0)) + { + ans = tmp; + pos = i; + } + } + } + } + printf("%s %d\n",dic[pos],ans); + return; +} +int main() +{ + while(~scanf("%s",str)) + { + solve(); + } + return 0; +} diff --git a/HDOJ/4272_autoAC.cpp b/HDOJ/4272_autoAC.cpp new file mode 100644 index 0000000..1c66a3c --- /dev/null +++ b/HDOJ/4272_autoAC.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#define MIN(a , b) ((a) < (b) ? (a) : (b)) +#define MAX(a , b) ((a) > (b) ? (a) : (b)) +using namespace std; +const int maxn = 1300; +int x[maxn],stack[maxn],cnt[maxn]; +bool dp[maxn][maxn],vis[maxn][maxn]; +int n; +void read() +{ + memset(cnt,0,sizeof(cnt)); + memset(vis,false,sizeof(vis)); + for(int i=0;i=0 && use < 5;i--) + { + if(st & (1 << (dep - i))) + { + use++; + if(stack[dep] == stack[i]) + { + int cur = st; + cur ^= 1; + cur ^= (1 << (dep - i)); + if(cur == 0) + { + flag = true; + break; + } + int pos = dep; + while((cur & 1) == 0) + { + cur >>= 1; + pos--; + } + int end = to-1; + while(end >= 0 && pos - end < 10) + { + cur |= (1 << (pos - end)); + end--; + } + if(dfs(pos , end+1 , cur)) + { + flag = true; + break; + } + } + } + } + vis[dep][st] = true; + return dp[dep][st] = flag; +} +int main() +{ + while(~scanf("%d",&n)) + { + read(); + if(check() == false) + { + puts("0"); + continue; + } + puts(dfs(n-1 , MAX(n-10 , 0) , (1 << MIN(10 , n)) - 1) ? "1" : "0"); + } + return 0; +} diff --git a/HDOJ/4273_autoAC.cpp b/HDOJ/4273_autoAC.cpp new file mode 100644 index 0000000..36ecc58 --- /dev/null +++ b/HDOJ/4273_autoAC.cpp @@ -0,0 +1,255 @@ +#include +#include +#include +#include +#include +using namespace std; +const int MAXN=550; +const double eps=1e-8; +struct Point +{ + double x,y,z; + Point(){} + Point(double xx,double yy,double zz):x(xx),y(yy),z(zz){} + Point operator -(const Point p1) + { + return Point(x-p1.x,y-p1.y,z-p1.z); + } + Point operator +(const Point p1) + { + return Point(x+p1.x,y+p1.y,z+p1.z); + } + Point operator *(const Point p) + { + return Point(y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x); + } + Point operator *(double d) + { + return Point(x*d,y*d,z*d); + } + Point operator / (double d) + { + return Point(x/d,y/d,z/d); + } + double operator ^(Point p) + { + return (x*p.x+y*p.y+z*p.z); + } +}; +struct CH3D +{ + struct face + { + int a,b,c; + bool ok; + }; + int n; + Point P[MAXN]; + int num; + face F[8*MAXN]; + int g[MAXN][MAXN]; + double vlen(Point a) + { + return sqrt(a.x*a.x+a.y*a.y+a.z*a.z); + } + Point cross(const Point &a,const Point &b,const Point &c) + { + return Point((b.y-a.y)*(c.z-a.z)-(b.z-a.z)*(c.y-a.y), + (b.z-a.z)*(c.x-a.x)-(b.x-a.x)*(c.z-a.z), + (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x) + ); + } + double area(Point a,Point b,Point c) + { + return vlen((b-a)*(c-a)); + } + double volume(Point a,Point b,Point c,Point d) + { + return (b-a)*(c-a)^(d-a); + } + double dblcmp(Point &p,face &f) + { + Point m=P[f.b]-P[f.a]; + Point n=P[f.c]-P[f.a]; + Point t=p-P[f.a]; + return (m*n)^t; + } + void deal(int p,int a,int b) + { + int f=g[a][b]; + face add; + if(F[f].ok) + { + if(dblcmp(P[p],F[f])>eps) + dfs(p,f); + else + { + add.a=b; + add.b=a; + add.c=p; + add.ok=true; + g[p][b]=g[a][p]=g[b][a]=num; + F[num++]=add; + } + } + } + void dfs(int p,int now) + { + F[now].ok=0; + deal(p,F[now].b,F[now].a); + deal(p,F[now].c,F[now].b); + deal(p,F[now].a,F[now].c); + } + bool same(int s,int t) + { + Point &a=P[F[s].a]; + Point &b=P[F[s].b]; + Point &c=P[F[s].c]; + return fabs(volume(a,b,c,P[F[t].a]))eps) + { + swap(P[1],P[i]); + flag=false; + break; + } + } + if(flag)return; + flag=true; + for(i=2;ieps) + { + swap(P[2],P[i]); + flag=false; + break; + } + } + if(flag)return; + flag=true; + for(int i=3;ieps) + { + swap(P[3],P[i]); + flag=false; + break; + } + } + if(flag)return; + for(i=0;i<4;i++) + { + add.a=(i+1)%4; + add.b=(i+2)%4; + add.c=(i+3)%4; + add.ok=true; + if(dblcmp(P[i],add)>0)swap(add.b,add.c); + g[add.a][add.b]=g[add.b][add.c]=g[add.c][add.a]=num; + F[num++]=add; + } + for(i=4;ieps) + { + dfs(i,j); + break; + } + } + } + tmp=num; + for(i=num=0;i +#include +#include +#include +#include +#include +#include +#include +#define inf 110000000 +#define M 10005 +#define N 10005 +#define Min(a,b) ((a)<(b)?(a):(b)) +#define Max(a,b) ((a)>(b)?(a):(b)) +#define pb(a) push_back(a) +#define mem(a,b) memset(a,b,sizeof(a)) +#define LL long long +#define MOD 1000000007 +using namespace std; +struct Node{ + int v,next; +}edge[N*2]; +int n,start[N],tot; +int up[N],low[N]; +void addedge(int u,int v){ + edge[tot].v=v; + edge[tot].next=start[u]; + start[u]=tot++; +} +void _addedge(int u,int v){ + addedge(u,v); + addedge(v,u); +} +bool ans; +void dfs(int u,int pre){ + if(ans) return; + if(up[u]!=-1&&low[u]>up[u]){ans=true;return;} + int tmp=0; + int leaf=1; + for(int i=start[u];i!=-1;i=edge[i].next){ + int v=edge[i].v; + if(v==pre) continue; + dfs(v,u); + leaf=0; + tmp+=low[v]; + } + if(leaf) return; + low[u]=max(tmp+1,low[u]); + if(up[u]!=-1&&low[u]>up[u]) ans=true; +} +int main(){ + while(scanf("%d",&n)!=EOF){ + tot=0;mem(start,-1); + for(int i=2;i<=n;i++){ + int u; + scanf("%d",&u); + _addedge(u,i); + } + int m; + for(int i=1;i<=n;i++){low[i]=1;up[i]=-1;} + scanf("%d",&m); + for(int i=0;i') low[u]=w+1; + else low[u]=up[u]=w; + } + ans=false; + dfs(1,0); + puts(ans?"Lie":"True"); + } + return 0; +} diff --git a/HDOJ/4275_autoAC.cpp b/HDOJ/4275_autoAC.cpp new file mode 100644 index 0000000..46153e0 --- /dev/null +++ b/HDOJ/4275_autoAC.cpp @@ -0,0 +1,187 @@ +#pragma comment(linker, "/STACK:16777216") +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const double eps(1e-8); +typedef long long lint; +#define hash hhhhhhh +#define end eeeeend +#define maxn 50010 +const lint mod = 1e9 + 7; +const lint A = 233, P = 23333, Q = 1e9 + 1027, B = 50009; +int n, m; +int dis[maxn]; +bool flag; +vector dia; +int start, end; +lint hash[maxn], cnt[maxn]; +int idx[maxn]; +lint fac[maxn]; +vector G[maxn]; +int center; +void dfs(int now, int fa) +{ + int nex; + for(int i = 0, sz = G[now].size(); i < sz; i++) if((nex = G[now][i]) != fa) + { + dis[nex] = dis[now] + 1; + dfs(nex, now); + } + return; +} +bool getDiameter(int now, int fa) +{ + int nex; + for(int i = 0, sz = G[now].size(); i < sz; i++) if((nex = G[now][i]) != fa) + if(getDiameter(nex, now)) + { + dia.push_back(now); + return true; + } + if(now == end) + { + dia.push_back(now); + return true; + } + return false; +} +void diameter() +{ + dis[1] = 0; + dfs(1, -1); + start = 1; + for(int i = 1; i <= n; i++) + if(dis[start] < dis[i]) start = i; + dis[start] = 0; + dfs(start, -1); + end = start; + for(int i = 1; i <= n; i++) + if(dis[end] < dis[i]) end = i; + dia.clear(); + getDiameter(start, -1); + if(dis[end] & 1) + { + flag = true; + int centerLeft = dia[(dia.size() >> 1) - 1]; + int centerRight = dia[dia.size() >> 1]; + center = n + 1; + G[center].push_back(centerLeft); + G[center].push_back(centerRight); + for(int i = 0, sz = G[centerLeft].size(); i < sz; i++) + if(G[centerLeft][i] == centerRight) + { + G[centerLeft][i] = center; + break; + } + for(int i = 0, sz = G[centerRight].size(); i < sz; i++) + if(G[centerRight][i] == centerLeft) + { + G[centerRight][i] = center; + break; + } + } + else + center = dia[dia.size() >> 1]; + return; +} +lint quick(lint base, lint pow) +{ + lint ret = 1; + while(pow) + { + if(pow & 1) ret = ret*base % mod; + base = base*base % mod; + pow >>= 1; + } + return ret; +} +lint C(int x, int y) +{ + lint ret = 1; + for(int i = 1; i + x - y <= x; i++) + ret = ret*(x - y + i) % mod; + ret = ret*quick(fac[y], mod - 2) % mod; + return ret; +} +bool cmp(int x, int y) +{ + return hash[x] < hash[y]; +} +void calc(int now, int fa) +{ + int nex; + for(int i = 0, sz = G[now].size(); i < sz; i++) if((nex = G[now][i]) != fa) + calc(nex, now); + if(G[now].size() == 1) + { + hash[now] = A*B % Q;//hash间负A*B % Q + cnt[now] = m; + return; + } + hash[now] = A*B % Q; + cnt[now] = m; + int num = 0; + for(int i = 0, sz = G[now].size(); i < sz; i++) if((nex = G[now][i]) != fa) + idx[num++] = nex; + sort(idx, idx + num, cmp); + for(int i = 0; i < num; i++) + { + nex = idx[i]; + hash[now] *= P; + hash[now] ^= hash[nex]; + hash[now] %= Q; + } + hash[now] = hash[now] * B % Q; + int st = 0; + while(st < num) + { + lint val = hash[idx[st]]; + lint kinds = cnt[idx[st]]; + lint count = 1; + st++; + while(st < num && val == hash[idx[st]]) + count++, st++; + cnt[now] = cnt[now] * C(kinds + count - 1, count) % mod; + } + return; +} +int main() +{ + fac[0] = 1; + for(int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod; + while(~scanf("%d %d", &n, &m)) + { + for(int i = 1; i <= n + 1; i++) G[i].clear(); + for(int i = 1; i < n; i++) + { + int u, v; + scanf("%d %d", &u, &v); + G[u].push_back(v); + G[v].push_back(u); + } + flag = false; + diameter(); + calc(center, -1); + if(flag) + printf("%I64d\n", cnt[center] * quick(m, mod - 2) % mod); + else printf("%I64d\n", cnt[center]); + } + return 0; +} diff --git a/HDOJ/4276_autoAC.cpp b/HDOJ/4276_autoAC.cpp new file mode 100644 index 0000000..96244ef --- /dev/null +++ b/HDOJ/4276_autoAC.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +using namespace std; +const int N=105; +int head[N],tot; +int dp[N][N*5]; +struct Edge +{ + int from,to,cost,pre; + Edge(){} + Edge(int a,int b,int c,int d){from=a;to=b;cost=c;pre=d;} +}edge[N*3]; +void addEdge(int u,int v,int cost) +{ + edge[tot]=Edge(u,v,cost,head[u]); + head[u]=tot++; +} +int spfa(int st,int ed) +{ + queue que; + int vis[N],dis[N],pre[N]; + memset(vis,0,sizeof(vis)); + memset(dis,0x7f,sizeof(dis)); + memset(pre,-1,sizeof(pre)); + que.push(st); + vis[st]=1; dis[st]=0; + while(!que.empty()) + { + int u=que.front(); + que.pop(); vis[u]=0; + for(int i=head[u];i!=-1;i=edge[i].pre) + { + int v=edge[i].to,cost=edge[i].cost; + if(dis[v]>dis[u]+cost) + { + dis[v]=dis[u]+cost; + pre[v]=i; + if(!vis[v]) + { + vis[v]=1; + que.push(v); + } + } + } + } + for(int i=ed;i!=st;i=edge[pre[i]].from) + { + edge[pre[i]].cost=0; + edge[pre[i]^1].cost=0; + } + return dis[ed]; +} +void dfs(int u,int fa,int coin) +{ + for(int e=head[u];e!=-1;e=edge[e].pre) + { + int v=edge[e].to,cost=edge[e].cost*2; + if(v==fa||coin=cost;i--) + { + for(int j=0;j+cost<=i;j++) + { + if(dp[u][i-j-cost]!=-1&&dp[v][j]!=-1) + dp[u][i]=max(dp[u][i],dp[u][i-j-cost]+dp[v][j]); + } + } + } +} +int main() +{ + int n,t; + while(scanf("%d%d",&n,&t)!=EOF) + { + tot=0; + memset(dp,-1,sizeof(dp)); + memset(head,-1,sizeof(head)); + for(int i=0;i +#include +#include +#include +#include +#include +#include +#define LL long long +#define N 25 +using namespace std; +int num[N]; +int n,summ,xj,xk; +int Case; +struct node +{ + int x,y,z; + bool operator < (const struct node &a) const + { + return (x!=a.x)?(x hashx; +void dfs(int); +int main() +{ + scanf("%d",&Case); + for(int c=0;cn) + { + xj=temp.x; + xk=temp.y; + if(((xj+xk)>(summ-xj-xk))&&(summ-xk>xk)&&(summ-xj>xj)) + { + ans.x=max(xj,max(summ-xj-xk,xk)); + ans.z=min(xj,min(summ-xj-xk,xk)); + if(xj!=ans.x&&xj!=ans.z) ans.y=xj; + else if(xk!=ans.x&&xk!=ans.z) ans.y=xk; + else ans.y=summ-ans.x-ans.z; + hashx.insert(ans); + } + return; + } + dfs(x+1); + temp.x+=num[x]; + dfs(x+1); + temp.x-=num[x]; + temp.y+=num[x]; + dfs(x+1); + temp.y-=num[x]; +} diff --git a/HDOJ/4278_autoAC.cpp b/HDOJ/4278_autoAC.cpp new file mode 100644 index 0000000..b93d8a1 --- /dev/null +++ b/HDOJ/4278_autoAC.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + int n; + char num[15]; + while(scanf("%s",num)) + { + if(num[0]=='0') + break; + int l=strlen(num); + int i; + int sum=0; + for(i=0;i>1; + temp=mid*mid+4*mid; + if(temp<=x) low=mid+1; + else up=mid-1; + } + low--; + ans=low*(low+1)/2 + (low/2 + low%2)*3; + temp=x-(low*low+4*low); + if(!temp) return ans; + if(temp<=(low+1)*2) + { + if((low+1)%2) ans+=temp/2 + temp%2; + else ans+=(temp-1)/2 + (temp-1)%2; + } + else + { + ans+=low+1; + if((low+1)%2) ans+=temp-(low+1)*2; + } + return ans; +} +int main() +{ + int T; + unsigned __int64 a,b,ans[2]; + cin>>T; + while(T--) + { + scanf("%I64u%I64u",&a,&b); + if(b<=5) {printf("0\n");continue;} + if(a<=6)a=0; + else a-=6; + b-=5; + ans[0]=solve(a); + ans[1]=solve(b); + printf("%I64u\n",ans[1]-ans[0]); + } + return 0; +} diff --git a/HDOJ/4280_autoAC.cpp b/HDOJ/4280_autoAC.cpp new file mode 100644 index 0000000..3b89bcf --- /dev/null +++ b/HDOJ/4280_autoAC.cpp @@ -0,0 +1,105 @@ +#include"stdio.h" +#include"string.h" +#pragma comment(linker, "/STACK:1024000000,1024000000") +#define inf 99999999 +int min(int a,int b) +{ + return a0) + { + level[edge[k].to]=level[top]+1; + q[rear++]=edge[k].to; + } + } + } + return false; +} +int dfs(int now,int maxf,int t) +{ + int ret=0,f,k; + if(now==t) + return maxf; + for(k=head[now];k!=-1;k=edge[k].next) + { + if(level[edge[k].to]==level[now]+1&&edge[k].val>0) + { + f=dfs(edge[k].to,min(maxf-ret,edge[k].val),t); + edge[k].val-=f; + edge[k^1].val+=f; + ret+=f; + if(ret==maxf) + return ret; + } + } + if(ret==0) + level[now]=0; + return ret; +} +int dinic(int s,int t) +{ + int ans=0; + while(bfs(s,t)) + ans+=dfs(s,inf,t); + return ans; +} +int main( ) +{ + int T,i,n,m,s,t; + int x,y,w,ps,pt; + scanf("%d",&T); + while(T--) + { + e=0;s=inf;t=0; + memset(head,-1,sizeof(head)); + scanf("%d%d",&n,&m); + for(i=1;i<=n;i++) + { + scanf("%d%d",&x,&y); + if(s>x) + {s=x;ps=i;} + if(t +#include +#include +#include +#include +using namespace std; +#define inf 1<<30 +struct Point{ + int x,y; +}point[17]; +int n,m,ans,val[17],dp1[1<<17]; +int dp[1<<17][17],best[1<<17]; +int Ok[1<<17]; +int dist[17][17]; +int Get_Dist(int i,int j) +{ + return ceil(sqrt(double(point[i].x-point[j].x)*(point[i].x-point[j].x)+double(point[i].y-point[j].y)*(point[i].y-point[j].y))); +} +int Judge(int state) +{ + int sum=0; + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +long long quickpow(long long a,long long b) +{ + long long n=1; + while(b>0) + { + if(b&1) + { + n*=a; + } + b>>=1; + a*=a; + } + return n; +} +int main() +{ + long long n; + while(scanf("%I64d",&n),n) + { + long long sign=0; + long long num=0; + for(int i=1;i<=sqrt(n);i++) + { + if(i*i==n) + { + num=i; + break; + } + } + if(num) + { + if(num%2==0) + sign+=(num/2-1); + else + sign+=(num/2); + } + for(long long k=3;k<=31;k++) + { + for(long long i=1;i<=1500;i++) + { + for(long long j=i+1;j<=1500;j++) + { + long long powsum=quickpow(j,k)+quickpow(i,k)+j*i*k; + if(powsum==n) + sign++; + if(powsum>n||powsum<0) + break; + } + if(quickpow(i,k)>n) + break; + } + } + printf("%I64d\n",sign); + } +} diff --git a/HDOJ/4283_autoAC.cpp b/HDOJ/4283_autoAC.cpp new file mode 100644 index 0000000..6dc97f2 --- /dev/null +++ b/HDOJ/4283_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +using namespace std; +const int inf = 10000000; +int n,a[105],sum[105],dp[105][105]; +int main() +{ + int t,i,j,k,l,cas = 1; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + memset(sum,0,sizeof(sum)); + for(i = 1; i<=n; i++) + { + scanf("%d",&a[i]); + sum[i] = sum[i-1]+a[i]; + } + memset(dp,0,sizeof(dp)); + for(i = 1; i<=n; i++) + { + for(j = i+1; j<=n; j++) + dp[i][j] = inf; + } + for(l = 1; l +#include +#define max(a,b)(a)>(b)?(a):(b) +#define INF 0x3f3f3f3f +int g[155][155]; +int dp[1<<16][16]; +int num[22]; +int earn[22]; +int cost[22]; +int main() +{ + int t,i,j,k,mon,n,m; + scanf("%d",&t); + while(t--) + { + scanf("%d%d%d",&n,&m,&mon); + memset(g,INF,sizeof(g)); + for(i=1;i<=n;i++) + g[i][i]=0; + int a,b,c; + while(m--) + { + scanf("%d%d%d",&a,&b,&c); + if(c=0) + dp[1<=0) + { + tmp+=earn[k]; + int stat=i+(1<=0) + { + flag=1; + break; + } + } + if(flag) + printf("YES\n"); + else printf("NO\n"); + } + return 0; +} diff --git a/HDOJ/4285_autoAC.cpp b/HDOJ/4285_autoAC.cpp new file mode 100644 index 0000000..9f1572b --- /dev/null +++ b/HDOJ/4285_autoAC.cpp @@ -0,0 +1,190 @@ +#include +#include +#include +#include +using namespace std; +const int MAXD=15; +const int STATE=1000010; +const int HASH=300007; +const int MOD=1000000007; +int N,M,K; +int maze[MAXD][MAXD]; +int code[MAXD]; +int ch[MAXD]; +int num; +struct HASHMAP +{ + int head[HASH],next[STATE],size; + long long state[STATE]; + int f[STATE]; + void init() + { + size=0; + memset(head,-1,sizeof(head)); + } + void push(long long st,int ans) + { + int i; + int h=st%HASH; + for(i=head[h];i!=-1;i=next[i]) + if(state[i]==st) + { + f[i]+=ans; + f[i]%=MOD; + return; + } + state[size]=st; + f[size]=ans; + next[size]=head[h]; + head[h]=size++; + } +}hm[2]; +void decode(int *code,int m,long long st) +{ + num=st&63; + st>>=6; + for(int i=m;i>=0;i--) + { + code[i]=st&7; + st>>=3; + } +} +long long encode(int *code,int m) +{ + int cnt=1; + memset(ch,-1,sizeof(ch)); + ch[0]=0; + long long st=0; + for(int i=0;i<=m;i++) + { + if(ch[code[i]]==-1)ch[code[i]]=cnt++; + code[i]=ch[code[i]]; + st<<=3; + st|=code[i]; + } + st<<=6; + st|=num; + return st; +} +void shift(int *code,int m) +{ + for(int i=m;i>0;i--)code[i]=code[i-1]; + code[0]=0; +} +void dpblank(int i,int j,int cur) +{ + int k,left,up; + for(k=0;k=K)continue; + int t=0; + for(int p=0;p +#include +#include +#include +#include +#define N 1000005 +#define inf 1<<29 +#define MOD 100000007 +#define LL long long +#define Key_value ch[ch[root][1]][0] +#define _match(a,b) ((a)==(b)) +#pragma comment(linker, "/STACK:1024000000,1024000000") +using namespace std; +int n,q,a[N],pl,pr; +int size[N],pre[N],rev[N],sum[5],val[N]; +int ch[N][2],tot1,root,s[N],tot2; +inline void NewNode(int &r,int k,int father){ + if(tot2) + r=s[tot2--]; + else + r=++tot1; + ch[r][0]=ch[r][1]=0; + pre[r]=father; + size[r]=1; + rev[r]=0; + val[r]=k; +} +inline void Push_Up(int x){ + int l=ch[x][0],r=ch[x][1]; + size[x]=size[l]+size[r]+1; +} +inline void Push_Down(int r){ + if(rev[r]){ + rev[ch[r][0]]^= 1; + rev[ch[r][1]]^= 1; + swap(ch[r][0],ch[r][1]); + rev[r]=0; + } +} +inline void Bulid(int &r,int L,int R,int father){ + if(L>R) + return ; + int mid=(L+R)/2; + NewNode(r,a[mid],father); + Bulid(ch[r][0],L,mid-1,r); + Bulid(ch[r][1],mid+1,R,r); + Push_Up(r); +} +void Init(){ + tot1=tot2=root=0; + ch[root][0]=ch[root][1]=pre[root]=rev[root]=size[root]=0; + NewNode(root,-100,0); + NewNode(ch[root][1],-1,root); + Push_Up(root); + Bulid(Key_value,1,n,ch[root][1]); + Push_Up(ch[root][1]); + Push_Up(root); +} +inline void Rotate(int x,int kind){ + int y=pre[x]; + Push_Down(y); + Push_Down(x); + ch[y][!kind]=ch[x][kind]; + pre[ch[x][kind]]=y; + if(pre[y]) + ch[pre[y]][ch[pre[y]][1]==y]=x; + pre[x]=pre[y]; + ch[x][kind]=y; + pre[y]=x; + Push_Up(y); +} +inline void Splay(int r,int goal){ + Push_Down(r); + while(pre[r]!=goal){ + if(pre[pre[r]]==goal) + Rotate(r,ch[pre[r]][0]==r); + else{ + int y=pre[r]; + int kind=(ch[pre[y]][0]==y); + if(ch[y][kind]==r){ + Rotate(r,!kind); + Rotate(r,kind); + } + else{ + Rotate(y,kind); + Rotate(r,kind); + } + } + } + Push_Up(r); + if(goal==0) root=r; +} +inline void RotateTo(int k, int goal) { + int x=root; + Push_Down(x); + while(k!=size[ch[x][0]]+1){ + if (k<=size[ch[x][0]]){ + x=ch[x][0]; + }else{ + k-=(size[ch[x][0]]+1); + x=ch[x][1]; + } + Push_Down(x); + } + Splay(x,goal); +} +void Print(); +inline void Reversal(int pos,int k){ + RotateTo(pos,0); + RotateTo(pos+k+1,root); + rev[Key_value]^=1; +} +inline void Insert(int pos,int k,int num){ + RotateTo(pos,0); + RotateTo(pos+1,root); + NewNode(Key_value,num,ch[root][1]); + Push_Up(ch[root][1]); + Push_Up(root); +} +inline void Delete(int pos,int k){ + RotateTo(pos,0); + RotateTo(pos+k+1,root); + Key_value=0; + Push_Up(ch[root][1]); +} +int cnt,ans[N]; +inline void scanf_(int &num){ + char in; + bool neg=false; + while(((in=getchar()) > '9' || in<'0') && in!='-') ; + if(in=='-'){ + neg=true; + while((in=getchar()) >'9' || in<'0'); + } + num=in-'0'; + while(in=getchar(),in>='0'&&in<='9') + num*=10,num+=in-'0'; + if(neg) + num=0-num; +} +inline void printf_(int num){ + bool flag=false; + if(num<0){ + putchar('-'); + num=-num; + } + int ans[10],top=0; + while(num!=0){ + ans[top++]=num%10; + num/=10; + } + if(top==0) + putchar('0'); + for(int i=top-1;i>=0;i--){ + char ch=ans[i]+'0'; + putchar(ch); + } +} +void InOrder(int r){ + if(r==0) + return; + Push_Down(r); + InOrder(ch[r][0]); + if(cnt) putchar(' '); + printf_(val[r]); + cnt++; + InOrder(ch[r][1]); +} +void Print(){ + RotateTo(1,0); + RotateTo(n+2,root); + cnt=0; + InOrder(Key_value); + putchar('\n'); +} +int main(){ + int t; + scanf_(t); + while(t--){ + scanf_(n); + for(int i=1;i<=n;i++) + scanf_(a[i]); + Init(); + char str[20]; + int k=1,pl,r1; + scanf_(pl);scanf_(pr);scanf_(q); + while(q--){ + scanf("%s",str); + if(str[0]=='M'&&str[4]=='R'){ + scanf("%s",str); + if(str[0]=='L') pl++; + else pr++; + } + else if(str[0]=='M'&&str[4]=='L'){ + scanf("%s",str); + if(str[0]=='L') pl--; + else pr--; + } + else if(str[0]=='I'){ + scanf("%s",str); + scanf_(a[1]); + if(str[0]=='L') {Insert(pl,k,a[1]);} + else {Insert(pr+1,k,a[1]);} + n++;pr++; + } + else if(str[0]=='D'){ + scanf("%s",&str); + if(str[0]=='L') {Delete(pl,k);} + else {Delete(pr,k);} + n--;pr--; + } + else if(str[0]=='R') + Reversal(pl,pr-pl+1); + } + Print(); + } + return 0; +} diff --git a/HDOJ/4287_autoAC.cpp b/HDOJ/4287_autoAC.cpp new file mode 100644 index 0000000..a34da3e --- /dev/null +++ b/HDOJ/4287_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +int hash[128]; +struct TrieNode{ + int no; + TrieNode *next[10]; +}node[30005]; +TrieNode *root = &node[0]; +int cnt,result[5005]; +char word[10],s[10]; +void init() +{ + hash['a']=hash['b']=hash['c']=2; + hash['d']=hash['e']=hash['f']=3; + hash['g']=hash['h']=hash['i']=4; + hash['j']=hash['k']=hash['l']=5; + hash['m']=hash['n']=hash['o']=6; + hash['p']=hash['q']=hash['r']=hash['s']=7; + hash['t']=hash['u']=hash['v']=8; + hash['w']=hash['x']=hash['y']=hash['z']=9; +} +void initRoot() +{ + int i; + for(i=0;i<10;i++) + { + root->next[i]=NULL; + } +} +void insert(char str[],int num) +{ + TrieNode *p = root; + int len=strlen(str),i,j; + for(i=0;inext[str[i]-'0']==NULL) + { + p->next[str[i]-'0']=&node[cnt]; + for(j=0;j<10;j++)node[cnt].next[j]=NULL; + node[cnt].no=-1; + cnt++; + } + p=p->next[str[i]-'0']; + } + p->no=num; +} +void query(char str[]) +{ + int len=strlen(str),i; + TrieNode *p=root; + for(i=0;inext[hash[str[i]]]; + if(p==NULL)break; + } + if(p==NULL)return; + else{ + if(p->no!=-1)result[p->no]++; + } +} +int main() +{ + int t,m,n,i; + scanf("%d",&t); + init(); + while(t--) + { + cnt=1; + initRoot(); + memset(result,0,sizeof(result)); + scanf("%d%d",&n,&m); + for(i=0;i +#include +#include +using namespace std; +int n; +int a[100005],len; +char str[10]; +__int64 sum; +int main() +{ + int i,j,k; + while(~scanf("%d",&n)) + { + len = 0; + while(n--) + { + scanf("%s",str); + if(!strcmp(str,"add")) + { + scanf("%d",&k); + for(i = len++; i>0; i--) + { + if(a[i-1]>k) + a[i] = a[i-1]; + else + break; + } + a[i] = k; + } + else if(!strcmp(str,"del")) + { + scanf("%d",&k); + for(i = 0; i +#include +using namespace std; +const int inf=1<<30; +const int nMax=10105; +const int mMax=3000005; +struct Node +{ + int c,u,v,next; + void insert(int nu,int nv,int nc,int nnext) + { + u=nu; + v=nv; + c=nc; + next=nnext; + } +}edge[mMax]; +int ne,head[nMax]; +int cur[nMax],ps[nMax],dep[nMax]; +void addedge(int u,int v,int w) +{ + edge[ne].insert(u,v,w,head[u]); + head[u]=ne++; + edge[ne].insert(v,u,0,head[v]); + head[v]=ne++; +} +int dinic(int s, int t){ + int tr, res = 0; + int i, j, k, f, r, top; + while(1){ + memset(dep, -1, sizeof(dep)); + for(f = dep[ps[0]=s] = 0, r = 1; f != r;) + { + for(i = ps[f ++], j = head[i]; j; j = edge[j].next) + { + if(edge[j].c && dep[k=edge[j].v] == -1) + { + dep[k] = dep[i] + 1; + ps[r ++] = k; + if(k == t) + { + f = r; break; + } + } + } + } + if(dep[t] == -1) break; + memcpy(cur, head, sizeof(cur)); + i = s, top = 0; + while(1) + { + if(i == t) + { + for(tr =inf, k = 0; k < top; k ++) + { + if(edge[ps[k]].c < tr) + { + tr = edge[ps[f=k]].c; + } + } + for(k = 0; k < top; k ++) + { + edge[ps[k]].c -= tr; + edge[ps[k]^1].c += tr; + } + i = edge[ps[top=f]].u; + res += tr; + } + for(j = cur[i]; cur[i]; j = cur[i] =edge[cur[i]].next) + { + if(edge[j].c && dep[i]+1 == dep[edge[j].v]) + { + break; + } + } + if(cur[i]) + { + ps[top ++] = cur[i]; + i = edge[cur[i]].v; + } + else + { + if(top == 0) + { + break; + } + dep[i] = -1; + i = edge[ps[-- top]].u; + } + } + } + return res; +} +int main() +{ + int i,j,a,b,s,t,m,n; + while(~scanf("%d%d%d%d",&n,&m,&s,&t)) + { + ne=2; + memset(head,0,sizeof(head)); + for(i=1;i<=n;i++) + { + scanf("%d",&a); + addedge(i,i+n,a); + } + for(i=1;i<=m;i++) + { + scanf("%d%d",&a,&b); + addedge(a+n,b,inf); + addedge(b+n,a,inf); + } + int res=dinic(s,t+n); + printf("%d\n",res); + } + return 0; +} diff --git a/HDOJ/4290_autoAC.cpp b/HDOJ/4290_autoAC.cpp new file mode 100644 index 0000000..99a8131 --- /dev/null +++ b/HDOJ/4290_autoAC.cpp @@ -0,0 +1,79 @@ +#include +#include +#define MAXD 33 +#define MOD 1000000007 +typedef __int64 LL; +int N, M, K; +LL C[MAXD][MAXD][MAXD], f[MAXD][MAXD], X[MAXD], S[MAXD]; +LL fac(LL a, int n) +{ + int i; + LL ans = 1; + for(i = 0; i < n; i ++) ans = ans * a % MOD; + return ans; +} +void exgcd(LL a, LL b, LL &x, LL &y) +{ + if(b == 0) x = 1, y = 0; + else exgcd(b, a % b, y, x), y -= x * (a / b); +} +LL getinv(LL a) +{ + LL x, y; + exgcd(a, MOD, x, y); + x %= MOD; + if(x < 0) x += MOD; + return x; +} +void prepare() +{ + int i, j, t; + memset(C, 0, sizeof(C)); + C[1][0][0] = 1; + for(i = 1; i <= 32; i ++) + { + C[1][i][0] = 1; + for(j = 1; j <= i; j ++) + C[1][i][j] = (C[1][i - 1][j] + C[1][i - 1][j - 1]) % MOD; + } + for(t = 2; t <= 32; t ++) + for(i = 0; i <= 32; i ++) + for(j = 0; j <= 32; j ++) + C[t][i][j] = fac(C[1][i][j], t); +} +void solve() +{ + int i, j, k, t; + LL ans; + for(t = 1; t <= N; t ++) + { + memset(f, 0, sizeof(f)), f[0][0] = 1; + for(i = 1; i <= K; i ++) + for(j = 0; j <= M; j ++) + for(k = 0; k <= j; k ++) + f[i][j] = (f[i][j] + f[i - 1][k] * C[t][M - k][j - k]) % MOD; + X[t] = f[K][M]; + } + S[0] = 1, S[1] = X[1]; + for(i = 2; i <= N; i ++) + { + S[i] = 0; + for(j = 1; j <= i; j ++) + { + if(j & 1) S[i] = (S[i] + S[i - j] * X[j] + MOD) % MOD; + else S[i] = (S[i] - S[i - j] * X[j] + MOD) % MOD; + } + S[i] = S[i] * getinv(i) % MOD; + } + ans = S[N]; + for(i = 2; i <= N; i ++) ans = ans * i % MOD; + if(ans < 0) ans += MOD; + printf("%I64d\n", ans); +} +int main() +{ + prepare(); + while(scanf("%d%d%d", &N, &M, &K) == 3) + solve(); + return 0; +} diff --git a/HDOJ/4292_autoAC.cpp b/HDOJ/4292_autoAC.cpp new file mode 100644 index 0000000..e9b5d3a --- /dev/null +++ b/HDOJ/4292_autoAC.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +using namespace std; +#define MAXN 1111 +#define MAXM 88888888 +struct Edge{ + int v,cap,next; +}edge[MAXM]; +int head[MAXN]; +int pre[MAXN]; +int cur[MAXN]; +int level[MAXN]; +int gap[MAXN]; +int NE,NV,vs,vt,n,f,d; +int Food[MAXN]; +int Drink[MAXN]; +void Insert(int u,int v,int cap,int cc=0){ + edge[NE].v=v;edge[NE].cap=cap; + edge[NE].next=head[u];head[u]=NE++; + edge[NE].v=u;edge[NE].cap=cc; + edge[NE].next=head[v];head[v]=NE++; +} +int SAP(int vs,int vt){ + memset(pre,-1,sizeof(pre)); + memset(level,0,sizeof(level)); + memset(gap,0,sizeof(gap)); + for(int i=0;ilevel[v]){ + cur[u]=i; + minlevel=level[v]; + } + } + gap[level[u]]--; + if(gap[level[u]]==0)break; + level[u]=minlevel+1; + gap[level[u]]++; + u=pre[u]; + } + return maxflow; +} +int main(){ + char str[MAXN]; + while(~scanf("%d%d%d",&n,&f,&d)){ + vs=0,vt=f+2*n+d+1,NV=vt+1,NE=0; + memset(head,-1,sizeof(head)); + for(int i=1;i<=f;i++){ + scanf("%d",&Food[i]); + Insert(vs,i,Food[i]); + } + for(int i=1;i<=d;i++){ + scanf("%d",&Drink[i]); + Insert(i+2*n+f,vt,Drink[i]); + } + for(int i=1;i<=n;i++){ + Insert(i+f,i+f+n,1); + } + for(int i=1;i<=n;i++){ + scanf("%s",str+1); + for(int j=1;j<=f;j++){ + if(str[j]=='Y'){ + Insert(j,i+f,1); + } + } + } + for(int i=1;i<=n;i++){ + scanf("%s",str+1); + for(int j=1;j<=d;j++){ + if(str[j]=='Y'){ + Insert(i+f+n,f+2*n+j,1); + } + } + } + printf("%d\n",SAP(vs,vt)); + } + return 0; +} diff --git a/HDOJ/4293_autoAC.cpp b/HDOJ/4293_autoAC.cpp new file mode 100644 index 0000000..9dfb912 --- /dev/null +++ b/HDOJ/4293_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +using namespace std; +int dp[510][510]; +int tt[510][510], an[510]; +int main() +{ + int i, j, k; + int n, a, b; + while(scanf("%d", &n) != EOF) + { + memset(dp, 0, sizeof(dp)); + memset(an, 0, sizeof(an)); + memset(tt, 0, sizeof(tt)); + for(i = 0; i < n; ++i) { + scanf("%d %d", &a, &b); + if(a+b < n && tt[a][n-b] < (n-a-b)) + tt[a][n-b]++; + } + for(i = 1; i <= n; ++i) + for(j = 0; j < i; ++j) { + dp[j][i] = an[j]+tt[j][i]; + an[i] = max(an[i], dp[j][i]); + } + printf("%d\n", an[n]); + } + return 0; +} diff --git a/HDOJ/4294_autoAC.cpp b/HDOJ/4294_autoAC.cpp new file mode 100644 index 0000000..68916c9 --- /dev/null +++ b/HDOJ/4294_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +using namespace std; +#define N 1000020 +int n, k, num[2], m, ans, sl, ssl; +int ss[N], s[N]; +bool v[10002]; +struct node { + int pre, val, mod; +} q[N]; +void bfs() { + memset(v, false, sizeof(v)); + int l = 1, r = 1; + for (int i=0; i ssl) return 1; + for (int i=0; i +#include +#include +using namespace std; +const int N=4100; +char s[N],ss[70]; +short l,sl[4],maxl; +short flag[N],d1[N][16][65],d2[N][16][65]; +int main() +{ + int i,j,k,x; + while(~scanf("%s",s)) + { + l=strlen(s); + memset(flag,0,sizeof(flag[0])*l); + for(i=0;i<4;i++) + { + scanf("%s",ss); + sl[i]=strlen(ss); + for(j=0;j+sl[i]<=l;j++) + { + for(k=0;ss[k];k++)if(s[j+k]!=ss[k])break; + if(ss[k]=='\0') flag[j]|=1<maxl) maxl=sl[i]; + } + memset(d1,0x3f,sizeof(d1[0])*(l+1)); + memset(d2,0xc3,sizeof(d1[0])*(l+1)); + d1[0][0][0]=d2[0][0][0]=0; + for(i=0;i +#define ll __int64 +int main() +{ + int n,w,s; + while(~scanf("%d",&n)) + { + ll max=0,ans=0,sum=0; + while(n--) + { + scanf("%d%d",&w,&s); + if(w+s>max) max=w+s; + sum+=w; + } + sum-=max; + if(sum>ans) ans=sum; + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/4297_autoAC.cpp b/HDOJ/4297_autoAC.cpp new file mode 100644 index 0000000..0a42c4d --- /dev/null +++ b/HDOJ/4297_autoAC.cpp @@ -0,0 +1,199 @@ +#pragma comment(linker, "/STACK:16777216") +#include +#include +#include +#include +#include +using namespace std; +const int maxn = 1000010; +struct node { + int be, ne, weight; + void init(int b, int e, int v) { + be = b; + ne = e; + weight = v; + } +}; +int rmq[maxn * 2]; +struct RMQ { + int lg[maxn + 1], minn[20][maxn + 1], n; + RMQ() { + lg[0] = -1; + for (int i = 1; i <= maxn; i++) { + lg[i] = ((i & (i - 1)) == 0) ? lg[i - 1] + 1 : lg[i - 1]; + minn[0][i] = i; + } + } + void init(int n) { + this->n = n; + for (int i = 1; i <= lg[n]; i++) + for (int j = 1; j <= n + 1 - (1 << i); j++) { + int a = minn[i - 1][j]; + int b = minn[i - 1][j + (1 << (i - 1))]; + minn[i][j] = rmq[a] < rmq[b] ? a : b; + } + } + int getmin(int s, int t) { + if (s > t) { + int temp = t; + t = s; + s = temp; + } + int k = lg[t - s + 1]; + int a = minn[k][s]; + int b = minn[k][t - (1 << k) + 1]; + if (rmq[a] < rmq[b]) + return a; + else + return b; + } +} st; +int root[maxn]; +struct LCA { + int n, len, E[maxn]; + node buf[maxn * 2]; + int F[maxn * 2], pos[maxn], cnt; + int dis[maxn]; + void init(int n) { + this->n = n; + len = 0; + memset(E, -1, sizeof(E)); + } + void addedge(int a, int b, int w) { + buf[len].init(b, E[a], w); + E[a] = len++; + buf[len].init(a, E[b], w); + E[b] = len++; + } + int query(int a, int b) { + int k = st.getmin(pos[a], pos[b]); + return F[k]; + } + void dfs(int a, int lev) { + F[++cnt] = a; + rmq[cnt] = lev; + pos[a] = cnt; + for (int i = E[a]; i != -1; i = buf[i].ne) { + int b = buf[i].be; + if (pos[b] != -1) + continue; + dis[b] = dis[a] + buf[i].weight; + dfs(b, lev + 1); + F[++cnt] = a; + rmq[cnt] = lev; + } + } + void dfs2(int a, int r) { + root[a] = r; + for (int i = E[a]; i != -1; i = buf[i].ne) + if (root[buf[i].be] == -1) + dfs2(buf[i].be, r); + } + void solve(int root) { + cnt = 0; + memset(pos, -1, sizeof(pos)); + memset(dis, 0, sizeof(dis)); + dfs(root, 0); + st.init(2*n-1); + } +} lca; +int nxt[maxn],n; +int cc[maxn],pos[maxn],len[maxn],num; +int f[maxn]; +int find(int x) { + if (x != f[x]) + f[x] = find(f[x]); + return f[x]; +} +void circle() { + for (int i = 1; i <= n; i++) + f[i] = i; + num = 0; + memset(cc, -1, sizeof(cc)); + memset(pos, -1, sizeof(pos)); + for (int i = 1; i <= n; i++) { + int a = find(i); + int b = find(nxt[i]); + if (a == b) + cc[i]=++num; + f[a] = b; + } + for (int i = 1; i <= n; i++) + if (cc[i] != -1) { + int k = nxt[i]; + int cnt = 0; + pos[i] = ++cnt; + root[i] = i; + while (k != i) { + pos[k] =++cnt; + root[k]=k; + cc[k]=cc[i]; + k=nxt[k]; + } + len[cc[i]] = cnt; + } +} +int main() { + int m; + while (scanf("%d %d", &n, &m) != EOF) { + lca.init(n + 1); + memset(root, -1, sizeof(root)); + for (int i = 1; i <= n; i++) + scanf("%d", nxt + i); + circle(); + for (int i = 1; i <= n; i++) + if (root[i]!=i) + lca.addedge(nxt[i], i, 1); + for (int i = 1; i <= n; i++){ + if (root[i] == i){ + lca.dfs2(i,i); + lca.addedge(0, i, 0); + } + } + lca.solve(0); + int a, b; + while (m-- > 0) { + scanf("%d %d", &a, &b); + int p = lca.query(a, b); + if (p != 0) + printf("%d %d\n", (lca.dis[a] - lca.dis[p]), (lca.dis[b]-lca.dis[p])); + else { + int ra = root[a], rb = root[b]; + if (cc[ra] != cc[rb]) + printf("-1 -1\n"); + else { + int cnt=len[cc[ra]]; + int temp1 = lca.dis[a]; + int temp2 = lca.dis[b]; + if (pos[ra] < pos[rb]) + temp1 += pos[rb] - pos[ra]; + else + temp1 += (cnt - pos[ra] + pos[rb]); + int temp3 = lca.dis[a]; + int temp4 = lca.dis[b]; + if (pos[rb] max(temp3, temp4)) + printf("%d %d\n", temp3, temp4); + if (max(temp1, temp2) == max(temp3, temp4)) { + if (min(temp1, temp2) < min(temp3, temp4)) + printf("%d %d\n", temp1, temp2); + if (min(temp1, temp2) > min(temp3, temp4)) + printf("%d %d\n", temp3, temp4); + if (min(temp1,temp2)==min(temp3, temp4)) { + if (temp1>=temp2) + printf("%d %d\n",temp1,temp2); + else + printf("%d %d\n",temp3,temp4); + } + } + } + } + } + } + return 0; +}