Children's Day
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 239 Accepted Submission(s): 138
For example, this is a big 'N' start with 'a' and it's size is 3.
a e bdf c g
Your task is to write different 'N' from size 3 to size 10. The pixel character used is from 'a' to 'z' continuously and periodic('a' is reused after 'z').
[pre] a e bdf c g h n i mo jl p k q ......... r j [/pre]HintNot all the resultsare listed in the sample. There are just some lines. The ellipsis expresseswhat you should write.
#include<iostream> #include<cstring> #include<string> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; char a[12][12]; int main() { int i,j,k; a[0][0]='a'; a[0][1]=' '; a[0][2]='e'; a[0][3]='\0'; a[1][0]='b'; a[1][1]='d'; a[1][2]='f'; a[1][3]='\0'; a[2][0]='c'; a[2][1]=' '; a[2][2]='g'; a[2][3]='\0'; cout<<a[0]<<endl; cout<<a[1]<<endl; cout<<a[2]<<endl; for(i=3;i<10;i++) { char p=a[i-1][i-1]; for(j=0;j<=i;j++) for(k=0;k<=i;k++) a[j][k]=' '; a[0][0]=p+1; if(a[0][0]>'z') a[0][0]='a'; for(j=1;j<=i;j++) { a[j][0]=a[j-1][0]+1; if(a[j][0]>'z') a[j][0]='a'; } for(j=i-1;j>=0;j--) { a[j][i-j]=a[j+1][i-j-1]+1; if(a[j][i-j]>'z') a[j][i-j]='a'; } for(j=1;j<=i;j++) { a[j][i]=a[j-1][i]+1; if(a[j][i]>'z') a[j][i]='a'; } for(j=0;j<=i;j++) a[j][i+1]='\0'; for(j=0;j<=i;j++) cout<<a[j]<<endl; } return 0; }
Herding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 575 Accepted Submission(s): 128
(Xi, Yi). To herding his cattles safely, the easiest way is to connect some of the trees (with different numbers, of course) with fences, and the close region they formed would be herding area. Little John wants the area of this region to be as small as possible,
and it could not be zero, of course.
The first line of each test case contains one integer N( 1<=N<=100 ). The following N lines describe the coordinates of the trees. Each of these lines will contain two float numbers Xi and Yi( -1000<=Xi, Yi<=1000 ) representing the coordinates of the corresponding
tree. The coordinates of the trees will not coincide with each other.
1 4 -1.00 0.00 0.00 -3.00 2.00 0.00 2.00 2.00
2.00
题目大意:很多点,找能围成的最小面积,肯定是三角形啊。没有的话需要输出Impossible。只需要判断三点共线即可。
#include<iostream> #include<cstring> #include<string> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; double a[105],b[105]; double eps=0.0000000001; int main() { int tes,n,i,j,k; scanf("%d",&tes); while(tes--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&a[i],&b[i]); double res=1000000000; //初始化最大面积 for(i=0;i<n;i++) for(j=i+1;j<n;j++) for(k=j+1;k<n;k++) { double x1,y1,x2,y2,x3,y3; x1=a[i],y1=b[i],x2=a[j],y2=b[j],x3=a[k],y3=b[k]; if(abs((y3-y2)*(x2-x1)-(y2-y1)*(x3-x2))>eps) { double a,b,c,p; //海伦公式求三角形的面积 a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); b=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)); c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)); p=(a+b+c)/2.0; double tmp=sqrt(p*(p-a)*(p-b)*(p-c)); if(tmp<res) res=tmp; } } if(res==1000000000) cout<<"Impossible"<<endl; else printf("%.2f\n",res); } return 0; }
Balls Rearrangement
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 196 Accepted Submission(s): 93
Some day Bob buys B new boxes, and he wants to rearrange the balls from the old boxes to the new boxes. The new boxes are numbered from 0 to B-1. After the rearrangement, the ball numbered x should be in the box number b if x = b mod B.
This work may be very boring, so he wants to know the cost before the rearrangement. If he moves a ball from the old box numbered a to the new box numbered b, the cost he considered would be |a-b|. The total cost is the sum of the cost to move every ball, and
it is what Bob is interested in now.
Then T test case followed. The only line of each test case are three integers N, A and B.(1<=N<=1000000000, 1<=A,B<=100000).
3 1000000000 1 1 8 2 4 11 5 3
0 8 16
先前自己A的一道原题啊,可以博客:HDU 4611Balls Rearrangement(思维)
Difference Between Primes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 561 Accepted Submission(s): 170
you are asked to write a program.
3 6 10 20
11 5 13 3 23 3
#include<iostream> #include<cstring> #include<string> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int M=10000; int mark[M]; int prim[M]; void sxprime() { memset(mark,1,sizeof(mark)); mark[0]=mark[1]=0; for(int i=2; i<=sqrt((double)M); i++) { if(mark[i]) { for(int j=i*i; j<M; j+=i) mark[j]=0; } } } bool isprim(int u) { if(u==0||u==1) return false; if(u==2) return true; if(u%2==0) return false; for(int i=3; i<=sqrt((double)u); i+=2) if(u%i==0) return false; return true; } int main() { int i,tes; int p=0,x; sxprime(); for(i=1; i<=M; i++) { if(mark[i]) prim[p++]=i; } scanf("%d",&tes); while(tes--) { scanf("%d",&x); int flag=0; if(x==0) { cout<<"2 2"<<endl; continue; } if(x>0) { for(i=0; i<p; i++) if(isprim(x+prim[i])) { cout<<x+prim[i]<<" "<<prim[i]<<endl; flag=1; break; } if(flag==0) cout<<"FAIL"<<endl; } else { x=-x; for(i=0; i<p; i++) if(isprim(x+prim[i])) { cout<<prim[i]<<" "<<x+prim[i]<<endl; flag=1; break; } if(flag==0) cout<<"FAIL"<<endl; } } return 0; }