题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2056
该题Output Limit Exceeded,可能是考虑情况太少了!
下面的代码Output Limit Exceeded了
View Code
#include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; int main(int argc, char *argv[]) { double a[8]={0}; //int n=2; while(1) { double x=0,y=0; double area=0; for(int i=0;i<8;i++) cin>>a[i]; if(a[0]>a[4]) { x=a[6]-a[0]; y=a[7]-a[1]; area=x*y; printf("%.2lf\n",area); } if(a[0]<a[4]) { x=a[2]-a[4]; y=a[3]-a[5]; area=x*y; printf("%.2lf\n",area); } } system("PAUSE"); return EXIT_SUCCESS; }
解决它~~~~~~~~~
下面的代码Time Limit Exceeded了
View Code
#include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; int main(int argc, char *argv[]) { double a[8]={0}; //int n=2; while(1) { double x1=0,y1=0,x2=0,y2=0; double area=0; for(int i=0;i<8;i++) cin>>a[i]; if(a[0]>a[4]) x1=a[0]; else x1=a[4]; if(a[1]>a[5]) y1=a[1]; else y1=a[5]; if(a[2]>a[6]) x2=a[6]; else x2=a[2]; if(a[3]>a[7]) y2=a[7]; else y2=a[3]; if(x2>x1&&y2>y1) { area=(x2-x1)*(y2-y1); printf("%.2lf\n",area); } } system("PAUSE"); return EXIT_SUCCESS; }
继续ing··························