标签:des style blog http color java os io strong
Description
Input
Output
Sample Input
Sample Output
分析:
最好的方法就是将输入的数组去除空行 \n,\t然后再两两进行比较
代码:
#include<stdio.h> #include<string.h> const int maxn=5001; char s1[maxn],s2[maxn]; void input(char *s) { char temp[maxn]; gets(temp); while(strcmp(temp,"START")!=0) gets(temp); while(gets(temp)) { if(strcmp(temp,"END")==0) break; if(strlen(temp)!=0) strcat(s,temp); strcat(s,"\n"); } } void del(char *s,int l) { char temp[maxn]; int i,j; j=0; for(i=0;i<l;i++) { if(s[i]!=‘ ‘&&s[i]!=‘\n‘&&s[i]!=‘\t‘) temp[j++]=s[i]; } temp[j]=‘\0‘; strcpy(s,temp); } int sum() { int l1,l2; l1=strlen(s1); l2=strlen(s2); if(l1==l2&&strcmp(s1,s2)==0) return 1; del(s1,l1); del(s2,l2); if(strcmp(s1,s2)==0) return 0; else return -1; } int main() { int T,count; scanf("%d",&T); while(T--) { input(s1); input(s2); count=sum(); if(count==1) printf("Accepted\n"); else if(count==0) printf("Presentation Error\n"); else printf("Wrong Answer\n"); } return 0; }
#include<stdio.h> #include<string.h> const int maxn=5001; char s1[maxn],s2[maxn],t1[maxn],t2[maxn]; char temp[maxn]; void input(char *s,char *t) { gets(temp); while(strcmp(temp,"START")!=0) gets(temp); while(gets(temp)) { if(strcmp(temp,"END")==0) break; if(strlen(temp)!=0) strcat(s,temp); strcat(s,"\n"); } int k=0; int l=strlen(s); int i; for(i=0;i<l;i++) { if(s[i]!=‘ ‘&&s[i]!=‘\n‘&&s[i]!=‘\t‘) t[k++]=s[i]; } t[k]=‘\0‘; } int main() { int T; scanf("%d",&T); while(T--) { s1[0]=‘\0‘; s2[0]=‘\0‘; input(s1,t1); input(s2,t2); if(strcmp(s1,s2)==0) printf("Accepted\n"); else if(strcmp(t1,t2)==0) printf("Presentation Error\n"); else printf("Wrong Answer\n"); } return 0; }
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <vector> #include <cmath> #include <cstdio> using namespace std; #ifdef __int64 typedef __int64 LL; #else typedef long long LL; #endif const int inf=0x3f3f3f3f; const int maxn=5050; char t[maxn],as[maxn],bs[maxn],ap[maxn],bp[maxn]; int main() { int n,ca,cb; scanf("%d",&n); getchar(); while(n--) { gets(t); memset(t,0,sizeof(t)); memset(as,0,sizeof(as)); memset(bs,0,sizeof(bs)); memset(ap,0,sizeof(ap)); memset(bp,0,sizeof(bp)); ca=cb=0; while(gets(t)) { if(strcmp(t,"END")==0) break; strcat(as,t); ca++; } gets(t); while(gets(t)) { if(strcmp(t,"END")==0) break; strcat(bs,t); cb++; } if(ca==cb&&strcmp(as,bs)==0) printf("Accepted\n"); else { int la=strlen(as),lb=strlen(bs); int lla=0,llb=0; for(int i=0;i<la;i++) { if(as[i]!=‘ ‘&&as[i]!=‘\n‘&&as[i]!=‘\t‘) ap[lla++]=as[i]; } for(int i=0;i<lb;i++) { if(bs[i]!=‘ ‘&&bs[i]!=‘\n‘&&bs[i]!=‘\t‘) bp[llb++]=bs[i]; } if(strcmp(ap,bp)==0) printf("Presentation Error\n"); else printf("Wrong Answer\n"); } } return 0; }
Description
Input
Output
Sample Input
Sample Output
Hint
For float may be not accurate enough, please use double instead of float.
分析:
一道高数题 就是求出曲线和直线的方程在积分就好了!(曲线的方程可用顶点式 y = a(x-h)^2+l, (h,L) 为顶点坐标)
代码:
1.
#include<stdio.h> int main() { int n; double x1,x2,x3,y1,y2,y3; double s,a,b,c,k,h; while(~scanf("%d",&n)) { while(n--) { scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3); a=(y2-y1)/((x2-x1)*(x2-x1)); b=-2*a*x1; c=y1-a*x1*x1-b*x1; k=(y2-y3)/(x2-x3); h=y2-k*x2; s=(a*(x3*x3*x3-x2*x2*x2)/3)+((b-k)*(x3*x3-x2*x2)/2)+((c-h)*(x3-x2)); printf("%.2lf\n",s); } } return 0; }
2.
这里我们设抛物线顶点式方程y=a*(x-h)^2+k;顶点坐标为(h,k)。h=x1;k=y1;a=(y-k)/(x-h)^2;
由积分可得(x2,x3)之间的面积,再减去梯形的面积即可
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <vector> #include <cstdio> #include <cmath> using namespace std; #ifdef __int64 typedef __int64 LL; #else typedef long long LL; #endif const int inf = 0x3f3f3f3f; const int maxn = 100000; int main() { int n; double x1,y1,x2,y2,x3,y3; scanf("%d",&n); while(n--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); double b=x1; double c=y1; double a=(y2-c)/(x2-b)/(x2-b); double k=(y3-y2)/(x3-x2); double b1=y2-k*x2; double s1=a*x3*x3*x3/3-(2*a*b+k)*x3*x3/2+(a*b*b+c-b1)*x3; double s2=a*x2*x2*x2/3-(2*a*b+k)*x2*x2/2+(a*b*b+c-b1)*x2; printf("%.2f\n",s1-s2); } return 0; }
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/lipching/p/3931393.html