hdu1071
来源:互联网 发布:java获取文件夹的路径 编辑:程序博客网 时间:2024/05/24 15:39
#include<stdio.h>
#include<iostream>
using namespace std;
struct point
{
double x,y;
}po[3];
double find_a(double x,double y,double x0,double y0)
{
return (y-y0)/((x-x0)*(x-x0));
}
double find_b(double x1,double y1,double x2,double y2)
{
return y1-((y2-y1)/(x2-x1))*x1;
}
int main()
{
freopen("in1.txt","r",stdin);
int t;
int i;
double a;
double b;
double sum=0;
cin>>t;
while(t--)
{
sum=0;
for(i=0;i<3;i++)
{
cin>>po[i].x>>po[i].y;
}
a=find_a(po[1].x,po[1].y,po[0].x,po[0].y);
//cout<<"a="<<a<<endl;
b=find_b(po[1].x,po[1].y,po[2].x,po[2].y);
//cout<<"b="<<b<<endl;
//cout<<"k="<<((po[1].y-po[2].y)/(po[1].x-po[2].x))<<endl;;
int num=(int)(po[1].x-po[2].x)+1;
double delt=1.0/1000;
double y;
int c=0;
for(double pos=po[1].x;pos<=po[2].x;)
{
if(a<0)
{
y=(a*(pos-po[0].x)*(pos-po[0].x)+po[0].y)-(((po[1].y-po[2].y)/(po[1].x-po[2].x))*pos+b);
sum+=y*delt;
pos+=delt;
c++;
if(c==1000)
{
c=0;
//cout<<"x="<<pos<<",y1="<<(a*(pos-po[0].x)*(pos-po[0].x)+po[0].y)<<",y2="<<(((po[1].y-po[2].y)/(po[1].x-po[2].x))*pos+b)<<endl;
}
}
else
{
y=(((po[1].y-po[2].y)/(po[1].x-po[2].x))*pos+b)-(a*(pos-po[0].x)*(pos-po[0].x)+po[0].y);
sum+=y*delt;
pos+=delt;
}
}
printf("%.2lf\n",sum);
}
return 0;
}
#include<iostream>
using namespace std;
struct point
{
double x,y;
}po[3];
double find_a(double x,double y,double x0,double y0)
{
return (y-y0)/((x-x0)*(x-x0));
}
double find_b(double x1,double y1,double x2,double y2)
{
return y1-((y2-y1)/(x2-x1))*x1;
}
int main()
{
freopen("in1.txt","r",stdin);
int t;
int i;
double a;
double b;
double sum=0;
cin>>t;
while(t--)
{
sum=0;
for(i=0;i<3;i++)
{
cin>>po[i].x>>po[i].y;
}
a=find_a(po[1].x,po[1].y,po[0].x,po[0].y);
//cout<<"a="<<a<<endl;
b=find_b(po[1].x,po[1].y,po[2].x,po[2].y);
//cout<<"b="<<b<<endl;
//cout<<"k="<<((po[1].y-po[2].y)/(po[1].x-po[2].x))<<endl;;
int num=(int)(po[1].x-po[2].x)+1;
double delt=1.0/1000;
double y;
int c=0;
for(double pos=po[1].x;pos<=po[2].x;)
{
if(a<0)
{
y=(a*(pos-po[0].x)*(pos-po[0].x)+po[0].y)-(((po[1].y-po[2].y)/(po[1].x-po[2].x))*pos+b);
sum+=y*delt;
pos+=delt;
c++;
if(c==1000)
{
c=0;
//cout<<"x="<<pos<<",y1="<<(a*(pos-po[0].x)*(pos-po[0].x)+po[0].y)<<",y2="<<(((po[1].y-po[2].y)/(po[1].x-po[2].x))*pos+b)<<endl;
}
}
else
{
y=(((po[1].y-po[2].y)/(po[1].x-po[2].x))*pos+b)-(a*(pos-po[0].x)*(pos-po[0].x)+po[0].y);
sum+=y*delt;
pos+=delt;
}
}
printf("%.2lf\n",sum);
}
return 0;
}
0 0
- HDU1071
- HDU1071
- HDU1071
- hdu1071
- hdu1071
- HDU1071
- hdu1071
- HDU1071
- HDU1071
- HDU1071(数学题)
- hdu1071 (积分求面积)
- hdu1071(积分求面积)
- HDU1071-抛物线积分
- HDU1071-能量守恒
- 第二周hdu1071
- HDU1071 The area 【积分】
- Hdu1071 The area
- hdu1071数学题 The area
- WPF学习开发历程(一)——明天开始学习
- STL之list容器详解
- Linux内核switch_to宏实现进程切换的原理
- 29. 继承
- java数据库连接池封装及使用
- hdu1071
- Effective Objective-C 2.0 第6条:理解“属性”
- Android学习——状态栏通知
- win7使用eclipse连接hadoop集群,运行mapreduce报错之Failed to set permissions of path
- docker 入门准备step1
- 函数传递const和非const非引用参数的笔记 - 20150905
- 腾讯大数据之新一代资源管理与调度平台
- Word Ladder
- 1028. List Sorting (25)