diff --git a/HDOJ/1700_autoAC.cpp b/HDOJ/1700_autoAC.cpp new file mode 100644 index 0000000..2f8ec8d --- /dev/null +++ b/HDOJ/1700_autoAC.cpp @@ -0,0 +1,30 @@ +#include +#include +int main() +{ + double x1,x2,x3,y1,y2,y3,a,b,c,r; + int T; + scanf("%d",&T); + while(T--) + { + scanf("%lf%lf",&x1,&y1); + r=sqrt(x1*x1+y1*y1); + a=1; + b=y1; + c=r*r/4-x1*x1; + y2=(-b-sqrt(b*b-4*a*c))/(2*a); + y3=(-b+sqrt(b*b-4*a*c))/(2*a); + if(fabs(x1-0)<1e-7) + { + x2=-sqrt(r*r-y2*y2); + x3=sqrt(r*r-y3*y3); + } + else + { + x2=(-r*r/2-y1*y2)/x1; + x3=(-r*r/2-y1*y3)/x1; + } + printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x3,y3); + } + return 0; +} diff --git a/HDOJ/1701_autoAC.cpp b/HDOJ/1701_autoAC.cpp new file mode 100644 index 0000000..0639e5c --- /dev/null +++ b/HDOJ/1701_autoAC.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +int main() +{ double j,k;int n,i; + cin>>n; + while(n--) + { + cin>>j>>k; + i=2; + while(i>1) + { + if(int(k*i*0.01)-int(j*i*0.01)==1) + break; + i++; + } + cout< +#include +#include +#include +using namespace std; +void que(int n) +{ + int a,b; + char str[5]; + queueq; + while(n--) + { + scanf("%s",str); + if(!strcmp(str,"IN")) + { + scanf("%d",&a); + q.push(a); + } + else + { + if(q.empty()) + printf("None\n"); + else + { + b=q.front(); + printf("%d\n",b); + q.pop(); + } + } + } + while(!q.empty()) + { + q.pop(); + } +} +void sta(int n) +{ + int a,b; + char str[5]; + stacks; + while(n--) + { + scanf("%s",str); + if(!strcmp(str,"IN")) + { + scanf("%d",&a); + s.push(a); + } + else + { + if(s.empty()) + printf("None\n"); + else + { + b=s.top(); + printf("%d\n",b); + s.pop(); + } + } + } + while(!s.empty()) + { + s.pop(); + } +} +int main() +{ + int t,n,i,j; + char s1[6]; + scanf("%d",&t); + while(t--) + { + scanf("%d %s",&n,s1); + if(!strcmp(s1,"FIFO")) + { + que(n); + } + else + { + sta(n); + } + } + return 0; +} diff --git a/HDOJ/1703_autoAC.cpp b/HDOJ/1703_autoAC.cpp new file mode 100644 index 0000000..72f1718 --- /dev/null +++ b/HDOJ/1703_autoAC.cpp @@ -0,0 +1,12 @@ +#include +int main(){ + int n; + while(scanf("%d",&n)&&n){ + if(n==1||n==2){ + printf("%d\n",(n-1)*5); continue; + } + else if(n==3) printf("15\n"); + else printf("%d\n",(n*2-4)*5); + } + return 0; +} diff --git a/HDOJ/1704_autoAC.cpp b/HDOJ/1704_autoAC.cpp new file mode 100644 index 0000000..a0867e4 --- /dev/null +++ b/HDOJ/1704_autoAC.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +using namespace std; +#define M 505 +int a[M][M],n; +void dfs(int x,int y) +{ + int i,j; + for(i=1;i<=n;i++) + { + if(a[i][x]==1) + { + a[i][y]=1; + for(j=1;j<=n;j++) + { + if(a[y][j]==1) + a[i][j]=1; + } + } + } +} +int main() +{ + int m,t,x,y,i,j,sum; + scanf("%d",&t); + while(t--) + { + sum=0; + memset(a,0,sizeof(a)); + scanf("%d%d",&n,&m); + for(i=1;i<=n;i++) + a[i][i]=1; + while(m--) + { + scanf("%d%d",&x,&y); + a[x][y]=1; + dfs(x,y); + } + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(a[i][j]==1) + sum++; + } + } + sum=n*(n+1)/2-sum; + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1705_autoAC.cpp b/HDOJ/1705_autoAC.cpp new file mode 100644 index 0000000..49a7d50 --- /dev/null +++ b/HDOJ/1705_autoAC.cpp @@ -0,0 +1,33 @@ +#include +struct point{ + int x,y; +}p[3],m[3]; +int gcd(int a,int b){ + int c; + while(b){ + c=a%b; + a=b; + b=c; + } + return a; +} +int abs(int x){ + return x>0?x:-x; +} +int S(point p1,point p2,point p0){ + return abs((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)); +} +int main(){ + int sum,s,ans; + while(~scanf("%d%d%d%d%d%d",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)){ + if(!p[0].x&&!p[0].y&&!p[1].x&&!p[1].y&&!p[2].x&&!p[2].y)break; + m[0].x=abs(p[0].x-p[1].x);m[0].y=abs(p[0].y-p[1].y); + m[1].x=abs(p[1].x-p[2].x);m[1].y=abs(p[1].y-p[2].y); + m[2].x=abs(p[0].x-p[2].x);m[2].y=abs(p[0].y-p[2].y); + sum=gcd(m[0].x,m[0].y)+gcd(m[1].x,m[1].y)+gcd(m[2].x,m[2].y); + s=S(p[1],p[2],p[0]); + ans=(s-sum+2)/2; + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1707_autoAC.cpp b/HDOJ/1707_autoAC.cpp new file mode 100644 index 0000000..ae7b06a --- /dev/null +++ b/HDOJ/1707_autoAC.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +using namespace std; +typedef struct +{ + int timecheck[8][12]; + char name[30]; +}student; +typedef struct +{ + char Lname[30]; +}Lstudent; +student book[201]; +Lstudent buf[201]; +bool c(Lstudent a,Lstudent b) +{ + return (strcmp(a.Lname,b.Lname)<0); +} +int main() +{ + int n,i,b,t,k,l,x,b1,e1,count; + scanf("%d",&n); + for(i=0;i +#include +__int64 a1[26],f[55],a2[26]; +char s1[55],s2[55]; +int main() +{ + int k,n,i,t,j; + scanf("%d",&t); + getchar(); + while(t--) + { + char ch='a'; + int p=1; + memset(a1,0,sizeof(a1)); + memset(a2,0,sizeof(a2)); + scanf("%s%s%d",s1,s2,&k); + for(i=0;i +using namespace std; +const int N=1005; +int pre[N],in[N],post[N]; +int n; +void getpost(int pa,int pb,int ia,int ib,int la,int lb) +{ + if(pa>pb||ia>ib||la>lb) return; + int a,b,i; + for (i=ia;i<=ib;i++) + { + if (in[i]==pre[pa]) + { + break; + } + } + a=i-ia;b=ib-i; + post[lb]=in[i]; + getpost(pa+1,pa+a,ia,i-1,la,la+a-1); + getpost(pb-b+1,pb,i+1,ib,lb-b,lb-1); +} +int main() +{ + while(~scanf("%d",&n)) + { + for (int i=1;i<=n;i++) + scanf("%d",&pre[i]); + for (int i=1;i<=n;i++) + scanf("%d",&in[i]); + getpost(1,n,1,n,1,n); + for (int i=1;i +int a[1000000],b[10000],t,n,m,i,j,flag=0,k=0; +int main() +{ + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&m); + for(i=0;i +#include +int max(int x,int y) +{ + if(x>=y) + return x; + return y; +} +int main() +{ + int m,n,i,j,k,d[105],a[105][105]; + while(scanf("%d%d",&n,&m)==2) + { + if(m==0&&n==0) break; + memset(d,0,sizeof(d)); + for(i=1;i<=n;i++) + for(j=1;j<=m;j++) + scanf("%d",&a[i][j]); + for(i=1;i<=n;i++) + for(j=m;j>=1;j--) + { + for(k=1;k<=j;k++) + d[j]=max(d[j],d[j-k]+a[i][k]); + } + printf("%d\n",d[m]); + } + return 0; +} diff --git a/HDOJ/1714_autoAC.cpp b/HDOJ/1714_autoAC.cpp new file mode 100644 index 0000000..7fe5db8 --- /dev/null +++ b/HDOJ/1714_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +using namespace std; +int main() +{ + double a,b; + double x,y; + int n; + cin >> n; + while(n--&&cin >> a >> b >> x >> y) + { + y = y>0?y:-y; + double f = y/x; + double newx = sqrt(a*a*b*b/(b*b + f*f*a*a)); + double newy = f*newx; + newx = newx/a*b; + newy /= b; + newx /= b; + double t = acos(newx); + double area = t * b * a / 2; + cout << fixed << setprecision(2) << area << endl; + } +} diff --git a/HDOJ/1716_autoAC.cpp b/HDOJ/1716_autoAC.cpp new file mode 100644 index 0000000..6d3d099 --- /dev/null +++ b/HDOJ/1716_autoAC.cpp @@ -0,0 +1,35 @@ +#include +#include +using namespace std; +int main() +{ + int a[5],tem; + cin>>a[1]>>a[2]>>a[3]>>a[4]; + while(a[1]||a[2]||a[3]||a[4]) + { + sort(a+1,a+5); + tem=a[1]; + if(tem) + cout<>a[1]>>a[2]>>a[3]>>a[4]; + if(a[1]||a[2]||a[3]||a[4]) + cout< +#include +#include +using namespace std; +int gcd(int a,int b){ + return b==0?a:gcd(b,a%b); +} +int main() +{ + char str[20]; + int T; + scanf("%d",&T); + while(T--) + { + scanf("%s",str); + int len = strlen(str); + int i,j,a,b; + int flag = 1; + int ans1 = 0,ans2 = 0; + int shi1 = 1,shi2 = 0; + for(i = 2;i < len;i++) + { + if(str[i] == '(') + {flag = 0;} + if(str[i] >= '0'&&str[i] <= '9') + { + if(flag) + { + shi1 = shi1*10; + ans1 = ans1*10+str[i]-'0'; + } + else + { + shi2 = shi2*10+9; + ans2 = ans2*10+str[i]-'0'; + } + } + } + if(flag) + { + printf("%d/%d\n",ans1/gcd(ans1,shi1),shi1/gcd(ans1,shi1)); + } + else + { + int cnt = gcd(ans2+shi2*ans1,shi2); + a=(ans2+shi2*ans1)/cnt; + b=shi2/cnt; + int Cnt=gcd(a,b*shi1); + printf("%d/%d\n",a/Cnt,b*shi1/Cnt); + } + } + return 0; +} diff --git a/HDOJ/1718_autoAC.cpp b/HDOJ/1718_autoAC.cpp new file mode 100644 index 0000000..3623a15 --- /dev/null +++ b/HDOJ/1718_autoAC.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +void main() +{ + int a[101],i,num,num1,rank,mark1,mark; + while(cin>>num) + { + memset(a,0,sizeof(a)); + while(cin>>num1>>mark1&&(num1!=0||mark1!=0)) + { + if(num1==num) + mark=mark1; + a[mark1]++; + } + for(i=100,rank=0;i>mark;i--) + rank+=a[i]; + cout< +#include +int main() +{ + int a,b; + while(scanf("%x%x",&a,&b)!=EOF){ + printf("%d\n",a+b); + } + return 0; +} diff --git a/HDOJ/1721_autoAC.cpp b/HDOJ/1721_autoAC.cpp new file mode 100644 index 0000000..d5de40e --- /dev/null +++ b/HDOJ/1721_autoAC.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +int a[8]; +int main() +{ + int x; + while(cin>>x) + { + int sum1; + int sum2; + if(x==-1) + break; + a[0]=x; + for(int i=1;i<=7;i++) + { + cin>>a[i]; + } + sum1=a[0]+a[2]+a[5]+a[7]; + sum2=a[1]+a[3]+a[4]+a[6]; + if(sum1==sum2) + cout<<"All the seeds can be cleared away!"< +using namespace std; +int main() +{ + int n,m,a,b; + while(cin>>n>>m) + { + a=n; + b=m; + while(a!=b) + { + if(a>b) + a-=b; + else + b-=a; + } + cout< +#include +#include +using namespace std; +int main() +{ int a[50]; + int n,m; + int i,j; + while(cin>>n>>m && (n||m)) + { + memset(a,0,sizeof(a)); + a[1]=1; + for(i=1;i<=n;i++) + for(j=1;j<=m;j++) + if(i+j<=n) + a[i+j]+=a[i]; + cout< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +double a,b,l,r; +double F(double x) +{ + return b*sqrt((1-x/a)*(1+x/a)); +} +double simpson(double a,double b) +{ + double c=(a+b)/2; + return (F(a)+4*F(c)+F(b))*(b-a)/6.; +} +double asr(double a,double b,double eps,double A) +{ + double c=(a+b)/2; + double L=simpson(a,c),R=simpson(c,b); + if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15.0; + return asr(a,c,eps/2,L)+asr(c,b,eps/2,R); +} +double ASR(double a,double b,double eps) +{ + return asr(a,b,eps,simpson(a,b)); +} +int main() +{ + int T_T; + scanf("%d",&T_T); + while(T_T--) + { + scanf("%lf%lf%lf%lf",&a,&b,&l,&r); + printf("%.3lf\n",2.*ASR(l,r,1e-6)); + } + return 0; +} diff --git a/HDOJ/1725_autoAC.cpp b/HDOJ/1725_autoAC.cpp new file mode 100644 index 0000000..c21ee1f --- /dev/null +++ b/HDOJ/1725_autoAC.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; +int order_mut[32]; +int function(int n) +{ + int i; + order_mut[0]=1; + for(i=1;i<=n;i++) + { + order_mut[i]=order_mut[i-1]*i; + if(order_mut[i]>n)break; + } + return i-1; +} +int main() +{ + int i,t,n,m,ans; + cin>>t; + while(t--) + { + scanf("%d",&n); + int m=function(n); + ans=0; + for(i=m;i>=1;i--) + { + int temp=n/order_mut[i]; + ans+=temp; + n-=temp*order_mut[i]; + if(n==0)break; + } + cout< +#include +#include +#define MAX 0x0f0f0f0f +using namespace std; +char s[105]; +int dp[105][105]; +int min(int a,int b){ + return a>b?b:a; +} +bool Judge(int a,int b){ + while(a +int main() +{ + int a,b; + char s[10][10]={"\0","one","two","three","four","five","six","seven","eight","nine"}; + char p[10][10]={"\0","\0","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"}; + char q[20][10]={"\0","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"}; + while(scanf("%d",&a)!=EOF) + { + if(a==0){printf("zero\n");continue;} + if(a/1000) + { + printf("%s thousand",s[a/1000]); + b=a; + a=a-b/1000*1000; + if(a)printf(" and "); + } + if(a/100) + { + printf("%s hundred",s[a/100]); + b=a; + a=a-b/100*100; + if(a)printf(" and "); + } + if(a<20)printf("%s",q[a]); + else + { + if(a>=20) + {printf("%s",p[a/10]);b=a;a=a-b/10*10;} + if(a)printf("-%s",s[a]); + } + printf("\n"); + } +} diff --git a/HDOJ/1728_autoAC.cpp b/HDOJ/1728_autoAC.cpp new file mode 100644 index 0000000..3344353 --- /dev/null +++ b/HDOJ/1728_autoAC.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#define MAXN 100 + 10 +using namespace std; +typedef struct{ + int x,y,turn; +}coordinate; +int m,n,k; +queueQ; +coordinate start,goal; +char maze[MAXN][MAXN]; +bool vis[MAXN][MAXN]; +const int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; +void Init(){ + memset(maze,0,sizeof(maze)); + memset(vis,false,sizeof(vis)); +} +bool Judge(int x,int y){ + if(x<=0||x>m||y<=0||y>n||maze[x][y]=='*') + return false; + return true; +} +bool BFS(){ + coordinate now,next; + while(!Q.empty()) + Q.pop(); + if(start.x==goal.x&&start.y==goal.y) + return true; + Q.push(start); + vis[start.x][start.y]=true; + while(!Q.empty()){ + now = Q.front(); + Q.pop(); + for(int i=0;i<4;i++){ + next.x = now.x + dx[i]; + next.y = now.y + dy[i]; + while(Judge(next.x,next.y)){ + if(!vis[next.x][next.y]){ + next.turn = now.turn + 1; + vis[next.x][next.y] = true; + Q.push(next); + if(next.x==goal.x&&next.y==goal.y&&next.turn<=k) + return true; + } + next.x += dx[i]; + next.y += dy[i]; + } + } + } + return false; +} +int main(){ + int T; + cin>>T; + while(T--){ + cin>>m>>n; + Init(); + for(int i=1;i<=m;i++) + for(int j=1;j<=n;j++) + cin>>maze[i][j]; + cin>>k>>start.y>>start.x>>goal.y>>goal.x; + start.turn=-1; + if(BFS()) + cout<<"yes"< +#include +#include +#include +#include +#define N 10005 +#define LL long long +#define inf 1<<29 +#define eps 1e-7 +using namespace std; +int get_sg(int s,int c){ + int q=sqrt((double)s); + while(q+q*q>=s) + q--; + if(c>q) return s-c; + else return get_sg(q,c); +} +int main(){ + int n,cas=0; + while(scanf("%d",&n)!=EOF&&n){ + int s,c; + printf("Case %d:\n",++cas); + int ans=0; + while(n--){ + scanf("%d%d",&s,&c); + ans^=get_sg(s,c); + } + if(ans) + puts("Yes"); + else + puts("No"); + } + return 0; +} diff --git a/HDOJ/1730_autoAC.cpp b/HDOJ/1730_autoAC.cpp new file mode 100644 index 0000000..516e701 --- /dev/null +++ b/HDOJ/1730_autoAC.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +int main() +{ + int n,m; + int i; + int ti,ji; + int ans; + while(scanf("%d%d",&n,&m)!=EOF) + { + ans=0; + while(n--) + { + scanf("%d%d",&ti,&ji); + ans^=abs(abs(ti-ji)-1); + } + printf("%s\n",ans==0?"BAD LUCK!":"I WIN!"); + } + return 0; +} diff --git a/HDOJ/1732_autoAC.cpp b/HDOJ/1732_autoAC.cpp new file mode 100644 index 0000000..5f09a24 --- /dev/null +++ b/HDOJ/1732_autoAC.cpp @@ -0,0 +1,141 @@ +#include +#include +#include +#include +using namespace std; +struct node +{ + int x,y,x1,y1,x2,y2,x3,y3; + int step; +}; +bool vist[8][8][8][8][8][8][8][8]; +int n,m,t[4][2]= {1,0,-1,0,0,1,0,-1}; +int f[10][10],cnt; +char s[10][10]; +queueq; +void bfs() +{ + while(!q.empty()) + { + node p=q.front(); + q.pop(); + if(f[p.x1][p.y1]&&f[p.x2][p.y2]&&f[p.x3][p.y3]) + { + printf("%d\n",p.step); + return; + } + for(int i=0; i<4; i++) + { + int mx=p.x+t[i][0]; + int my=p.y+t[i][1]; + int xx=p.x+2*t[i][0]; + int yy=p.y+2*t[i][1]; + if(mx>=0&&mx=0&&my=0&&xx=0&&yy0) + { + memset(vist,false,sizeof(vist)); + memset(f,0,sizeof(f)); + while(!q.empty()) + q.pop(); + cnt=0; + int w=0; + node p; + for(int i=0; i +#include +#include +#include +#define MAXN 20005 +#define Lim 75 +#define INF (1<<30) +#define max(a,b) (a>b?a:b) +#define min(a,b) (a=0&&dx=0&&dy0&&dis[u]==dis[v]+1) + { + flag=true; + aug=min(aug,E[j].w); + pre[v]=u; + u=v; + if(u==t) + { + ans+=aug; + while(u!=s) + { + u=pre[u]; + E[cur[u]].w-=aug; + E[cur[u]^1].w+=aug; + } + aug=INF; + } + break; + } + } + if(flag) continue; + int mindis=n; + for(i=head[u];i!=-1;i=E[i].next) + { + v=E[i].v; + if(E[i].w>0&&dis[v]=0&&dx=0&&dy +#include +#include +#include +using namespace std; +int a[10001][101]; +int b[10001]; +int main() +{ + int n,m,t,i,k,j,x,d; + while(scanf("%d%d%d",&n,&m,&t)!=EOF) + { + x=0; + for(i=0;i=0;j--) + { + if(a[i-1][j]==0) + b[k]++; + else + break; + } + k++; + } + } + for(i=m-1;i>=0;i--) + { + if(a[n-1][i]==0) + x--; + else + break; + } + sort(b,b+k,greater()); + for(i=0;i +#include +#include +int zsh(char s[]) +{ + int p; + for(p=0;p=10) + { + c[j+1]++; + c[j]-=10; + } + } + if(c[l]>0) + l++; + for(j=0;j0?(strlen(a)-zsh(a)-1):0; + lxb=pd(b)>0?(strlen(b)-zsh(b)-1):0; + char a1[405],b1[405]; + lx=lxa>lxb?lxa:lxb; + lz=zsh(a)>zsh(b)?zsh(a):zsh(b); + for(i=0;i=lx;j--) + printf("%c",a1[j]); + if(i>=lx) + printf("\n"); + else + { + printf("."); + for(;j>=i;j--) + printf("%c",a1[j]); + printf("\n"); + } + } + return 0; +} diff --git a/HDOJ/1754_autoAC.cpp b/HDOJ/1754_autoAC.cpp new file mode 100644 index 0000000..44b187d --- /dev/null +++ b/HDOJ/1754_autoAC.cpp @@ -0,0 +1,43 @@ +#include +int main() +{ + int sc[200001],i,j,k,mx,mi,a,b,m,n; + char t; + while(~scanf("%d%d",&n,&m)) + { + mx = -1; + for(i=1;i<=n;i++) + { + scanf("%d",&sc[i]); + if(mxmx) + { + mx = b; + mi = a; + } + } + } + } + return 0; +} diff --git a/HDOJ/1755_autoAC.cpp b/HDOJ/1755_autoAC.cpp new file mode 100644 index 0000000..dda8c07 --- /dev/null +++ b/HDOJ/1755_autoAC.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +using namespace std; +int a[10],n; +int num[40320*9]; +int getnum() +{ + int res=0,i; + for(i=1;i<=n;i++) + res=res*10+a[i]; + return res; +} +int main() +{ + int m,k,x,i,t; + bool flag; + while(scanf("%d%d",&n,&m)!=EOF) + { + for(i=1;i<=n;i++) + scanf("%d",&a[i]); + sort(a+1,a+1+n); + t=0; + if(a[1]!=0) + num[t++]=getnum(); + while(next_permutation(a+1,a+1+n)) + { + if(a[1]!=0) + num[t++]=getnum(); + } + while(m--) + { + scanf("%d%d",&x,&k); + flag=true; + for(i=0;i +#include +#include +#include +#include +using namespace std; +#define esp 1e-8 +#define ISZERO(a) (fabs(a)<1e-8) +#define ADD 1001 +int n; +struct Point +{ + double x,y; +}a[110],b; +double chac(Point q,Point w,Point e,Point r) +{ + return (((w.x-q.x)*(e.y-q.y)-(w.y-q.y)*(e.x-q.x)) * ((w.x-q.x)*(r.y-q.y)-(w.y-q.y)*(r.x-q.x))); +} +bool calc() +{ + int i=0,ans; + double c1,c2,c3; + Point c; + a[n]=a[0]; + while(i +#include +#define maxn 10 +struct matrix{ + int ma[maxn][maxn]; + matrix(){memset( ma, 0, sizeof(ma) );} +}; +int k, m; +matrix operator * (const matrix & a,const matrix & b){ + matrix t; + for(int h = 0; h < maxn; h ++ ){ + for(int i = 0; i < maxn; i ++ ){ + for(int j = 0; j < maxn; j ++ ){ + t.ma[h][i] += a.ma[h][j] * b.ma[j][i] % m; + } + t.ma[h][i] %= m; + } + } + return t; +} +matrix binary_multiply(int n,matrix a){ + matrix t; + if( n == 1 ) + return a; + if( n > 1 ){ + t = binary_multiply( n>>1, a ); + t = t * t; + } + if( n & 1 ) + t = t * a; + return t; +} +int main(){ + int i; + matrix a, t; + while( ~scanf("%d%d", &k, &m ) ){ + for( i = 1; i < maxn; i ++ ) + a.ma[i][i-1] = 1; + for( i = 0; i < maxn; i ++ ) + scanf("%d", &a.ma[0][i] ); + if( k < maxn ) + printf("%d\n", k % m ); + else{ + t = binary_multiply( k-9, a ); + for( k = i = 0; i < maxn; i ++ ){ + k += t.ma[0][i] * ( maxn - i - 1 ); + k %= m; + } + printf("%d\n", k ); + } + } + return 0; +} diff --git a/HDOJ/1759_autoAC.cpp b/HDOJ/1759_autoAC.cpp new file mode 100644 index 0000000..fa872a0 --- /dev/null +++ b/HDOJ/1759_autoAC.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +#define MAXN 1005 +bool reach[MAXN][MAXN]; +int map[MAXN][MAXN]; +char s[1005]; +int d[MAXN],n; +struct pt +{ + int d,x; +}; +void BFS(int x) +{ + int i,j; + pt now,next; + queue q; + now.x=x; + now.d=0; + d[now.x]=now.d; + q.push(now); + while(!q.empty()) + { + now=q.front(); + q.pop(); + if (now.d>n+2) break; + for(i=1;i<=map[now.x][0];i++) + { + next.x=map[now.x][i]; + next.d=now.d+1; + if (next.d0) {reach[x][y]=1;map[x][++map[x][0]]=y;} + } + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + d[j]=0x1fffff; + BFS(i); + } + sum=0; + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + sum+=reach[i][j]; + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1760_autoAC.cpp b/HDOJ/1760_autoAC.cpp new file mode 100644 index 0000000..48d8ee2 --- /dev/null +++ b/HDOJ/1760_autoAC.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +using namespace std; +mapsg; +mapis; +int n,m; +bool judge(string str,int i,int j) +{ + if(str[i * m + j] == '1' || str[i * m + j + 1] == '1' || str[i * m + m + j] == '1' || str[i * m + m + j + 1] == '1') + return false; + return true; +} +void input(string &str,int i,int j) +{ + str[i * m + j]=str[i * m + j + 1]=str[i * m + m + j] = str[i * m + m + j + 1] = '1'; +} +int DFS(string str) +{ + if(is[str]) + return sg[str]; + for(int i = 0;i < n - 1;i++) + { + for(int j = 0;j < m - 1;j++) + { + if(judge(str,i,j)) + { + string temp = str; + input(temp,i,j); + if(DFS(temp) == 0) + { + is[str] = 1; + sg[str] = 1; + return 1; + } + } + } + } + is[str] = 1; + sg[str] = 0; + return 0; +} +int main() +{ + string str; + string temp; + while(scanf("%d %d",&n,&m)!=EOF) + { + str=""; + sg.clear(); + is.clear(); + for(int i = 0;i < n;i++) + { + cin >> temp; + str += temp; + } + if(DFS(str)) + printf("Yes\n"); + else + printf("No\n"); + } + return 0; +} diff --git a/HDOJ/1761_autoAC.cpp b/HDOJ/1761_autoAC.cpp new file mode 100644 index 0000000..0847f39 --- /dev/null +++ b/HDOJ/1761_autoAC.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef map STRING2MAP; +int main() +{ + int n, m; + int i, j; + int k; + char name[25], like[25], hate[25], go[25]; + map t_map; + map::iterator it_t; + map t_now; + map::iterator it_n; + STRING2MAP::iterator it_f; + STRING2MAP S2M; + string t_add[101], t_remove[101]; + int p_add, p_remove; + int h, l; + int geted; + while (scanf("%d%d", &n, &m) != EOF) + { + t_map.clear(); + t_now.clear(); + for (i=0; i < n; i++) + { + scanf("%s", name); + scanf("%d", &k); + t_map[name] = S2M; + it_t = t_map.find(name); + for (j=0; j < k; j++) + { + scanf("%s", like); + it_t->second.insert(STRING2MAP::value_type(like, 1)); + } + scanf("%d", &k); + for (j=0; j < k; j++) + { + scanf("%s", hate); + it_t->second.insert(STRING2MAP::value_type(hate, 2)); + } + } + scanf("%d", &k); + for (j=0; j < k; j++) + { + scanf("%s", go); + t_now[go] = true; + } + for (i=0; isecond.find(it_n->first); + if (it_f != it_t->second.end()) + { + geted = it_f->second; + if (geted & 1) l++; + if (geted & 1<<1) h++; + if (l>0 && h>0) break; + } + } + if (h == 0 && l > 0) + t_add[p_add++] = it_t->first; + if (h > 0 && l == 0) + t_remove[p_remove++] = it_t->first; + } + if (p_remove == 0 && p_add == 0) + break; + for (j=0; j < p_remove; j++) + t_now.erase(t_remove[j]); + for (j=0; j first; + it_n++; + for (; it_n != t_now.end(); it_n++) + cout << " " << it_n->first; + cout << endl; + } + return 0; +} diff --git a/HDOJ/1786_autoAC.cpp b/HDOJ/1786_autoAC.cpp new file mode 100644 index 0000000..a5976f2 --- /dev/null +++ b/HDOJ/1786_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + int m; + int n,v; + while(scanf("%d %d",&n,&v),n,v) + { + int i; + m=0; + int a; + for(i=0;i +using namespace std; +#define N 100000001 +int euler(int n) +{ + int ans=1; + int i; + for(i=2;i*i<=n;i++) + { + if(n%i==0) + { + n/=i; + ans*=i-1; + while(n%i==0) + { + n/=i; + ans*=i; + } + } + } + if(n>1) + ans*=n-1; + return ans; +} +int main() +{ + int n; + while(scanf("%d",&n),n) + { + printf("%d\n",n-1-euler(n)); + } + return 0; +} diff --git a/HDOJ/1788_autoAC.cpp b/HDOJ/1788_autoAC.cpp new file mode 100644 index 0000000..82419aa --- /dev/null +++ b/HDOJ/1788_autoAC.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; +__int64 gcd(__int64 x,__int64 y) +{ + if(x>n>>a&&(n||a)) + { + __int64 u,v; + cin>>u; + for(int i=1;i>v; + u=work(u,v); + } + cout< +#include +#include +#include +using namespace std; +struct Work +{ + int deadline; + int score; +}x[1002]; +bool cmp(Work a,Work b) +{ + if(a.score==b.score) + return a.deadlineb.score; +} +int main() +{ + int t,n,i,j,sum; + bool a[10002]; + cin>>t; + while(t--) + { + sum=0; + cin>>n; + for(i=0;i=1;--j) + if(!a[j]) + { + a[j]=true; + break; + } + if(j==0) + sum+=x[i].score; + } + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1792_autoAC.cpp b/HDOJ/1792_autoAC.cpp new file mode 100644 index 0000000..5201c1c --- /dev/null +++ b/HDOJ/1792_autoAC.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +int main() +{ + int n,m,s,k; + while(cin>>n>>m) + { + s=n*m-n-m; + cout< +#include +using namespace std; +#define N 1010 +#define inf 0xfffffff +int dp[N][N]; +int s[N][N]; +int sum[N],dia[N]; +int main(){ +int i,n,j,k,pos; +while(scanf("%d",&n)!=EOF) +{ +sum[0]=0; +for(i=0;i<=n+1;i++) +for(j=0;j<=n+1;j++) +dp[i][j]=inf; +for(i=1;i<=n;i++) +scanf("%d",&pos); +for(i=1;i<=n;i++) +{ +scanf("%d",&dia[i]); +sum[i]=sum[i-1]+dia[i]; +dp[i][i]=0; +s[i][i]=i; +} +int des; +for(k=2;k<=n;k++) +{ +for(i=1;i+k-1<=n;i++) +{ +des=i+k-1; +for(j=s[i][des-1];j<=s[i+1][des];j++) +{ +if(j==i) +{ +if(dp[i][des]>=dp[j+1][des]+sum[des]-sum[j]) +{ +dp[i][des]=dp[j+1][des]+sum[des]-sum[j]; +s[i][des]=j; +} +} +else if(j==des) +{ +if(dp[i][des]>=dp[i][j-1]+sum[j-1]-sum[i-1]) +{ +dp[i][des]=dp[i][j-1]+sum[j-1]-sum[i-1]; +s[i][des]=j; +} +} +else +{ +if(dp[i][des]>=dp[i][j-1]+dp[j+1][des]+sum[j-1]-sum[i-1]+sum[des]-sum[j]) +{ +dp[i][des]=dp[i][j-1]+dp[j+1][des]+sum[j-1]-sum[i-1]+sum[des]-sum[j]; +s[i][des]=j; +} +} +} +} +} +cout< +#include +#include +int map[31][31],a[10010]; +struct op +{ + int num,count; +}p[31][31]; +struct ed +{ + int x,y,cnt; +}e[1000]; +int cmp(const void *a,const void *b) +{ + return *(int *)b-*(int *)a; +} +int amp(const void *a,const void *b) +{ + struct ed *c,*d; + c=(ed *)a; + d=(ed *)b; + return d->cnt-c->cnt; +} +int MAX(int a,int b) +{ + if(a>b)return a; + return b; +} +int main() +{ + int i,n,j,k,t,x,y,temp,m; + __int64 sum; + scanf("%d",&t); + while(t--) + { + sum=0; + scanf("%d",&n); + for(i=0;i=i) + { + p[k][y].count+=p[i][j].num-temp; + k--; + } + k=y-1; + while(k>=j) + { + p[x][k].count+=p[i][j].num-temp; + k--; + } + x++;y++; + temp++; + } + } + } + k=0; + for(i=0;i +#include +using namespace std; +int test[10000] = {1,2,4,6,10,12,16,18,22,28,30,36,40,42,46,52,58,60,66,70,72,78,82,88,96,100,102,106,108,112,126,130,136,138,148,150,156,162,166,172,178,180,190,192,196,198,210,222,226,228,232,238,240,250,256,262,268,270,276,280,282,292,306,310,312,316,330,336,346,348,352,358,366,372,378,382,388,396,400,408,418,420,430,432,438,442,448,456,460,462,466,478,486,490,498,502,508,520,522,540,546,556,562,568,570,576,586,592,598,600,606,612,616,618,630,640,642,646,652,658,660,672,676,682,690,700,708,718,726,732,738,742,750,756,760,768,772,786,796,808,810,820,822,826,828,838,852,856,858,862,876,880,882,886,906,910,918,928,936,940,946,952,966,970,976,982,990,996,1008,1012,1018,1020,1030,1032,1038,1048,1050,1060,1062,1068,1086,1090,1092,1096,1102,1108,1116,1122,1128,1150,1152,1162,1170,1180,1186,1192,1200,1212,1216,1222,1228,1230,1236,1248,1258,1276,1278,1282,1288,1290,1296,1300,1302,1306,1318,1320,1326,1360,1366,1372,1380,1398,1408,1422,1426,1428,1432,1438,1446,1450,1452,1458,1470,1480,1482,1486,1488,1492,1498,1510,1522,1530,1542,1548,1552,1558,1566,1570,1578,1582,1596,1600,1606,1608,1612,1618,1620,1626,1636,1656,1662,1666,1668,1692,1696,1698,1708,1720,1722,1732,1740,1746,1752,1758,1776,1782,1786,1788,1800,1810,1822,1830,1846,1860,1866,1870,1872,1876,1878,1888,1900,1906,1912,1930,1932,1948,1950,1972,1978,1986,1992,1996,1998,2002,2010,2016,2026,2028,2038,2052,2062,2068,2080,2082,2086,2088,2098,2110,2112,2128,2130,2136,2140,2142,2152,2160,2178,2202,2206,2212,2220,2236,2238,2242,2250,2266,2268,2272,2280,2286,2292,2296,2308,2310,2332,2338,2340,2346,2350,2356,2370,2376,2380,2382,2388,2392,2398,2410,2416,2422,2436,2440,2446,2458,2466,2472,2476,2502,2520,2530,2538,2542,2548,2550,2556,2578,2590,2592,2608,2616,2620,2632,2646,2656,2658,2662,2670,2676,2682,2686,2688,2692,2698,2706,2710,2712,2718,2728,2730,2740,2748,2752,2766,2776,2788,2790,2796,2800,2802,2818,2832,2836,2842,2850,2856,2860,2878,2886,2896,2902,2908,2916,2926,2938,2952,2956,2962,2968,2970,2998,3000,3010,3018,3022,3036,3040,3048,3060,3066,3078,3082,3088,3108,3118,3120,3136,3162,3166,3168,3180,3186,3190,3202,3208,3216,3220,3228,3250,3252,3256,3258,3270,3298,3300,3306,3312,3318,3322,3328,3330,3342,3346,3358,3360,3370,3372,3388,3390,3406,3412,3432,3448,3456,3460,3462,3466,3468,3490,3498,3510,3516,3526,3528,3532,3538,3540,3546,3556,3558,3570,3580,3582,3592,3606,3612,3616,3622,3630,3636,3642,3658,3670,3672,3676,3690,3696,3700,3708,3718,3726,3732,3738,3760,3766,3768,3778,3792,3796,3802,3820,3822,3832,3846,3850,3852,3862,3876,3880,3888,3906,3910,3916,3918,3922,3928,3930,3942,3946,3966,3988,4000,4002,4006,4012,4018,4020,4026,4048,4050,4056,4072,4078,4090,4092,4098,4110,4126,4128,4132,4138,4152,4156,4158,4176,4200,4210,4216,4218,4228,4230,4240,4242,4252,4258,4260,4270,4272,4282,4288,4296,4326,4336,4338,4348,4356,4362,4372,4390,4396,4408,4420,4422,4440,4446,4450,4456,4462,4480,4482,4492,4506,4512,4516,4518,4522,4546,4548,4560,4566,4582,4590,4596,4602,4620,4636,4638,4642,4648,4650,4656,4662,4672,4678,4690,4702,4720,4722,4728,4732,4750,4758,4782,4786,4788,4792,4798,4800,4812,4816,4830,4860,4870,4876,4888,4902,4908,4918,4930,4932,4936,4942,4950,4956,4966,4968,4972,4986,4992,4998,5002,5008,5010,5020,5022,5038,5050,5058,5076,5080,5086,5098,5100,5106,5112,5118,5146,5152,5166,5170,5178,5188,5196,5208,5226,5230,5232,5236,5260,5272,5278,5280,5296,5302,5308,5322,5332,5346,5350,5380,5386,5392,5398,5406,5412,5416,5418,5430,5436,5440,5442,5448,5470,5476,5478,5482,5500,5502,5506,5518,5520,5526,5530,5556,5562,5568,5572,5580,5590,5622,5638,5640,5646,5650,5652,5656,5658,5668,5682,5688,5692,5700,5710,5716,5736,5740,5742,5748,5778,5782,5790,5800,5806,5812,5820,5826,5838,5842,5848,5850,5856,5860,5866,5868,5878,5880,5896,5902,5922,5926,5938,5952,5980,5986,6006,6010,6028,6036,6042,6046,6052,6066,6072,6078,6088,6090,6100,6112,6120,6130,6132,6142,6150,6162,6172,6196,6198,6202,6210,6216,6220,6228,6246,6256,6262,6268,6270,6276,6286,6298,6300,6310,6316,6322,6328,6336,6342,6352,6358,6360,6366,6372,6378,6388,6396,6420,6426,6448,6450,6468,6472,6480,6490,6520,6528,6546,6550,6552,6562,6568,6570,6576,6580,6598,6606,6618,6636,6652,6658,6660,6672,6678,6688,6690,6700,6702,6708,6718,6732,6736,6760,6762,6778,6780,6790,6792,6802,6822,6826,6828,6832,6840,6856,6862,6868,6870,6882,6898,6906,6910,6916,6946,6948,6958,6960,6966,6970,6976,6982,6990,6996,7000,7012,7018,7026,7038,7042,7056,7068,7078,7102,7108,7120,7126,7128,7150,7158,7176,7186,7192,7206,7210,7212,7218,7228,7236,7242,7246,7252,7282,7296,7306,7308,7320,7330,7332,7348,7350,7368,7392,7410,7416,7432,7450,7456,7458,7476,7480,7486,7488,7498,7506,7516,7522,7528,7536,7540,7546,7548,7558,7560,7572,7576,7582,7588,7590,7602,7606,7620,7638,7642,7648,7668,7672,7680,7686,7690,7698,7702,7716,7722,7726,7740,7752,7756,7758,7788,7792,7816,7822,7828,7840,7852,7866,7872,7876,7878,7882,7900,7906,7918,7926,7932,7936,7948,7950,7962,7992,8008,8010,8016,8038,8052,8058,8068,8080,8086,8088,8092,8100,8110,8116,8122,8146,8160,8166,8170,8178,8190,8208,8218,8220,8230,8232,8236,8242,8262,8268,8272,8286,8290,8292,8296,8310,8316,8328,8352,8362,8368,8376,8386,8388,8418,8422,8428,8430,8442,8446,8460,8466,8500,8512,8520,8526,8536,8538,8542,8562,8572,8580,8596,8598,8608,8622,8626,8628,8640,8646,8662,8668,8676,8680,8688,8692,8698,8706,8712,8718,8730,8736,8740,8746,8752,8760,8778,8782,8802,8806,8818,8820,8830,8836,8838,8848,8860,8862,8866,8886,8892,8922,8928,8932,8940,8950,8962,8968,8970,8998,9000,9006,9010,9012,9028,9040,9042,9048,9058,9066,9090,9102,9108,9126,9132,9136,9150,9156,9160,9172,9180,9186,9198,9202,9208,9220,9226,9238,9240,9256,9276,9280,9282,9292,9310,9318,9322,9336,9340,9342,9348,9370,9376,9390,9396,9402,9412,9418,9420,9430,9432,9436,9438,9460,9462,9466,9472,9478,9490,9496,9510,9520,9532,9538,9546,9550,9586,9600,9612,9618,9622,9628,9630,9642,9648,9660,9676,9678,9688,9696,9718,9720,9732,9738,9742,9748,9766,9768,9780,9786,9790,9802,9810,9816,9828,9832,9838,9850,9856,9858,9870,9882,9886,9900,9906,9922,9928,9930,9940,9948,9966,9972,10006}; +int main() +{ + int Q; + cin >> Q; + while(Q--) + { + int n; + cin >> n; + for(int i=0;i<10000;i++) + { + if(n<=test[i]) + { + cout << test[i]+1 << endl; + break; + } + } + } +} diff --git a/HDOJ/1796_autoAC.cpp b/HDOJ/1796_autoAC.cpp new file mode 100644 index 0000000..03def80 --- /dev/null +++ b/HDOJ/1796_autoAC.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +using namespace std; +int a[15]; +int n,m; +int gcd(int a,int b) +{ + if(!b) + return a; + else + return gcd(b,a%b); +} +int ans; +int kk; +void dfs(int val,int s,int k,int cnt) +{ + if(cnt>k) + return; + if(k==cnt) + { + if(cnt%2) + ans+=m/val; + else + ans-=m/val; + return; + } + for(int i=s+1;i<=kk;i++) + dfs(val/gcd(a[i],val)*a[i],i,k,cnt+1); +} +int main() +{ + int i; + while(scanf("%d%d",&m,&n)!=EOF) + { + m--; + kk=0; + for(i=1;i<=n;i++) + { + scanf("%d",&a[i]); + if(a[i]) + a[++kk]=a[i]; + } + ans=0; + for(i=1;i<=kk;i++) + dfs(1,0,i,0); + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1798_autoAC.cpp b/HDOJ/1798_autoAC.cpp new file mode 100644 index 0000000..1568019 --- /dev/null +++ b/HDOJ/1798_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +using namespace std; +struct circle +{ + double x,y,r; +}; +double dist(circle a,circle b) +{ + return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); +} +int main() +{ + circle a,b; + double d,p,area,sb,sa; + while(scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.r,&b.x,&b.y,&b.r)!=EOF) + { + d=dist(a,b); + double rr=min(a.r,b.r); + if(d<=abs(a.r-b.r)) + area=acos(-1.0)*rr*rr; + else + if(d>=a.r+b.r) + area=0.0; + else{ + p=(a.r+b.r+d)/2.0; + sa=acos((a.r*a.r+d*d-b.r*b.r)/(2.0*a.r*d)); + sb=acos((b.r*b.r+d*d-a.r*a.r)/(2.0*b.r*d)); + area=sa*a.r*a.r+sb*b.r*b.r-2*sqrt(p*(p-a.r)*(p-b.r)*(p-d)); + } + printf("%.3lf\n",area); + } + return 0; +} diff --git a/HDOJ/1799_autoAC.cpp b/HDOJ/1799_autoAC.cpp new file mode 100644 index 0000000..99b810e --- /dev/null +++ b/HDOJ/1799_autoAC.cpp @@ -0,0 +1,23 @@ +#include +#define MAXN 2000+10 +int a[MAXN][MAXN]={0}; +int main() +{ + int T,i,j; + for(i=0;i