diff --git a/HDOJ/1800_autoAC.cpp b/HDOJ/1800_autoAC.cpp new file mode 100644 index 0000000..f08cf5d --- /dev/null +++ b/HDOJ/1800_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#define mem(a) memset(a, 0, sizeof(a)) +using namespace std; +int n,f[3000+5]; +int main() +{ + while(~scanf("%d",&n)) + { + int i; + for(i=0;if[i-1])count=1; + else { count++; max = max>count? max:count;} + } + printf("%d\n",max); + } + return 0; +} diff --git a/HDOJ/1801_autoAC.cpp b/HDOJ/1801_autoAC.cpp new file mode 100644 index 0000000..0d24d4b --- /dev/null +++ b/HDOJ/1801_autoAC.cpp @@ -0,0 +1,69 @@ +#include +#include +using namespace std; +const int maxn=110; +int map[maxn][maxn],color[maxn][maxn]; +char s[maxn][maxn]; +int n,m,r,c,ans; +void change() +{ + int i,j,k,p; + for(i=0;i +#include +int main() +{ + int n,m,c; + while(scanf("%d%d%d",&n,&m,&c),(m+n+c)) + { + int p,q; + p=n-7; + q=m-7; + if((p*q)&1) + printf("%d\n",(p*q)/2+c); + else + printf("%d\n",(p*q)/2); + } + return 0; +} diff --git a/HDOJ/1803_autoAC.cpp b/HDOJ/1803_autoAC.cpp new file mode 100644 index 0000000..6cdc52a --- /dev/null +++ b/HDOJ/1803_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +double pi=3.1415926535897932; +using namespace std; +double MIN(double x,double y) +{ + if(x-y>0) return y; + else return x; +} +int main() +{ + double x,y; + while(scanf("%lf%lf",&x,&y)!=EOF) + { + if(x<1&&y<1) break; + double x1=x*x*(y-x/pi)/(4*pi); + double temp=MIN(y/(pi+1),x); + double y1=pi*temp*temp*x/4; + if(x1-y1>0) printf("%.3f\n",x1); + else printf("%.3lf\n",y1); + } + return 0; +} diff --git a/HDOJ/1804_autoAC.cpp b/HDOJ/1804_autoAC.cpp new file mode 100644 index 0000000..9d845ec --- /dev/null +++ b/HDOJ/1804_autoAC.cpp @@ -0,0 +1,72 @@ +#include +#include +#define MAX 100+10 +int fun2(char *str); +int fun1(char *str); +int main() +{ + int n1,n2; + char str1[MAX][MAX],str2[MAX][MAX],str3[MAX][MAX]; + while(scanf("%d %d",&n1,&n2)>0) + { + memset(str3,'\0',sizeof(str3)); + for(int i=0;i +#include +#include +#include +using namespace std; +class node +{ +public: + node* left; + node* right; + char c; + node() + { + left = right = NULL; + } + ~node() + { + if(left) + delete left; + if(right) + delete right; + } +}; +void print(node* s) +{ + char output[10001]; + char* o = output + 10000; + *o = 0; + queue q; + q.push(s); + while(!q.empty()) + { + node* temp = q.front(); + q.pop(); + o--; + *o = temp->c; + if(temp->left) q.push(temp->left); + if(temp->right) q.push(temp->right); + } + puts(o); +} +int main() +{ + int n; + scanf("%d",&n); + while(n--) + { + char input[10001]; + scanf("%s",input); + int len = strlen(input); + stack s; + node* temp; + for(int i=0;i='a') + { + temp = new node; + temp->c = input[i]; + s.push(temp); + } + else + { + node *left, *right; + right = s.top(); + s.pop(); + left = s.top(); + s.pop(); + temp = new node; + temp->c = input[i]; + temp->left = left; + temp->right = right; + s.push(temp); + } + } + print(s.top()); + delete s.top(); + s.pop(); + } +} diff --git a/HDOJ/1806_autoAC.cpp b/HDOJ/1806_autoAC.cpp new file mode 100644 index 0000000..9c16ee4 --- /dev/null +++ b/HDOJ/1806_autoAC.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +using namespace std; +const int MAXN=100010; +int a[MAXN]; +int b[MAXN]; +int dp[MAXN][20]; +void makeRMQ(int n,int b[]) +{ + for(int i=0;i>1); + if(a[mid]>=tmp)r=mid; + else l=mid+1; + } + return r; +} +int main() +{ + int n,q; + int s,t; + while(scanf("%d",&n),n) + { + scanf("%d",&q); + for(int i=0;i=0;i--) + { + if(i==n-1)tmp=1; + else + { + if(a[i]==a[i+1])tmp++; + else tmp=1; + } + b[i]=tmp; + } + makeRMQ(n,b); + while(q--) + { + scanf("%d%d",&s,&t); + s--; + t--; + int temp=bi_search(s,t); + int ans=t-temp+1; + t=temp-1; + if(s>t)printf("%d\n",ans); + else printf("%d\n",max(ans,rmq(s,t))); + } + } + return 0; +} diff --git a/HDOJ/1808_autoAC.cpp b/HDOJ/1808_autoAC.cpp new file mode 100644 index 0000000..62ccbc4 --- /dev/null +++ b/HDOJ/1808_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#include +int yushu[100010],d[100010]; +int main() +{ + int m,i,j,ans,c,n,sum; + while(scanf("%d%d",&c,&n)!=EOF) + { + if(c==0&&n==0) + break; + memset(yushu,0,sizeof(yushu)); + for(i=1;i<=n;i++) + scanf("%d",&d[i]); + int st,ed; + sum=0; + for(i=1;i<=n;i++) + { + sum=(sum+d[i])%c; + if(sum==0) + { + st=1; + ed=i; + break; + } + else if(yushu[sum]) + { + st=yushu[sum]+1; + ed=i; + break; + } + else + yushu[sum]=i; + } + for(i=st;i<=ed;i++) + printf(i==ed?"%d\n":"%d ",i); + } + return 0; +} diff --git a/HDOJ/1809_autoAC.cpp b/HDOJ/1809_autoAC.cpp new file mode 100644 index 0000000..b2301fe --- /dev/null +++ b/HDOJ/1809_autoAC.cpp @@ -0,0 +1,98 @@ +#include +#include +#define HASH 10007 +#define MAXD 10010 +#define MAXN 55 +typedef long long LL; +int S, N, M, sg[MAXD], g[MAXN][MAXN]; +struct HashMap +{ + int head[HASH], size, next[MAXD]; + LL st[MAXD]; + void init() + { + memset(head, -1, sizeof(head)), size = 0; + } + int find(LL _st) + { + int i, h = _st % HASH; + for(i = head[h]; i != -1; i = next[i]) + if(st[i] == _st) break; + return i; + } + void push(LL _st) + { + int h = _st % HASH; + st[size] = _st, sg[size] = -1; + next[size] = head[h], head[h] = size ++; + } +}hm; +LL encode(int code[][MAXN]) +{ + int i, j; + LL ans = 0; + for(i = 0; i < N; i ++) + for(j = 0; j < M; j ++) ans = ans << 1 | code[i][j]; + return ans; +} +void decode(int code[][MAXN], LL st) +{ + int i, j; + for(i = N - 1; i >= 0; i --) + for(j = M - 1; j >= 0; j --) code[i][j] = st & 1, st >>= 1; +} +void init() +{ + char b[MAXN]; + int i, j; + scanf("%d%d", &N, &M); + for(i = 0; i < N; i ++) + { + scanf("%s", b); + for(j = 0; j < M; j ++) g[i][j] = b[j] - '0'; + } +} +int dfs(int cur, LL st) +{ + int i, j, k, g[MAXN][MAXN], h[MAXN]; + decode(g, st); + memset(h, 0, sizeof(h)); + for(i = 0; i < N - 1; i ++) + for(j = 0; j < M - 1; j ++) + if(!g[i][j] && !g[i + 1][j] && !g[i][j + 1] && !g[i + 1][j + 1]) + { + g[i][j] = g[i + 1][j] = g[i][j + 1] = g[i + 1][j + 1] = 1; + LL c = encode(g); + k = hm.find(c); + if(k != -1) h[sg[k]] = 1; + else + { + hm.push(c), k = hm.find(c); + h[dfs(k, c)] = 1; + } + g[i][j] = g[i + 1][j] = g[i][j + 1] = g[i + 1][j + 1] = 0; + } + for(i = 0; h[i]; i ++); + return sg[cur] = i; +} +void solve() +{ + int i, j, k, ans = 0, t; + for(t = 0; t < S; t ++) + { + init(), hm.init(); + LL c = encode(g); + hm.push(c), k = hm.find(c); + dfs(k, c); + ans ^= sg[k]; + } + printf("%s\n", ans ? "Yes" : "No"); +} +int main() +{ + while(scanf("%d", &S) == 1) + { + solve(); + } + return 0; +} diff --git a/HDOJ/1811_autoAC.cpp b/HDOJ/1811_autoAC.cpp new file mode 100644 index 0000000..7ec51d0 --- /dev/null +++ b/HDOJ/1811_autoAC.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +int n,m; +struct node +{ + int x; + int y; + char l; +}a[20005]; +int c[10005]; +int in[10005]; +vector ch[10005]; +queue q; +void init() +{ + int i; + for(i=0;i'&&!flag){ + ch[xx].push_back(yy); + in[yy]++; + } + else if(a[i].l == '<'&&!flag){ + ch[yy].push_back(xx); + in[xx]++; + } + } + for(i=0;i1) + flag=2; + int t = q.front(); + q.pop(); + for(i=0;i +#include +#include +#include +#include +#include +#include +using namespace std; +int n,c[1005]; +long long ans[405],tot[405],g[405]; +void chenggao(long long a[],long long b[]) +{ int i,j; + memset(g,0,sizeof(g)); + g[0]=a[0]+b[0]; + for(i=1;i<=a[0];i++) + for(j=1;j<=b[0];j++) + g[i+j-1]+=a[i]*b[j]; + for(i=1;i<=g[0];i++) + { g[i+1]+=g[i]/10000; + g[i]=g[i]%10000; + } + while(g[g[0]]==0&&g[0]>0)g[0]--; + for(i=0;i<=g[0];i++) + a[i]=g[i]; +} +void jia(long long a[],long long b[]) +{ int i; + a[0]=max(a[0],b[0]); + for(i=1;i<=a[0];i++) + a[i]=a[i]+b[i]; + for(i=1;i<=a[0];i++) + { a[i+1]+=a[i]/10000; + a[i]=a[i]%10000; + } + while(a[a[0]+1]!=0) + { a[0]++; + a[a[0]+1]=a[a[0]]/10000; + a[a[0]]=a[a[0]]%10000; + } +} +void chudan(long long a[],int x) +{ long long d=0; + int i; + for(i=a[0];i>=1;i--) + { d=d*10000+a[i]; + a[i]=d/x; + d=d%x; + } + while(a[a[0]]==0&&a[0]>0)a[0]--; +} +void chengdan(long long a[],int x) +{ int i; + for(i=1;i<=a[0];i++) + a[i]=a[i]*x; + for(i=1;i<=a[0];i++) + { a[i+1]+=a[i]/10000; + a[i]=a[i]%10000; + } + while(a[a[0]+1]!=0) + { a[0]++; + a[a[0]+1]=a[a[0]]/10000; + a[a[0]]=a[a[0]]%10000; + } +} +void print(long long a[]) +{ int i; + printf("%lld",a[a[0]]); + for(i=a[0]-1;i>=1;i--) + { printf("%lld",a[i]/1000); + printf("%lld",a[i]/100%10); + printf("%lld",a[i]/10%10); + printf("%lld",a[i]%10); + } + printf("\n"); +} +void Mulpow(int x,int tmp) +{ int i; + memset(tot,0,sizeof(tot)); + c[0]=0; + while(tmp>0) + { c[0]++; + c[c[0]]=tmp%2; + tmp=tmp/2; + } + tot[0]=1; + tot[1]=x; + for(i=c[0]-1;i>=1;i--) + { chenggao(tot,tot); + if(c[i]==1) + chengdan(tot,x); + } +} +int main() +{ + int p,x,y,i,tmp,N; + while(scanf("%d%d",&n,&p)!=EOF) + { N=n*n; + memset(ans,0,sizeof(ans)); + if(n==1) + { printf("%d\n",p); + continue; + } + if(n%2==0) + { Mulpow(p,N);//0 + jia(ans,tot); + Mulpow(p,N/4);//90 + jia(ans,tot); + Mulpow(p,N/2);//180 + jia(ans,tot); + Mulpow(p,N/4);//270 + jia(ans,tot); + Mulpow(p,N/2); + jia(ans,tot); + Mulpow(p,N/2); + jia(ans,tot); + Mulpow(p,n+(N-n)/2); + jia(ans,tot); + Mulpow(p,n+(N-n)/2); + jia(ans,tot); + y=8; + } + else + { Mulpow(p,N);//0 + jia(ans,tot); + Mulpow(p,1+(N-1)/4);//90 + jia(ans,tot); + Mulpow(p,1+(N-1)/2);//180 + jia(ans,tot); + Mulpow(p,1+(N-1)/4);//270 + jia(ans,tot); + Mulpow(p,n+(N-n)/2); + jia(ans,tot); + Mulpow(p,n+(N-n)/2); + jia(ans,tot); + Mulpow(p,n+(N-n)/2); + jia(ans,tot); + Mulpow(p,n+(N-n)/2); + jia(ans,tot); + y=8; + } + chudan(ans,y); + print(ans); + } + return 0; +} diff --git a/HDOJ/1813_autoAC.cpp b/HDOJ/1813_autoAC.cpp new file mode 100644 index 0000000..246c162 --- /dev/null +++ b/HDOJ/1813_autoAC.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +using namespace std; +const int inf = 1000000000; +struct node +{ + int x,y; +}; +char str[4][10] = {"east","north","south","west"}; +char map[9][9]; +int to[4][2] = {0,1,-1,0,1,0,0,-1}; +int L,n,dis[9][9],step,path[1000]; +queue Q; +int onedge(int i,int j) +{ + return i==0 || j == 0 || i == n-1 || j == n-1; +} +int ismap(int i,int j) +{ + return i>=0 && i=0 && jdis[a.x][a.y]+1) + { + dis[next.x][next.y]=dis[a.x][a.y]+1; + Q.push(next); + } + } + } +} +void init() +{ + int i,j,k; + node a; + while(!Q.empty()) Q.pop(); + for(i = 0; istep) return 0; + if(cnt == step) return 1; + int i,x,y,tx,ty; + char tem[9][9]; + for(i = 0; i<4; i++) + { + memset(tem,0,sizeof(tem)); + for(x = 0; x +#include +#include +#include +using namespace std; +const int MAXN=16010; +const int MAXM=100000; +struct Node +{ + int a,b,pre,next; +}E[MAXM],E2[MAXM]; +int _n,n,m; +int V[MAXN],ST[MAXN][2],Q[MAXN],Q2[MAXN],vst[MAXN]; +bool res_ex; +void init_d() +{ + for(int i=0;i +#include +#include +#include +#include +using namespace std; +#define MAXN 1111 +struct Edge{ + int v,Next; +}edge[MAXN*MAXN*11]; +int N,A,B,NE; +int head[MAXN]; +void Insert(int u,int v) +{ + edge[NE].v=v; + edge[NE].Next=head[u]; + head[u]=NE++; +} +int cnt,_count; +int low[MAXN],dfn[MAXN]; +int color[MAXN]; +bool mark[MAXN]; +stackS; +void Tarjan(int u) +{ + low[u]=dfn[u]=++cnt; + mark[u]=true; + S.push(u); + for(int i=head[u];i!=-1;i=edge[i].Next){ + int v=edge[i].v; + if(dfn[v]==0){ + Tarjan(v); + low[u]=min(low[u],low[v]); + }else if(mark[v]){ + low[u]=min(low[u],dfn[v]); + } + } + if(low[u]==dfn[u]){ + int v; + _count++; + do{ + v=S.top(); + S.pop(); + mark[v]=false; + color[v]=_count; + }while(u!=v); + } +} +struct Point{ + int x,y; +}pp[MAXN],hate[MAXN],like[MAXN],s1,s2; +int dist[MAXN][MAXN]; +inline int Get_dist(Point p,Point q) +{ + return abs(p.x-q.x)+abs(p.y-q.y); +} +void Build(int limit) +{ + NE=0; + memset(head,-1,(2*N+4)*sizeof(int)); + for(int i=1;i<=A;i++){ + Insert(hate[i].x,hate[i].y+N); + Insert(hate[i].y,hate[i].x+N); + Insert(hate[i].x+N,hate[i].y); + Insert(hate[i].y+N,hate[i].x); + } + for(int i=1;i<=B;i++){ + Insert(like[i].x,like[i].y); + Insert(like[i].y+N,like[i].x+N); + Insert(like[i].x+N,like[i].y+N); + Insert(like[i].y,like[i].x); + } + for(int i=1;i<=N;i++){ + for(int j=i+1;j<=N;j++){ + if(dist[i][N+1]+dist[j][N+1]>limit){ + Insert(i,j+N); + Insert(j,i+N); + } + if(dist[i][N+2]+dist[j][N+2]>limit){ + Insert(i+N,j); + Insert(j+N,i); + } + if(dist[i][N+1]+dist[N+1][N+2]+dist[j][N+2]>limit){ + Insert(i,j); + Insert(j+N,i+N); + } + if(dist[i][N+2]+dist[N+1][N+2]+dist[j][N+1]>limit){ + Insert(i+N,j+N); + Insert(j,i); + } + } + } +} +bool Judge() +{ + cnt=_count=0; + memset(mark,false,(2*N+4)*sizeof(bool)); + memset(dfn,0,(2*N+4)*sizeof(int)); + for(int i=1;i<=2*N;i++)if(dfn[i]==0)Tarjan(i); + for(int i=1;i<=N;i++){ + if(color[i]==color[i+N])return false; + } + return true; +} +int main() +{ + while(~scanf("%d%d%d",&N,&A,&B)){ + scanf("%d%d%d%d",&s1.x,&s1.y,&s2.x,&s2.y); + dist[N+1][N+2]=Get_dist(s1,s2); + for(int i=1;i<=N;i++){ + scanf("%d%d",&pp[i].x,&pp[i].y); + dist[i][N+1]=Get_dist(pp[i],s1); + dist[i][N+2]=Get_dist(pp[i],s2); + } + for(int i=1;i<=A;i++){ + scanf("%d%d",&hate[i].x,&hate[i].y); + } + for(int i=1;i<=B;i++){ + scanf("%d%d",&like[i].x,&like[i].y); + } + int low=0,high=44444444,mid,ans=-1; + while(low<=high){ + mid=(low+high)>>1; + Build(mid); + if(Judge()){ + ans=mid; + high=mid-1; + }else + low=mid+1; + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1816_autoAC.cpp b/HDOJ/1816_autoAC.cpp new file mode 100644 index 0000000..40491cf --- /dev/null +++ b/HDOJ/1816_autoAC.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +using namespace std; +const int maxn=2000+50; +int n,m; +int a[maxn],b[maxn]; +int c[maxn],d[maxn]; +struct TwoSAT +{ + int n; + vector G[maxn*2]; + int S[maxn*2],c; + bool mark[maxn*2]; + bool dfs(int x) + { + if(mark[x^1]) return false; + if(mark[x]) return true; + mark[x]=true; + S[c++]=x; + for(int i=0;in=n; + for(int i=0;i<2*n;i++) G[i].clear(); + memset(mark,0,sizeof(mark)); + } + void add_clause(int x,int xval,int y,int yval) + { + x=x*2+xval; + y=y*2+yval; + G[x].push_back(y); + } + bool solve() + { + for(int i=0;i<2*n;i+=2) + if(!mark[i] && !mark[i+1]) + { + c=0; + if(!dfs(i)) + { + while(c>0) mark[S[--c]]=false; + if(!dfs(i+1)) return false; + } + } + return true; + } +}TS; +bool ok(int mid) +{ + TS.init(n); + for(int i=0;iL) + { + int mid = L+(R-L+1)/2; + if(ok(mid)) L=mid; + else R=mid-1; + } + printf("%d\n",L); + } + return 0; +} diff --git a/HDOJ/1817_autoAC.cpp b/HDOJ/1817_autoAC.cpp new file mode 100644 index 0000000..b2f03d4 --- /dev/null +++ b/HDOJ/1817_autoAC.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; +int gcd(int a,int b) +{ + return b==0?a:gcd(b,a%b); +} +__int64 pow(int a,int b) +{ + __int64 s=1; + for(int i=0;i>n) + { + ans=0; + if(n>=40)continue; + if(n<0)break; + if(n==0){ printf("0\n");continue; } + for(i=1;i<=n;i++) + ans+=pow(3,gcd(n,i)); + if(n%2) + { + ans+=( pow(3,(n+1)/2) *n); + } + else + { + ans+=( pow(3,n/2+1) * n/2); + ans+=( pow(3,n/2) *n/2 ); + } + ans/=(2*n); + printf("%I64d\n",ans); + } + return 0; +} diff --git a/HDOJ/1818_autoAC.cpp b/HDOJ/1818_autoAC.cpp new file mode 100644 index 0000000..12a81c7 --- /dev/null +++ b/HDOJ/1818_autoAC.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +using namespace std; +int n,m; +int v[1100005]; +struct node +{ + int yes; + int no; + int kill; + int add; + int time; +}tr[105]; +struct node1 +{ + int bug; + int step; + bool operator < (const node1 &a)const + { + return step > a.step; + } +}; +priority_queue Q; +bool ok(int bug,node t) +{ + if((t.no&bug)!=0)return false; + if((t.yes&bug)!=t.yes)return false; + return true; +} +int fix(int bug,node t) +{ + int tmp=bug; + bug=((~t.kill)&bug); + bug=(t.add|bug); + if(tmp==bug)return -1; + return bug; +} +void bfs() +{ + node1 w,e; + while(!Q.empty()) + { + w=Q.top(); + Q.pop(); + if(w.bug==0){printf("Fastest sequence takes %d seconds.\n",w.step);return;} + //cout<<"----"<= v[e.bug])continue; + v[e.bug] = e.step; + Q.push(e); + } + } + } + printf("Bugs cannot be fixed.\n"); +} +int main() +{ + char a[200],b[200]; + node1 w; + int CASE=1; + while(scanf("%d%d",&n,&m)!=EOF && n && m) + { + int g = 0; + g = (1 < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +long long bishops(int n, int k) +{ + long long r1[9]; + long long r2[9]; + for (int i = 1; i <= n; ++i) + r1[i] = i % 2 != 0 ? i : r1[i-1]; + for (int i = 1; i <= n-1; ++i) + r2[i] = i % 2 != 0 ? i+1 : r2[i-1]; + long long c1[9][65] = {{0}}; + long long c2[9][65] = {{0}}; + for (int i = 0; i <= n; ++i) + c1[i][0] = 1; + for (int j = 1; j <= k; ++j) + c1[0][j] = 0; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= k && j <= i; ++j) + c1[i][j] = c1[i-1][j] + c1[i-1][j-1]*(r1[i] - j + 1); + for (int i = 0; i <= n-1; ++i) + c2[i][0] = 1; + for (int j = 1; j <= k; ++j) + c2[0][j] = 0; + for (int i = 1; i <= n-1; ++i) + for (int j = 1; j <= k && j <= i; ++j) + c2[i][j] = c2[i-1][j] + c2[i-1][j-1]*(r2[i] - j + 1); + long long r = 0; + for (int i = 0; i <= k; ++i) + r += c1[n][i] * c2[n-1][k-i]; + return r; +} +int main(int argc, char *argv[]) +{ + for (int n, k; cin >> n >> k && !(n == 0 && k == 0); ) + cout << bishops(n, k) << endl; + return 0; +} diff --git a/HDOJ/1822_autoAC.cpp b/HDOJ/1822_autoAC.cpp new file mode 100644 index 0000000..b70d1fa --- /dev/null +++ b/HDOJ/1822_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int map1[5000][5000],map2[5000][5000]; +int m,n; +bool check(int x ,int y) +{ + int i ,j,maxx = map2[y][x]; + for(i = 1; i <=n; i++) + if(map2[i][x] > maxx) return false; + return true; +} +int main() +{ + int T,i,j; + scanf("%d",&T); + while(T--) + { + scanf("%d%d",&m,&n); + for(i = 1; i <= m; i++) + for(j = 1; j <= n; j++) + scanf("%d",&map1[i][j]);//cin>>map1[i][j]; + for(i = 1; i <= n; i++) + for(j = 1; j <= m; j++) + scanf("%d",&map2[i][j]);//cin>>map2[i][j]; + int ans = 0,max1 = 0,max2 = 0; + for(i = 1; i <= n; i++) + { + int maxx = map1[1][i]; + for(j = 2; j <= m; j++) + if(map1[j][i] > maxx) maxx = map1[j][i]; + for(j = 1; j <= m; j++) + { + if(map1[j][i] == maxx) + { + if(check(j,i)) + { + ans++; + max1 = map1[j][i]; + max2 = map2[i][j]; + } + } + } + } + if(ans == 1) printf("%d %d\n",max1,max2);//cout< +#include +#include +#include +using namespace std; +#define lson l,m,rt<<1 +#define rson m+1,r,rt<<1|1 +const double eps=1e-6; +const int maxn=2100; +int xL,xR,yL,yR,Value; +int Max[220<<2][maxn<<2]; +int N,M; +int maxv; +void pushup(int xrt,int rt) +{ + Max[xrt][rt]=max(Max[xrt][rt<<1],Max[xrt][rt<<1|1]); +} +void updateY(int xrt,int x,int l,int r,int rt) +{ + if(l==r) + { + if(x==-1) + { + Max[xrt][rt]=max(Max[xrt<<1][rt],Max[xrt<<1|1][rt]); + } + else + { + Max[xrt][rt]=max(Max[xrt][rt],Value); + } + return ; + } + int m=(l+r)/2; + if(yL<=m) updateY(xrt,x,lson); + else updateY(xrt,x,rson); + pushup(xrt,rt); +} +void updateX(int l,int r,int rt) +{ + if(l==r) + { + updateY(rt,l,1,M,1); + return ; + } + int m=(l+r)/2; + if(xL<=m) updateX(lson); + else updateX(rson); + updateY(rt,-1,1,M,1); +} +void queryY(int xrt,int l,int r,int rt) +{ + if(yL<=l&&r<=yR) + { + maxv=max(maxv,Max[xrt][rt]); + return ; + } + int m=(l+r)/2; + if(yL<=m) queryY(xrt,lson); + if(yR>m) queryY(xrt,rson); +} +void queryX(int l,int r,int rt) +{ + if(xL<=l&&r<=xR) + { + queryY(rt,1,M,1); + return ; + } + int m=(l+r)/2; + if(xL<=m) queryX(lson); + if(xR>m) queryX(rson); +} +int main() +{ + int op;char cmd[20]; + N=200;M=2100; + while(scanf("%d",&op)!=EOF&&op) + { + memset(Max,-1,sizeof(Max)); + while(op--) + { + scanf("%s",cmd); + if(cmd[0]=='I') + { + int H; + double a,l; + scanf("%d%lf%lf",&H,&a,&l); + H-=99; + int A=(int)((a+eps)*10); + int L=(int)((l+eps)*10); + xL=H;yL=A;Value=L; + updateX(1,N,1); + } + else if(cmd[0]=='Q') + { + int H1,H2; + double a1,a2; + scanf("%d%d%lf%lf",&H1,&H2,&a1,&a2); + int A1=(int)((a1+eps)*10); + int A2=(int)((a2+eps)*10); + xL=min(H1,H2)-99,xR=max(H1,H2)-99; + yL=min(A1,A2),yR=max(A1,A2); + maxv=-(1<<30); + queryX(1,N,1); + if(maxv==-1) printf("-1\n"); + else printf("%.1lf\n",maxv/10.); + } + } + } + return 0; +} diff --git a/HDOJ/1824_autoAC.cpp b/HDOJ/1824_autoAC.cpp new file mode 100644 index 0000000..3d6e321 --- /dev/null +++ b/HDOJ/1824_autoAC.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include +using namespace std; +const int MAX_N = 2 * 5000 + 10; +struct TwoSAT { + int n; + vector G[2 * MAX_N]; + bool mark[2 * MAX_N]; + int S[2 * MAX_N], c; + void Init(int n) + { + this->n = n; + for (int i = 0; i <= 2 * n; ++i) + G[i].clear(); + memset(mark, 0, sizeof(mark)); + } + bool Dfs(int x) + { + if (mark[x ^ 1]) return false; + if (mark[x]) return true; + mark[x] = true; + S[c++] = x; + for (int i = 0; i < G[x].size(); ++i) + { + if (!Dfs(G[x][i])) + return false; + } + return true; + } + void AddClause(int x, int y) + { + int a = 2 * x; + int b = 2 * y; + G[a ^ 1].push_back(b); + G[b ^ 1].push_back(a); + } + void AddClauseTeam(int i, int j, int k) + { + int a = 2 * i; + int b = 2 * j; + int c = 2 * k; + G[a].push_back(b ^ 1); + G[a].push_back(c ^ 1); + G[b].push_back(a ^ 1); + G[b].push_back(c); + G[c].push_back(a ^ 1); + G[c].push_back(b); + G[a ^ 1].push_back(b); + G[a ^ 1].push_back(c); + G[b ^ 1].push_back(a); + G[b ^ 1].push_back(c ^ 1); + G[c ^ 1].push_back(a); + G[c ^ 1].push_back(b ^ 1); + } + bool Solve() + { + for (int i = 0; i < 2 * n; i += 2) + { + if (!mark[i] && !mark[i + 1]) + { + c = 0; + if (!Dfs(i)) + { + while (c > 0) mark[S[--c]] = false; + if (!Dfs(i + 1)) + return false; + } + } + } + return true; + } +}; +TwoSAT sat; +int main() +{ + int n, m; + while (scanf("%d %d", &n, &m) != EOF) + { + int a, b, c; + sat.Init(3 * n); + for (int i = 0; i < n; ++i) + { + scanf("%d %d %d", &a, &b, &c); + sat.AddClauseTeam(a, b, c); + } + for (int i = 0; i < m; ++i) + { + scanf("%d %d", &a, &b); + sat.AddClause(a, b); + } + bool ok = sat.Solve(); + if (ok) + printf("yes\n"); + else + printf("no\n"); + } + return 0; +} diff --git a/HDOJ/1827_autoAC.cpp b/HDOJ/1827_autoAC.cpp new file mode 100644 index 0000000..053a011 --- /dev/null +++ b/HDOJ/1827_autoAC.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +using namespace std; +const int M = 1005; +const int N = 3005; +struct node { + int to; + int next; +}num[N]; +int ins[M]; +int belong[M]; +int dfn[M]; +int low[M]; +int rdu[M]; +int sccf[M]; +int head[M]; +int sum[M]; +stacks; +int index, cont; +int ans; +int T, n, m, e, e1; +void init() { + e = 0; + index = 1; + cont = 0; + e1 = 0; + memset(num, 0, sizeof(num)); + memset(head, -1, sizeof(head)); + memset(dfn, 0, sizeof(dfn)); + memset(low, 0, sizeof(low)); + memset(sccf, 0, sizeof(sccf)); + memset(rdu, 0, sizeof(rdu)); + memset(belong, 0, sizeof(belong)); + memset(sum, 0, sizeof(sum)); +} +void add(int a, int b) { + num[e].to = b; + num[e].next = head[a]; + head[a] = e++; +} +void Tanjian(int u) { + int v; + dfn[u] = low[u] = index++; + ins[u] = 1; + s.push(u); + for(int k = head[u]; k != -1; k = num[k].next) { + v = num[k].to; + if(!dfn[v]) { + Tanjian(v); + low[u] = min(low[u], low[v]); + } + else if(ins[v]) { + low[u] = min(low[u], low[v]); + } + } + if(low[u] == dfn[u]) { + cont++; + do { + v = s.top(); + s.pop(); + sccf[v] = cont; + belong[cont]++; + ins[v] = 0; + }while(u != v); + } +} +int main() +{ + int a, b; + while(scanf("%d%d", &n, &m) != EOF) { + init(); + for(int i = 1; i <= n; i++) { + scanf("%d", &sum[i]); + } + for(int i = 0; i < m; i++) { + scanf("%d%d", &a, &b); + add(a, b); + } + for(int i = 1; i <= n; i++) { + if(!dfn[i]) { + Tanjian(i); + } + } + int v; + ans = 0; + int conum = 0; + for(int i = 1; i <= n; i++) { + for(int k = head[i]; k != -1; k = num[k].next) { + v = num[k].to; + if(sccf[i] != sccf[v]) { + rdu[sccf[v]]++; + } + } + } + for(int i = 1; i <= cont; i++) { + if(rdu[i] == 0) { + conum++; + int minn = 99999999; + for(int j = 1; j <= n; j++) { + if(sccf[j] == i) { + minn = min(sum[j], minn); + } + } + ans += minn; + } + } + printf("%d %d\n", conum, ans); + } + return 0; +} diff --git a/HDOJ/1828_autoAC.cpp b/HDOJ/1828_autoAC.cpp new file mode 100644 index 0000000..f746243 --- /dev/null +++ b/HDOJ/1828_autoAC.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +const int maxn=5010; +const int CONST=10001; +using namespace std; +struct Line +{ + int l,r,h; + char lab; +}line[maxn*2]; +struct node +{ + int lc,rc,cnt,len,num; + char rn,ln; +}tree[maxn*2*4]; +int n,pos[maxn*2],m,ans,tmpl,tmpr; +int abs(int a){return a>0?a:-a;} +bool cmp(Line a,Line b) +{ + return a.htmpr||pos[tree[i].rc]=tmpl&&pos[tree[i].rc]<=tmpr) + { + tree[i].cnt+=val; + update_len(i); + } + if(tree[i].lc==tree[i].rc-1)return; + update(2*i,val); + update(2*i+1,val); + update_len(i); +} +void scan() +{ + int now=2*n; + int last=0,lh=line[2*n].h; + while(now) + { + ans+=tree[1].num*2*(lh-line[now].h); + lh=line[now].h; + tmpl=line[now].l,tmpr=line[now].r; + update(1,line[now].lab); + ans+=abs(tree[1].len-last); + last=tree[1].len; + --now; + } +} +int main() +{ + while(scanf("%d",&n)!=EOF) + { + int x1,y1,x2,y2; + for(int i=1;i<=n;i++) + { + scanf("%d%d%d%d",&x1,&y1,&x2,&y2); + //x1+=CONST,x2+=CONST,y1+=CONST,y2+=CONST; + line[i].l=x1,line[i].r=x2,line[i].h=y1,line[i].lab=1; + line[n+i].l=x1,line[n+i].r=x2,line[n+i].h=y2,line[n+i].lab=-1; + pos[i]=x1,pos[n+i]=x2; + } + sort(line+1,line+1+2*n,cmp); + sort(pos+1,pos+1+2*n); + m=1; + ans=0; + for(int i=2;i<=2*n;i++) + if(pos[i]!=pos[i-1])pos[++m]=pos[i]; + built(1,1,m); + scan(); + printf("%d\n",ans); + } +} diff --git a/HDOJ/1829_autoAC.cpp b/HDOJ/1829_autoAC.cpp new file mode 100644 index 0000000..881ed2f --- /dev/null +++ b/HDOJ/1829_autoAC.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; +struct Pair +{ + int from,conflict; +}; +Pair *record; +int find(int x) +{ + if(x==record[x].from) + return x; + return record[x].from=find(record[x].from); +} +void link(int a,int b) +{ + int fa=find(a); + int fb=find(b); + if(fa!=fb) + record[fb].from=fa; +} +int main() +{ + int t; + int cnt=1; + scanf("%d",&t); + while(t--) + { + int n,m; + bool flag=false; + scanf("%d %d",&n,&m); + record=new Pair[n+1]; + for(int i=1;i<=n;i++) + { + record[i].from=i; + record[i].conflict=0; + } + int a,b; + for(int i=1;i<=m;i++) + { + scanf("%d %d",&a,&b); + int fa=find(a); + int fb=find(b); + if(fa==fb)flag=true; + if(record[a].conflict!=0) + { + link(b,record[a].conflict); + } + if(record[b].conflict!=0) + { + link(a,record[b].conflict); + } + record[a].conflict=b; + record[b].conflict=a; + } + cout<<"Scenario #"< +#include +#include +#include +#include +#include +#include +using namespace std; +#define maxn 210 +#define LL long long +#define eps 1e-6 +#define PI acos(-1.0) +int n,m,tot; +struct Point{ + double x,y; + Point(){} + Point(double _x,double _y) + { + x=_x; y=_y; + } +}; +bool operator < (const Point& a,const Point& b) +{ + if(fabs(a.x-b.x)>eps) + return a.xeps) + return a.yg; +vectorvp,p[maxn]; +Line lines[maxn]; +vectorE[maxn*maxn/2]; +vectorans; +Point pts[maxn]; +bool check(double a,double b) +{ + if(b>a+eps) return b+eps&E,double w) +{ + double d=w+PI; + if(d>PI+eps) d-=2*PI; + int id; + for(id=0;ideps) - (d<-eps); +} +double cross(const Point & o, const Point & a, const Point & b) +{ + return (a.x-o.x)*(b.y-o.y) - (b.x-o.x)*(a.y-o.y); +} +int inside_convex(Point * ps, int n, Point q) +{ + bool s[3] = {1, 1, 1}; + ps[n] = ps[0]; + for(int i = 0; i < n && (s[0] | s[2]); i ++) { + s[ 1+sig(cross(ps[i+1], q, ps[i])) ] = 0; + } + if(s[0] | s[2]) return s[1]+1; + return 0; +} +void init() +{ + int i,j; + for(i=0;i::iterator it=g.begin();it!=g.end();it++) + { + vp.push_back(it->first); + it->second=tot; + E[tot++].clear(); + } + for(i=0;i2*eps) ans++; + } + } + printf("Number of regions=%d.\n",ans); +} +int main() +{ + int ncase; + scanf("%d",&ncase); + while(ncase--) + { + scanf("%d %d",&n,&m); + init(); + gao(); + } + return 0; +} diff --git a/HDOJ/1838_autoAC.cpp b/HDOJ/1838_autoAC.cpp new file mode 100644 index 0000000..ba6f456 --- /dev/null +++ b/HDOJ/1838_autoAC.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +using namespace std; +char s[2010][2010]; +int dp[2010][2010]; +int main() +{ + int test,n; + scanf("%d",&test); + while(test--) + { + scanf("%d",&n); + for(int i = 0; i < n; i++) + scanf("%s",s[i]); + for(int i = 0; i < n; i++) + { + dp[0][i] = 1; + dp[i][0] = 1; + } + int ans = -1,cnt = 0; + for(int i = 1; i < n; i++) + { + for(int j = 1; j < n; j++) + { + if(s[i][j] != s[i-1][j] && s[i][j] != s[i][j-1] && s[i][j] == s[i-1][j-1]) + dp[i][j] = min(min(dp[i-1][j-1],dp[i-1][j]),dp[i][j-1])+1; + else dp[i][j] = 1; + if(s[i][j] == '1') + ans = max(ans,dp[i][j]); + } + } + for(int i = 0; i < n; i++) + { + for(int j = 0; j < n; j++) + { + if(dp[i][j] == ans && s[i][j] == '1') + cnt++; + } + } + printf("%d %d\n",ans,cnt); + } + return 0; +} diff --git a/HDOJ/1839_autoAC.cpp b/HDOJ/1839_autoAC.cpp new file mode 100644 index 0000000..cae9ef9 --- /dev/null +++ b/HDOJ/1839_autoAC.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +typedef __int64 ss; +struct node +{ + ss k; + ss t; + ss v; +}; +ss n,m,t,a[50005],sum,flag; +vectorvet[10005]; +ss vist[10005],dis[10005]; +ss spfa(ss num) +{ + ss minx=a[num]; + for(ss i=0; i<=n; i++) + { + dis[i]=((ss)1<<25); + vist[i]=0; + } + dis[1]=0; + vist[1]=1; + queueq; + q.push(1); + while(!q.empty()) + { + ss x=q.front(); + q.pop(); + vist[x]=0; + for(ss i=0; i=minx) + { + if(dis[p.k]>dis[x]+p.t) + { + dis[p.k]=dis[x]+p.t; + if(!vist[p.k]) + q.push(p.k); + vist[p.k]=1; + } + } + } + } + if(dis[n]<=t) + return 1; + else return 0; +} +int main() +{ + int text; + scanf("%d",&text); + while(text--) + { + ss cnt=0; + scanf("%I64d%I64d%I64d",&n,&m,&t); + for(ss i=0; i<=n; i++) + vet[i].clear(); + for(ss i=0; i +int main() +{ + int n,a,b,c; + scanf("%d",&n); + while(n--){ + scanf("%d%d%d",&a,&b,&c); + if(a!=0){ + if(b*b-a*4*c>0) + printf("2\n"); + else if(b*b==4*a*c) + printf("1\n"); + else + printf("0\n"); + } + else{ + if(b==0){ + if(c==0) + printf("INF\n"); + else + printf("0\n"); + } + else + printf("1\n"); + } + } + return 0; +} diff --git a/HDOJ/1841_autoAC.cpp b/HDOJ/1841_autoAC.cpp new file mode 100644 index 0000000..9365699 --- /dev/null +++ b/HDOJ/1841_autoAC.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +int len[2]; +int next[2][1000111]; +char str[2][1000111]; +void getnext(int z) +{ + int j,k; + j=1;k=0; + next[z][1]=0; + while(str[z][j]) + { + if(k==0 || str[z][j]==str[z][k]) next[z][++j]=++k; + else k=next[z][k]; + } +} +int KMP1(int a,int b) +{ + int i,j; + j=1; + for(i=1;str[a][i];) + { + if(str[a][i]==str[b][j]) + { + i++;j++; + if(j==len[b]) return 1; + } + else + { + j=next[b][j]; + if(j==0) {i++;j=1;} + } + } + return 0; +} +int KMP2(int a,int b) +{ + int i,j; + int flag; + j=1; + for(i=1;str[a][i];) + { + flag=1; + if(str[a][i]==str[b][j]) + { + if(i==len[a]-1) return j; + if(j==len[b]-1) flag=1; + else {flag=0;i++;j++;} + } + if(flag) + { + j=next[b][j]; + if(j==0) {i++;j=1;} + } + } + return 0; +} +int main() +{ + int T; + int ans1,ans2,ans; + scanf("%d",&T); + while(T--) + { + str[0][0]='#'; + str[1][0]='#'; + scanf("%s%s",str[0]+1,str[1]+1); + len[0]=strlen(str[0]); + len[1]=strlen(str[1]); + getnext(0); + getnext(1); + if(len[0]>len[1]) ans=KMP1(0,1); + else ans=KMP1(1,0); + if(ans) {printf("%d\n",(len[0]>len[1]?len[0]:len[1])-1);continue;} + ans1=KMP2(0,1); + ans2=KMP2(1,0); + ans=ans1>ans2?ans1:ans2; + ans=len[0]+len[1]-2-ans; + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1843_autoAC.cpp b/HDOJ/1843_autoAC.cpp new file mode 100644 index 0000000..3fa9530 --- /dev/null +++ b/HDOJ/1843_autoAC.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +using namespace std; +struct P +{ + int x; + int y; + P() {} + P(int xx, int yy):x(xx), y(yy) {} +}; +bool operator < (P p1, P p2) +{ + if (p1.x == p2.x) + { + return p1.y < p2.y; + } + return p1.x < p2.x; +} +class cmp1 +{ + public: + bool operator()(const P& left, const P& right) + { + if (left.y == right.y) + { + return left.x < right.x; + } + return left.y < right.y; + } +}; +class cmp2 +{ + public: + bool operator()(const P& left, const P& right) + { + if (left.x == right.x) + { + return left.y < right.y; + } + return left.x > right.x; + } +}; +P p1[100005]; +P p2[100005]; +int h, v; +void gao(P p2[], int v, vector

&vec) +{ + sort(p2+1, p2+1+v); + int pt = v; + vec.push_back(p2[v]); + for (int i = v-1; i >= 1; i--) + { + if (p2[i].x < p2[pt].x && p2[i].y > p2[pt].y) + { + vec.push_back(p2[i]); + pt = i; + } + } +} +int main() +{ + int T; + scanf("%d", &T); + for (int cas = 1; cas <= T; cas++) + { + scanf("%d%d", &h, &v); + for (int i = 1; i <= h; i++) + { + scanf("%d%d", &p1[i].x, &p1[i].y); + } + for (int i = 1; i <= v; i++) + { + scanf("%d%d", &p2[i].x, &p2[i].y); + } + vector

v1; + vector

v2; + gao(p1, h, v1); + gao(p2, v, v2); + int cnt = 0; + int t = 0; + int size = (int)v1.size(); + for (int i = 0; i < (int)v2.size(); i++) + { + if (t == size) break; + if (i == (int)v2.size()-1) + { + cnt++; + break; + } + if (v1[t].x > v2[i+1].x) + { + cnt++; + while (t < size && v1[t].y <= v2[i].y) + { + t++; + } + } + } + printf("%d\n", cnt); + } + return 0; +} diff --git a/HDOJ/1845_autoAC.cpp b/HDOJ/1845_autoAC.cpp new file mode 100644 index 0000000..c4d3a81 --- /dev/null +++ b/HDOJ/1845_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + int T; + int t; + int a,b; + int n; + scanf("%d",&T); + while(T--) + { + scanf("%d",&n); + t=3*n/2; + while(t--) scanf("%d%d",&a,&b); + printf("%d\n",n/2); + } + return 0; +} diff --git a/HDOJ/1846_autoAC.cpp b/HDOJ/1846_autoAC.cpp new file mode 100644 index 0000000..4b1d129 --- /dev/null +++ b/HDOJ/1846_autoAC.cpp @@ -0,0 +1,16 @@ +#include +int main() +{ + int c; + scanf("%d",&c); + while(c--) + { + int n,m; + scanf("%d%d",&n,&m); + if(n%(m+1)==0) + printf("second\n"); + else + printf("first\n"); + } + return 0; +} diff --git a/HDOJ/1847_autoAC.cpp b/HDOJ/1847_autoAC.cpp new file mode 100644 index 0000000..a1d6d4c --- /dev/null +++ b/HDOJ/1847_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + int n ; + while(~scanf("%d",&n)) + { + if(n%3 == 0) + { + puts("Cici") ; + } + else + { + puts("Kiki") ; + } + } + return 0 ; +} diff --git a/HDOJ/1848_autoAC.cpp b/HDOJ/1848_autoAC.cpp new file mode 100644 index 0000000..77a6662 --- /dev/null +++ b/HDOJ/1848_autoAC.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; +int fib[20],sg[1010],m,n,p; +int calsg(int now){ + int i,tem; + int next[20]; + memset(next,0,sizeof(next)); + for(i=1;fib[i]<=now;i++){ + tem=now-fib[i]; + if(sg[tem]==-1) + sg[tem]=calsg(tem); + next[sg[tem]]=1; + } + for(i=0;;i++) + if(next[i]==0){ + return i; + } +} +int main(){ + int i,j,tem; + fib[1]=1; + fib[2]=2; + for(i=3;i<=16;i++) + fib[i]=fib[i-1]+fib[i-2]; + memset(sg,-1,sizeof(sg)); + while(scanf("%d %d %d",&m,&n,&p)==3 && !(m==0 && n==0 && p==0)){ + tem=calsg(m)^calsg(n)^calsg(p); + if(tem==0) + printf("Nacci\n"); + else + printf("Fibo\n"); + } +} diff --git a/HDOJ/1849_autoAC.cpp b/HDOJ/1849_autoAC.cpp new file mode 100644 index 0000000..d5a6c4d --- /dev/null +++ b/HDOJ/1849_autoAC.cpp @@ -0,0 +1,19 @@ +#include +const int MAX=1001; +int s[MAX]; +using namespace std; +int main() +{ + int n,m,i; + while(cin>>n,n) + { + m=0; + for(i=1;i<=n;i++) + cin>>s[i],m^=s[i]; + if(m) + cout<<"Rabbit Win!"< +int main() +{ + int a[105]; + int n,i,flag,sum,k; + while(scanf("%d",&n)!=EOF) + { + if(n==0) + break; + for(i=0,sum=0;i +using namespace std; +int main() +{ + int c,n,m,l; + cin>>c; + while(c--) + { + cin>>n; + int s=0; + for(int i=0;i>m>>l; + s^=m%(l+1); + } + cout<<(s?"No":"Yes")< +#include +#include "math.h" +__int64 powmod(int d, int n, int k) +{ + __int64 a,b; + if((n==0) || (d == 1)) + return 1; + for(a = d,b = 1; n>0; n=n/2) + { + if(n%2 == 1) + { + b = (b*a)%k; + } + a = (a*a)%k; + } + return b%k; +} +__int64 cacul_sum(int d, int n, int k) +{ + int l; + __int64 t1,t2,r; + l = (d-1)*k; + t1 = powmod(d, n+1, l); + t2 = (t1+l-1)%l; + r = t2/(d-1); + return r; +} +int cacul_res(int n, int k) +{ + __int64 m1,m2,m,r; + m1 = cacul_sum(251, n, k); + m2 = cacul_sum(2, 3*n, k); + m = (m1*m2)%k; + r = powmod(2008, m, k); + return r; +} +int main() +{ + int n,k; + __int64 r; + while(1) + { + scanf("%d%d", &n, &k); + if((n==0)&&(k==0)) + break; + r = cacul_res(n,k); + printf("%I64d\n", r); + } + return 0; +} diff --git a/HDOJ/1853_autoAC.cpp b/HDOJ/1853_autoAC.cpp new file mode 100644 index 0000000..57b506a --- /dev/null +++ b/HDOJ/1853_autoAC.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +using namespace std; +#define N 505 +#define MAXN 1<<28 +int map[N][N]; +int lx[N], ly[N]; +int slack[N]; +int match[N]; +bool visitx[N], visity[N]; +int n; +bool Hungary(int u) +{ + visitx[u] = true; + for(int i = 1; i <= n; ++i) + { + if(visity[i]) + continue; + else + { + if(lx[u] + ly[i] == map[u][i]) + { + visity[i] = true; + if(match[i] == -1 || Hungary(match[i])) + { + match[i] = u; + return true; + } + } + else + slack[i] = min(slack[i], lx[u] + ly[i] - map[u][i]); + } + } + return false; +} +void KM_perfect_match() +{ + int temp; + for(int i = 1; i <= n; ++i) + lx[i] = -MAXN; + memset(ly, 0, sizeof(ly)); + for(int i = 1; i <= n; ++i) + for(int j = 1; j <= n; ++j) + lx[i] = max(lx[i], map[i][j]); + for(int i = 1; i <= n; ++i) + { + for(int j = 1; j <= n; ++j) + slack[j] = MAXN; + while(1) + { + memset(visitx, false, sizeof(visitx)); + memset(visity, false, sizeof(visity)); + if(Hungary(i)) + break; + else + { + temp = MAXN; + for(int j = 1; j <= n; ++j) + if(!visity[j]) + temp = min(temp, slack[j]); + for(int j = 1; j <= n; ++j) + { + if(visitx[j]) + lx[j] -= temp; + if(visity[j]) + ly[j] += temp; + else + slack[j] -= temp; + } + } + } + } +} +int main() +{ + int m; + int a, b, cost; + int ans; + bool flag; + while(scanf("%d%d", &n, &m) != EOF) + { + ans = 0; + flag = true; + memset(match, -1, sizeof(match)); + for(int i = 1; i <= n; ++i) + for(int j = 1; j <= n; ++j) + map[i][j] = -MAXN; + for(int i = 1; i <= m; ++i) + { + scanf("%d%d%d", &a, &b, &cost); + if(-cost > map[a][b]) + map[a][b] = -cost; + } + KM_perfect_match(); + for(int i = 1; i <= n; ++i) + { + if(match[i] == -1 || map[ match[i] ][i] == -MAXN) + { + flag = false; + break; + } + ans += map[match[i]][i]; + } + if(flag) + printf("%d\n", -ans); + else + printf("-1\n"); + } + return 0; +} diff --git a/HDOJ/1854_autoAC.cpp b/HDOJ/1854_autoAC.cpp new file mode 100644 index 0000000..c89092b --- /dev/null +++ b/HDOJ/1854_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#define N 1010 +char str[N]; +int Judge(char *s) +{ + int len,i,ans; + len=strlen(s); + ans=0; + for(i=0;i1) + { + ans--; + } + else + { + return 0; + } + } + } + if(ans>=1) + { + return 1; + } +} +int main() +{ + int n,len,flag; + scanf("%d",&n); + getchar(); + while(n--) + { + scanf("%s",str); + flag=Judge(str); + if(flag) + { + printf("Yes\n"); + } + else + { + printf("No\n"); + } + } + return 0; +} diff --git a/HDOJ/1856_autoAC.cpp b/HDOJ/1856_autoAC.cpp new file mode 100644 index 0000000..834f632 --- /dev/null +++ b/HDOJ/1856_autoAC.cpp @@ -0,0 +1,40 @@ +#include +int a[10000002],dis[10000002],hsd[10000002]; +int find(int x) +{ + if(dis[x]!=x) + dis [x]=find(dis [x]); + return dis[x]; +} +int main() +{ + int n,i,j,max1; + while(scanf("%d",&n)!=EOF) + { + if(n==0) + printf("1\n"); + else + { + for(j=1; j<=10000000; j++) + { + dis[j]=j; + hsd[j]=1; + } + max1=0; + for(i=1; i<=2*n; i=i+2) + { scanf("%d%d",&a[i],&a[i+1]); + a[i]=find(a[i]); + a[i+1]=find(a[i+1]); + if(a[i]!=a[i+1]) + { + dis[a[i+1]]=a[i]; + hsd[a[i]]=hsd[a[i]]+hsd[a[i+1]]; + if(hsd[a[i]]>max1) + max1=hsd[a[i]]; + } + } + printf("%d\n",max1); + } + } + return 0; +} diff --git a/HDOJ/1857_autoAC.cpp b/HDOJ/1857_autoAC.cpp new file mode 100644 index 0000000..8a64d87 --- /dev/null +++ b/HDOJ/1857_autoAC.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +using namespace std; +const int KIND = 26; +const int MAXN = 1000000; +int cnt_node; +int R,C; +char map[505][505]; +char word[10005][22]; +struct node{ + bool isword; + int r,c; + node* next[KIND]; + void init(){ + r=c=-1; + isword=false; + memset(next, 0, sizeof(next)); + } +}Heap[MAXN]; +inline node* new_node(){ + Heap[cnt_node].init(); + return &Heap[cnt_node++]; +} +void insert(node* root, char *str){ + for(char *p=str; *p; ++p){ + int ch=*p-'A'; + if(root->next[ch]==NULL) + root->next[ch] = new_node(); + root=root->next[ch]; + } + root->isword=true; +} +void search(node* root, char *str, int row, int col){ + for(char *p=str; *p; ++p){ + int ch=*p-'A'; + if(root->next[ch]==NULL) + return ; + root=root->next[ch]; + if(root->isword && root->r==-1 && root->c==-1){ + root->r=row, root->c=col; + } + } + if(root->isword && root->r==-1 && root->c==-1){ + root->r=row, root->c=col; + } +} +void output(node* root, char *str){ + for(char *p=str; *p; ++p){ + int ch=*p-'A'; + if(root->next[ch]==NULL) + return; + root=root->next[ch]; + } + if(root->isword) + printf("%d %d\n", root->r, root->c); +} +int main(){ + cnt_node=0; + node* root=new_node(); + scanf("%d%d%*c",&R,&C); + for(int i=0; i +#include +using namespace std; +struct node +{ + int d; + __int64 w; +}; +node f[1000002]; +__int64 v[1000002]; +int main() +{ + int t,n; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + for(int i=1;i<=n;i++) + { + scanf("%I64d",&v[i]); + f[i].d=0; + } + f[1].w=v[1]; + for(int i=2;i<=n;i++) + { + if(f[i-1].w>=0) + { + f[i].w=f[i-1].w+v[i]; + f[i].d=f[i-1].d+1; + } + else f[i].w=v[i]; + } + int Max=1; + for(int i=2;i<=n;i++) + { + if(f[i].w>f[Max].w) Max=i; + else if(f[i].w==Max&&(i-f[i].d +#include +using namespace std; +int main(){ + int a[100],b[100],n; + while(n--){ + int j=1,i=0; + while(scanf("%d%d",&a[i],&b[i])!=EOF,a[i]||b[i]){ + i++; + j=j+1;} + sort(a,a+j-1); + sort(b,b+j-1); + if(j!=1) printf("%d %d %d %d\n",a[0],b[0],a[j-2],b[j-2]); + else + break; + } + return 0; +} diff --git a/HDOJ/1860_autoAC.cpp b/HDOJ/1860_autoAC.cpp new file mode 100644 index 0000000..da87472 --- /dev/null +++ b/HDOJ/1860_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +int main() +{ + int i,j,sum; + char a[5],b[80]; + while(gets(a)) + { + if(a[0]=='#') + break; + else + gets(b); + for(i=0;i +#include +#include +#include +#define Len 200 +using namespace std; +typedef struct +{ + int S,E; + int times,timee; +}node; +typedef struct +{ + int num,aver; +}nodf; +node E[Len]; +nodf AN[Len]; +int ID[1000]; +int main() +{ + char SE; + int id,h,m; + int idnum,annum; + int sum,ber; + int x,y; + idnum=0,annum=0; + while(scanf("%d",&id)!=EOF) + { + if(id==-1) + { + for(int i=0;i>SE; + sum=0,ber=0; + for(int i=0;i=ber) + AN[annum].aver++; + annum++; + } + memset(E,0,sizeof(E)); + memset(ID,0,sizeof(ID)); + idnum=0; + } + if(id!=0&&id!=-1) + { + cin>>SE; + scanf("%d:%d",&h,&m); + if(SE=='S') + { + ID[idnum]=id; + idnum++; + E[id].times=h*60+m; + E[id].S=1; + } + if(SE=='E') + { + E[id].timee=h*60+m; + E[id].E=1; + } + } +} +return 0; +} diff --git a/HDOJ/1862_autoAC.cpp b/HDOJ/1862_autoAC.cpp new file mode 100644 index 0000000..b0f8adc --- /dev/null +++ b/HDOJ/1862_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#define M 100000 +#include +struct ln{ + int xuehao; + char name[10]; + int score; +}; +struct ln a[M+10]; +int cmpx(const void *a,const void *b){ + return (*(ln*)a).xuehao-(*(ln*)b).xuehao; +} +int cmpn(const void *a,const void *b){ + ln *c=(ln*)a; + ln *d=(ln *)b; + if(!strcmp(c->name,d->name)) + return c->xuehao-d->xuehao; + else + return strcmp(c->name,d->name); +} +int cmps(const void *a,const void *b){ + ln *c=(ln*)a; + ln *d=(ln *)b; + if(c->score==d->score) + return c->xuehao-d->xuehao; + else + return c->score-d->score; +} +int main(){ + int n,c; + int i; + int t=0; + while(scanf("%d%d",&n,&c)&&n){ + t++; + for(i=0;i +#include +#define Max 10000000 +int map[110][110],cost[110],vit[110],m,n; +void prim(int x) +{ + int i,j,min,k,sum=0; + memset(vit,0,sizeof(vit)); + for(i=1;i<=m;i++) + cost[i]=map[x][i]; + cost[x]=0; + vit[x]=1; + for(i=1;imap[k][j]) + cost[j]=map[k][j]; + } + printf("%d\n",sum); +} +int main() +{ + int i,j,a,b,c; + while(scanf("%d%d",&n,&m)!=EOF&&n) + { + for(i=1;i<=m;i++) + for(j=1;j<=m;j++) + { + if(i==j) + map[i][j]=0; + map[i][j]=Max; + } + for(i=0;i +#include +#include +using namespace std; +int main() +{ + int n,i,j,mark,z,m; + float c[1000],maxx,b[100],sum,aa,bb,cc; + char a[100]; + while(~scanf("%f%d",&maxx,&n),n){ + for(i=1,z=1;i<=n;i++){ + scanf("%d",&m); + getchar(); + c[z]=mark=0;aa=bb=cc=0; + for(j=0;j600||bb>600||cc>600) mark=1; + c[z]+=b[j]; + if(c[z]>maxx) mark=1; + } + if(mark) continue; + z++; + } + z--; + sort(c+1,c+z+1); + sum=0; + for(i=z;i>=1;i--) + { + if(sum+c[i]>maxx) continue; + sum+=c[i]; + } + printf("%.2f\n",sum); + } +} diff --git a/HDOJ/1865_autoAC.cpp b/HDOJ/1865_autoAC.cpp new file mode 100644 index 0000000..865e4d1 --- /dev/null +++ b/HDOJ/1865_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +int str1[210][300]={{0}}; +int main() +{ + int n; + scanf("%d",&n); + getchar(); + while(n--) + { + char str[300]; + gets(str); + int len=strlen(str); + str1[0][0]=1; + str1[1][0]=2; + for(int i=2;i=0;i--) + if(str1[len-1][i]) + break; + for(int j=i;j>=0;j--) + printf("%d",str1[len-1][j]); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1866_autoAC.cpp b/HDOJ/1866_autoAC.cpp new file mode 100644 index 0000000..c092fe7 --- /dev/null +++ b/HDOJ/1866_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +using namespace std; +int number[4]; +char str[501]; +int map[1001][1001]; +int main() +{ + int i,j,k,sum,min_x,min_y,max_x,max_y; + int length,mark,x,y,ans; + while(gets(str)) + { + memset(map,0,sizeof(map)); + length = strlen(str); + ans = 0; + for(i=0;i= '0' && str[j] <='9') + { + sum = sum*10 + str[j] - '0'; + mark = 1; + } + else if(mark == 1 && str[j-1] >= '0' && str[j-1] <='9') + { + number[k++] = sum; + sum = 0; + mark = 0; + } + } + i = j; + min_x = min(number[0],number[2]); + max_x = max(number[0],number[2]); + min_y = min(number[1],number[3]); + max_y = max(number[1],number[3]); + for(x = min_ ;x +#include +int next[100005]; +void getnext(char str[]) +{ + int i = 1,j = 0; + int len = strlen(str); + next [0] = -1; + while(i < len) + { + if(j == -1 || str[i] == str[j]) + { + i++; + j++; + next[i] = j; + } + else + j = next[j]; + } +} +int kmp(char str1[],char str2[]) +{ + int i= 0,j = 0; + int len1 = strlen(str1),len2 = strlen(str2); + getnext(str2); + while(i0) + { + printf("%s",str2); + printf("%s\n",str1+x); + } + else + { + printf("%s",str1); + printf("%s\n",str2+x); + } + } + else if(x>y) + { + printf("%s",str1); + printf("%s\n",str2+x); + } + else + { + printf("%s",str2); + printf("%s\n",str1+y); + } + } + return 0; +} diff --git a/HDOJ/1868_autoAC.cpp b/HDOJ/1868_autoAC.cpp new file mode 100644 index 0000000..d23b91a --- /dev/null +++ b/HDOJ/1868_autoAC.cpp @@ -0,0 +1,21 @@ +#include +#include +using namespace std; +int main() +{ + int n,i,j; + while(cin>>n) + { + j = 0; + if(n%2)j = j+1; + for(i = 2;i<=sqrt(n);i++) + { + if(n%i==0) + { + if(i%2!=0)j = j+1; + if(n/i%2!=0)j = j+1; + } + } + cout < +#include +#include +#include +#include +#include +#define MAX_V 110 +#define INF 0x7ffffff +using namespace std; +map name; +int ans[MAX_V][MAX_V],d[MAX_V][MAX_V],dd[MAX_V][MAX_V]; +bool ok[MAX_V][MAX_V]; +int main() +{ + int n,m,a,b; + while(~scanf("%d%d",&n,&m)) + { + memset(d,0,sizeof(d)); + memset(ans,0,sizeof(ans)); + memset(ok,0,sizeof(ok)); + while(m--) + { + scanf("%d%d",&a,&b); + ans[a][b]=ans[b][a]=d[a][b]=d[b][a]=1; + ok[a][b]=ok[b][a]=1; + } + int times=6; + while(times--){ + memset(dd,0,sizeof(dd)); + for(int i=0;i +#include +int main() +{ + int l; + char a[1000]; + while(gets(a)) + { + l=strlen(a); + int wbx=0; + int i; + for(i=0;i +#include +using namespace std; +struct man +{ + int a,b,c; +}; +man x[1001]; +int n,t,i,m,a; +bool cmp(man x,man y) +{ + if(x.c>y.c) + return false; + return true; +} +void print(int a) +{ + int j; + for(j=0;j +#include +#include +using namespace std; +struct st +{ + string name; + int mark; + int num; +}rt[305]; +int cmp(const st &a,const st &b) +{ + if(a.mark!=b.mark) + return a.mark>b.mark; + return a.num>t) + { + int s=t,tick=0; + while(s--) + { + cin>>rt[s].name>>rt[s].mark; + rt[s].num=t-s-1; + } + sort(rt,rt+t,cmp);s=t; + while(s--) + { + cin>>a>>b; + if(b!=rt[t-s-1].mark) {tick=1;break;} + else if(a!=rt[t-s-1].name) tick=2; + } + if(tick==1) while(s--) cin>>a>>b; + switch(tick) + { + case 0:cout<<"Right"< +#include +#include +using namespace std; +struct node +{ + int b1; + int shu; + friend bool operator < (node a,node b) + { + if(a.b1!= b.b1){ + return a.b1 < b.b1; + } + else{ + return a.shu > b.shu ; + } + } +}; +int main() +{ + int a,b,c,z,d,e,f,xx,wc; + char ss[10]; + node t; + while(scanf("%d",&a)!=EOF) + { + priority_queue q; + priority_queue q1; + priority_queue q2; + xx=0; + while(a--) + { + scanf("%s",ss); + if(ss[0]=='I') + { + scanf("%d%d",&b,&c); + t.b1=c; + t.shu=++xx; + if(b==1) + { + q.push(t); + } + else if(b==2) + { + q1.push(t); + } + else if(b==3) + { + q2.push(t); + } + } + else + { + scanf("%d",&z); + if(z==1) + { + if(q.empty()==1) + { + printf("EMPTY\n"); + } + else + { + t=q.top(); + q.pop(); + printf("%d\n",t.shu); + } + } + else if(z==2) + { + if(q1.empty()==1) + { + printf("EMPTY\n"); + } + else + { + t=q1.top(); + q1.pop(); + printf("%d\n",t.shu); + } + } + else if(z==3) + { + if(q2.empty()==1) + { + printf("EMPTY\n"); + } + else + { + t=q2.top(); + q2.pop(); + printf("%d\n",t.shu); + } + } + } + } + } + return 0; +} diff --git a/HDOJ/1874_autoAC.cpp b/HDOJ/1874_autoAC.cpp new file mode 100644 index 0000000..fbf0632 --- /dev/null +++ b/HDOJ/1874_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +using namespace std; +const int M=2005; +#define min(a,b) al) + map[s][e]=map[e][s]=l; + } + for(k=0;k +#include +#include +using namespace std; +int x[10005],y[10005],fa[1000005]; +double fun(int x1,int y1,int x2,int y2) +{ + return sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0)); +} +int find(int x) +{ + int k,j,r; + r=x; + while(r!=fa[r]) + r=fa[r]; + k=x; + while(k!=r) + { + j=fa[k]; + fa[k]=r; + k=j; + } + return r; +} +int main() +{ + int t,n,i,j,k; + double len; + scanf("%d",&t); + while(t--) + { + pair pa; + pair< double,pair > p[10005]; + k=0; + scanf("%d",&n); + for(i=0;i=10&&len<=1000) + { + pa=make_pair(i,j); + p[k++]=make_pair(len,pa); + } + } + sort(p,p+k); + for(i=0;i<=n;i++) + fa[i]=i; + int a,b,ans=0; + double cnt=0; + for(i=0;i +#include +int n,m; +int map[111][111]; +struct A +{ + int ts; + int ms; +}dp[111][111]; +int Judge(int x,int y) +{ + if(x<0 || x>=n || y<0 || y>=m) return 1; + return 0; +} +int main() +{ + int T; + int i,l; + int t,x_n,y_n; + scanf("%d",&T); + while(T--) + { + scanf("%d%d",&n,&m); + for(i=0;idp[x_n][y_n].ts) + { + dp[x_n][y_n].ts=dp[i][l].ts+1; + dp[x_n][y_n].ms=dp[i][l].ms; + } + else if(dp[i][l].ts+1==dp[x_n][y_n].ts) dp[x_n][y_n].ms+=dp[i][l].ms; + x_n--; + y_n++; + } + if(i+l+map[i][l]>n+m-2) + { + if(dp[i][l].ts>dp[n-1][m-1].ts) + { + dp[n-1][m-1].ts=dp[i][l].ts; + dp[n-1][m-1].ms=dp[i][l].ms; + } + else if(dp[i][l].ts==dp[n-1][m-1].ts) dp[n-1][m-1].ms+=dp[i][l].ms; + } + else if(i+l+map[i][l]==n+m-2) + { + if(dp[i][l].ts+1>dp[n-1][m-1].ts) + { + dp[n-1][m-1].ts=dp[i][l].ts+1; + dp[n-1][m-1].ms=dp[i][l].ms; + } + else if(dp[i][l].ts+1==dp[n-1][m-1].ts) dp[n-1][m-1].ms+=dp[i][l].ms; + } + } + } + printf("%d %d\n",dp[n-1][m-1].ts,dp[n-1][m-1].ms); + } + return 0; +} diff --git a/HDOJ/1877_autoAC.cpp b/HDOJ/1877_autoAC.cpp new file mode 100644 index 0000000..7134e6d --- /dev/null +++ b/HDOJ/1877_autoAC.cpp @@ -0,0 +1,17 @@ +#include +#include +using namespace std; +int main() +{ + int m; + __int64 A,B; + char ans[30]; + while(cin>>m&&m) + { + cin>>A>>B; + A+=B; + itoa(A,ans,m); + cout< +#include +#include +#include +#include +#include +using namespace std; +int a[1024],b[1024]; +int main() +{ + int n,i,j,m,ji1,ji2,ji,sji; + while(~scanf("%d",&n)) + { + if(!n)break; + scanf("%d",&m); + for(i=1;i<=n;i++) + { + a[i]=i; + } + memset(b,0,sizeof(b)); + for(i=0;iji2) + { + ji=ji1; + ji1=ji2; + ji2=ji; + } + a[ji2]=ji1; + } + sji=0; + for(i=2;i<=n;i++) + { + if(a[i] == i) + { + sji=1; + break; + } + } + for(i=1;i<=n;i++) + { + if(b[i]%2) + { + sji=1; + break; + } + } + if(sji) + { + printf("0\n"); + } + else + { + printf("1\n"); + } + } + return 0; +} diff --git a/HDOJ/1879_autoAC.cpp b/HDOJ/1879_autoAC.cpp new file mode 100644 index 0000000..96099c2 --- /dev/null +++ b/HDOJ/1879_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define ll long long +#define db double +const int maxn=108; +const int INF=0x7f7f7f7f; +int mp[maxn][maxn]; +int low[maxn],vis[maxn]; +int sum; +void prim(int n) +{ + int i,j,k,mi; + memset(vis,0,sizeof(vis)); + for(i=1;i<=n;i++) + low[i]=mp[1][i]; + for(i=2;i<=n;i++) + { + mi=INF; + for(j=2;j<=n;j++) + if(!vis[j]&&low[j]mp[k][j]) + low[j]=mp[k][j]; + } + for(i=1;i<=n;i++) + sum+=low[i]; +} +int main() +{ + int i,j,k,n,a,b,c,d,m; + while(scanf("%d",&n)==1&&n) + { + memset(mp,INF,sizeof(mp)); + for(i=1;i<=n;i++) mp[i][i]=0; + m=n*(n-1)/2; + for(i=1;i<=m;i++) + { + scanf("%d%d%d%d",&a,&b,&c,&d); + if(d==1) + mp[a][b]=mp[b][a]=0; + else + mp[a][b]=mp[b][a]=c; + } + sum=0; + prim(n); + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1880_autoAC.cpp b/HDOJ/1880_autoAC.cpp new file mode 100644 index 0000000..dae0ba5 --- /dev/null +++ b/HDOJ/1880_autoAC.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +using namespace std; +struct cd +{ + string a; + string b; +}dic[100100]; +int main(void) +{ + string js,tem,cx; + char ct[30]; + int tms=0; + while(getline(cin,tem),tem!="@END@") + { + dic[tms].a=tem.substr(0,tem.find(']',0)+1); + dic[tms].b=tem.substr(tem.find(']',0)+2); + ++tms; + } + int cs;int i; + cin>>cs; + int a; while((a=getchar())!='\n'); + while(cs--&&getline(cin,cx)) + { + if(cx[0]=='[') + { + for(i=0;i +#include +using namespace std; +int m[31][1000]; +struct bg_typ +{ + int h,l,t; +}; +bg_typ bg[31]; +bool cmp(const bg_ a,const bg_ b) +{ + return a.t>n&&n>=0) + { + int mmax=0; + for(int t=1;t<=n;++t) + { + cin>>bg[t].h>>bg[t].l>>bg[t].t; + if(bg[t].t>mmax) + mmax=bg[t].t; + } + sort(bg+1,bg+n+1,cmp); + for(int i=0;i<=n;++i)m[i][0]=m[0][i]=0; + for(int i=1;i<=n;++i) + { + for(int j=0;j<=mmax;++j) + { + if(j<=bg[i].t&&j-bg[i].l>=0) + m[i][j]=max(m[i-1][j],m[i-1][j-bg[i].l]+bg[i].h); + else if(j +#include +#include +#include +#include +#include +#define LL long long +#define _LL __int64 +using namespace std; +const int INF = 0x3f3f3f3f; +int n,m; +char map[17][17]; +int sta[17],tmp[17]; +int bit[17]; +int ans; +void cal() +{ + bit[0] = 1; + for(int i = 1; i < 17; i++) + bit[i] = (bit[i-1] << 1); +} +void input() +{ + memset(sta,0,sizeof(sta)); + if(n >= m) + { + for(int i = 0; i < n; i++) + { + scanf("%s",map[i]); + for(int j = 0; j < m; j++) + { + if(map[i][j] == 'X') + sta[i] = (sta[i] << 1) + 1; + else sta[i] <<= 1; + } + } + } + else + { + for(int i = 0; i < n; i++) + { + scanf("%s",map[i]); + for(int j = 0; j < m; j++) + { + if(map[i][j] == 'X') + sta[j] = (sta[j] << 1) + 1; + else sta[j] <<= 1; + } + } + swap(n,m); + } +} +void solve() +{ + int step; + ans = INF; + for(int i = 0; i < (1< 0) + tmp[0] ^= bit[j-1]; + if(j < m-1) + tmp[0] ^= bit[j+1]; + tmp[0] ^= bit[j]; + tmp[1] ^= bit[j]; + } + } + for(int j = 1; j < n && step < ans; j++) + { + for(int k = 0; k < m && step < ans; k++) + { + if(bit[k]&tmp[j-1]) + { + step++; + if(k > 0) + tmp[j] ^= bit[k-1]; + if(k < m-1) + tmp[j] ^= bit[k+1]; + tmp[j] ^= bit[k]; + tmp[j+1] ^= bit[k]; + } + } + } + if(!tmp[n-1]) + ans = min(ans,step); + } +} +int main() +{ + cal(); + while(~scanf("%d %d",&n,&m)) + { + if(n == 0 && m == 0) break; + input(); + solve(); + if(ans == INF) + printf("Damaged billboard.\n"); + else printf("You have to tap %d tiles.\n",ans); + } + return 0; +} diff --git a/HDOJ/1883_autoAC.cpp b/HDOJ/1883_autoAC.cpp new file mode 100644 index 0000000..0c0619f --- /dev/null +++ b/HDOJ/1883_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +const int maxn = 2111; +const double eps = 1e-8; +const double pi = acos(-1.0); +int n, R, ctp; +inline int dcmp(double x) {return (x > eps) - (x < -eps);} +inline double Sqr(double x){return x * x;} +struct Point {int x, y;} p[maxn]; +inline double CalDis(const Point &a, const Point &b) +{return sqrt(Sqr(a.x - b.x) + Sqr(a.y - b.y));} +struct Cov { double site; int se;}cover[maxn <<2]; +int AScomp(const void *a, const void *b) +{ + if(!dcmp((*(Cov*)a).site - (*(Cov*)b).site)) + return -((*(Cov*)a).se - (*(Cov*)b).se); + return dcmp((*(Cov*)a).site - (*(Cov*)b).site); +} +void AngManage(double &x) +{ + while(x + pi < eps) x += 2 * pi; + while(x - pi > eps) x -= 2 * pi; +} +void AddAnSeg(double start, double end) +{ + AngManage(start), AngManage(end); + if(start - end > eps) AddAnSeg(start, pi), AddAnSeg(-pi + eps * 2, end); + else + { + cover[ctp].site = start, cover[ctp].se = 1;++ ctp; + cover[ctp].site = end, cover[ctp].se = -1;++ ctp; + } +} +int MakeAns() +{ + int i, j, ans = 0, cnt; + double dis, ang, ac, RR = 2 * (R + 0.001); + for(i = 0 ; i < n; ++ i) + { + for(j = ctp = 0; j < n; ++ j) + if(j != i && (dis = CalDis(p[i], p[j])) < RR) + { + ang = atan2((double)p[j].y - p[i].y, (double)p[j].x - p[i].x); + ac = acos(dis * 0.5 / R); + AddAnSeg(ang - ac, ang + ac); + } + qsort(cover, ctp, sizeof(Cov), AScomp); + for(j = cnt = 0; j < ctp; ++ j) + ans = std::max(ans, cnt += cover[j].se); + } + return ans + 1; +} +int main() +{ + while(scanf("%d%d", &n, &R), n | R) + { + for(int i = 0; i < n; ++ i) + scanf("%d%d", &p[i].x, &p[i].y); + printf("It is possible to cover %d points.\n", MakeAns()); + } + return 0; +} diff --git a/HDOJ/1884_autoAC.cpp b/HDOJ/1884_autoAC.cpp new file mode 100644 index 0000000..5a57547 --- /dev/null +++ b/HDOJ/1884_autoAC.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define mod 1000000007ll +#define N 100009 +#define inf 1000000000ll; +using namespace std; +typedef pair II; +int dx[]={0,0,-1,-1,1,1}, + dy[]={-1,1,0,-1,0,1}; +int n; +char s[100][100]; +int d[100][100][1<<4],in[100][100][1<<4]; +queue Q; +int get(char c){ + if(c=='.') return 0; + return 1<<(c-'A'); +} +void update(int x,int y,int z,int v){ + if(d[x][y][z]==-1||d[x][y][z]>v){ + d[x][y][z]=v; + if(!in[x][y][z]) in[x][y][z]=1,Q.push(x*1600+y*16+z); + } +} +int main(){ + while(scanf("%d",&n),n) + { + memset(s,0,sizeof(s)); + memset(d,-1,sizeof(d)); + memset(in,0,sizeof(in)); + while(!Q.empty()) Q.pop(); + char c; + for(int i=1;i<=n;i++) + for(int j=1;j +#include +#include +#include +#include +#include +#include +#include +#include +#define inf 0x3f3f3f3f +using namespace std; +struct point +{ + int x,y,z; +}; +point b; +mapgg; +int n,m; +char mp[105][105]; +int vis[105][105][16]; +int dir[4][2]={ {1,0},{-1,0},{0,-1},{0,1} }; +void init() +{ + gg['b']=gg['B']=0; + gg['y']=gg['Y']=1; + gg['r']=gg['R']=2; + gg['g']=gg['G']=3; +} +int bfs() +{ + queuess; + ss.push(b); + vis[b.x][b.y][b.z]=0; + while(ss.size()) + { + point f=ss.front(); + ss.pop(); + for(int i=0;i<4;i++) + { + b.x=f.x+dir[i][0]; + b.y=f.y+dir[i][1]; + b.z=f.z; + if(mp[b.x][b.y]!='#'&&vis[b.x][b.y][b.z]==-1) + { + if(mp[b.x][b.y]=='X') return vis[f.x][f.y][f.z]+1; + if(mp[b.x][b.y]=='.') + { + vis[b.x][b.y][b.z]=vis[f.x][f.y][f.z]+1; + ss.push(b); + continue; + } + int t=gg[mp[b.x][b.y]]; + if(isupper(mp[b.x][b.y])) + { + if(b.z>>t&1) + { + vis[b.x][b.y][b.z]=vis[f.x][f.y][f.z]+1; + ss.push(b); + } + } + else + { + b.z=b.z|1< +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int M=1200; +char dd[10]="WNES"; +int rr[M]; +int cnt; +int n; +struct Point +{ + int x,y; + bool operator<(const Point &ret)const + { + if(x!=ret.x) + return x re; +bool check(int i,int x,int y) +{ + int sum=0; + if(i==0) + { + for(int j=1;j<=n;j++) + { + if(point[j].y==y&&point[j].xy) + { + sum++; + } + } + else if(i==2) + { + for(int j=1;j<=n;j++) + { + if(point[j].y==y&&point[j].x>x) + { + sum++; + } + } + } + else + { + for(int j=1;j<=n;j++) + if(point[j].x==x&&point[j].yy) + { + if(nid==-1) + { + ny=point[i].y; + nx=point[i].x; + nid=i; + } + else if(abs(point[i].y-y)x) + { + if(nid==-1) + { + ny=point[i].y; + nx=point[i].x; + nid=i; + } + else if(abs(point[i].x-x)=0;i--) + { + if(check(i,ax,ay)) + { + dfs(ax,ay,i,0); + break; + } + } + cnt=0; + while(!re.empty()) + { + int c=re.top(); + re.pop(); + rr[cnt++]=c; + } + if(flag) + { + for(int i=0;i=0;i--) + { + rr[i]=(rr[i]+2)%4; + printf("%c",dd[rr[i]]); + } + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1890_autoAC.cpp b/HDOJ/1890_autoAC.cpp new file mode 100644 index 0000000..395ef5b --- /dev/null +++ b/HDOJ/1890_autoAC.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +using namespace std; +#define Keytree (ch[ ch[root][1] ][0]) +const int maxn = 100010; +struct node { + int num,id; +}in[maxn]; +int id[maxn]; +int cmp(node a,node b){ + if(a.num!=b.num) return a.numr) return ; + int mid=(l+r)>>1; + Newnode(x,f); + map[id[mid]]=x; + build(ch[x][0],l,mid-1,x); + build(ch[x][1],mid+1,r,x); + pushup(x); + } + void init(int n){ + int i; + pre[0]=ch[0][0]=ch[0][1]=0; + size[0]=flip[0]=tot=0; + for(i=1;i<=n;i++) { + scanf("%d",&in[i].num); + in[i].id=i; + } + sort(in+1,in+n+1,cmp); + for(i=1;i<=n;i++) id[in[i].id]=i; + map[id[1]] = 1; + map[id[n]] = 2; + Newnode(root,0); + Newnode(ch[root][1],root); + build(Keytree,2,n-1,ch[root][1]); + pushup(ch[root][1]); + pushup(root); + } + void solve(int n){ + for(int i=1;i<=n;i++){ + Splay(map[i],0); + printf("%d",i+size[ch[root][0]]); + if(i +using namespace std; +int a[1010][1010],c[1010][1010],n=1005; +int lowbit(int x) +{ + return x&(-x); +} +int sum(int x,int y) +{ + int i,j,sum=0; + for(i=x;i>0;i-=lowbit(i)) + { + for(j=y;j>0;j-=lowbit(j)) + { + sum+=c[i][j]; + } + } + return sum; +} +void inster(int x,int y,int z) +{ + int i,j; + for(i=x;i<=n;i+=lowbit(i)) + { + for(j=y;j<=n;j+=lowbit(j)) + { + c[i][j]+=z; + } + } +} +int main() +{ + int x1,y1,x2,y2,t,m,i,j,n1,f=0; + scanf("%d",&t); + while(t--) + { + printf("Case %d:\n",++f); + memset(a,0,sizeof(a)); + memset(c,0,sizeof(c)); + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + { + a[i][j]=1; + inster(i,j,1); + } + scanf("%d",&m); + while(m--) + { + char s; + getchar(); + s=getchar(); + if(s=='S') + { + scanf("%d%d%d%d",&x1,&y1,&x2,&y2); + x1++;x2++;y1++;y2++; + if(x1>x2) + swap(x1,x2); + if(y1>y2) + swap(y1,y2); + printf("%d\n",sum(x2,y2)-sum(x2,y1-1)-sum(x1-1,y2)+sum(x1-1,y1-1)); + } + else + if(s=='A') + { + scanf("%d%d%d",&x1,&y1,&n1); + x1++;y1++; + inster(x1,y1,n1); + a[x1][y1]+=n1; + } + else + if(s=='D') + { + scanf("%d%d%d",&x1,&y1,&n1); + x1++;y1++; + if(n1>a[x1][y1]) + n1=a[x1][y1]; + inster(x1,y1,-n1); + a[x1][y1]-=n1; + } + else + if(s=='M') + { + scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&n1); + x1++;y1++;x2++;y2++; + if(a[x1][y1]>=n1) + { + a[x1][y1]-=n1; + inster(x1,y1,-n1); + inster(x2,y2,n1); + a[x2][y2]+=n1; + } + else + { + inster(x1,y1,-a[x1][y1]); + inster(x2,y2,a[x1][y1]); + a[x2][y2]+=a[x1][y1]; + a[x1][y1]=0; + } + } + } + } + return 0; +} diff --git a/HDOJ/1893_autoAC.cpp b/HDOJ/1893_autoAC.cpp new file mode 100644 index 0000000..bc8ce80 --- /dev/null +++ b/HDOJ/1893_autoAC.cpp @@ -0,0 +1,33 @@ +# include +# define inf 1000000007 +const double eps=1e-8; +__int64 a[100005]; +void init(){ + int i; + for(i=0;i<=313;i++) + a[i] = 1; + for(i=314;i<=100000;i++){ + a[i]= a[i-100] + a[i-314]; + a[i]=a[i]%inf; + } +} +int main(){ + int T,y,i; + double x; + init(); + scanf("%d",&T); + while(T--){ + scanf("%lf",&x); + if(x<0) + printf("0\n"); + else if(x<1) + printf("1\n"); + else + { + x=x*100; + y=(int)(x+eps); + printf("%I64d\n",a[y]); + } + } + return 0; +} diff --git a/HDOJ/1894_autoAC.cpp b/HDOJ/1894_autoAC.cpp new file mode 100644 index 0000000..636927e --- /dev/null +++ b/HDOJ/1894_autoAC.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +string a[100010]; +int main() +{ + int cas,i,j,n,cnt; + cin>>cas; + while(cas--) + { + cnt=0; + cin>>n; + for(i=0;i>a[i]; + sort(a,a+n); + for(i=0;i=a[j].size()) break; + if(a[i].compare(0,a[i].size(),a[j],0,a[i].size())==0) + cnt++; + else break; + } + } + if(cnt>11519) cnt=cnt%11519; + printf("%d\n",cnt); + } + return 0; +} diff --git a/HDOJ/1895_autoAC.cpp b/HDOJ/1895_autoAC.cpp new file mode 100644 index 0000000..86d30a4 --- /dev/null +++ b/HDOJ/1895_autoAC.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +using namespace std; +#define SIZE 310 +int a[5][SIZE],n[5],b[SIZE*SIZE],c[SIZE*SIZE]; +int main() +{ + int t,i,j,len1,len2,len3,k,p1,p2,carry,flg; + __int64 ans; + scanf("%d",&t); + while(t--) + { + for(i=0;i<5;i++) + { + scanf("%d",&n[i]); + for(j=0;j= 0;j++) + { + while(a[4][i]+b[j]+c[carry]>0) + { + carry--; + } + if(a[4][i]+b[j]+c[carry] == 0) + { + p1=p2=1; + while(j0 && c[carry] == c[carry-1]) + { + carry--; + p2++; + } + ans+=p1*p2; + } + } + } + printf("%I64d\n",ans%1000000007); + } + return 0; +} diff --git a/HDOJ/1896_autoAC.cpp b/HDOJ/1896_autoAC.cpp new file mode 100644 index 0000000..02d3eb3 --- /dev/null +++ b/HDOJ/1896_autoAC.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +using namespace std; +struct stone{int pos , dis;}; +struct compare +{ + bool operator() (const stone & s1 , const stone & s2) + { + if(s1.pos != s2.pos){return s1.pos > s2.pos;} + return s1.dis > s2.dis; + } +}; +int main() +{ + int t; + cin >> t; + while(t --) + { + int n; + cin >> n; + priority_queue , compare> record; + for(int i = 1; i <= n; ++i) + { + stone s; + cin >> s.pos >> s.dis; + record.push(s); + } + int cnt = 1; + while(!record.empty()) + { + stone t = record.top(); + record.pop(); + if(cnt % 2) + { + t.pos += t.dis; + record.push(t); + } + if(record.empty()){cout << t.pos << endl;} + ++cnt; + } + } + return 0; +} diff --git a/HDOJ/1897_autoAC.cpp b/HDOJ/1897_autoAC.cpp new file mode 100644 index 0000000..c1a1c10 --- /dev/null +++ b/HDOJ/1897_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 0x7fffffff +#define max3(a,b,c) (max(a,b)>c?max(a,b):c) +#define min3(a,b,c) (min(a,b) Q; + map P; + int n, q, y; + int cnt = 0; + while(t--) + { + cnt++; + Q.clear(); + P.clear(); + scanf("%d%d%d", &n, &q, &y); + int lp; + for(int i = 0; i < n; ++i) + { + scanf("%d", &lp); + P[lp]++; + Q.insert(lp); + } + multiset::iterator kp; + printf("Case %d:\n", cnt); + for(int i = 0; i < q; ++i) + { + int tp; + scanf("%d", &tp); + int tt = tp + y; + multiset::iterator it = Q.lower_bound(tp); + if(it == Q.end()) + printf("-1\n"); + else + { + int tmp = (*it); + if(tmp == tp) + { + printf("%d\n", tp); + Q.erase(*it); + P[(*it)] --; + for(int kk = 0; kk < P[(*it)]; ++kk) + Q.insert(tp); + } + else + { + int qq = (*it); + if(qq <= (tt)) + { + printf("%d\n", qq); + P[qq]--; + Q.erase(qq); + for(int kk = 0; kk < P[qq]; ++kk) + Q.insert(qq); + } + else + printf("-1\n"); + } + } + } + } + return 0; +} diff --git a/HDOJ/1898_autoAC.cpp b/HDOJ/1898_autoAC.cpp new file mode 100644 index 0000000..de2912f --- /dev/null +++ b/HDOJ/1898_autoAC.cpp @@ -0,0 +1,18 @@ +#include +int main() +{ + int a,b,n,q,w; + long int t; + scanf("%d",&n); + while(n--) + { + scanf("%d%d%ld",&a,&b,&t); + q=t%a;w=t%b; + if(q