Algorithm training of Quantum team (20190719)2

Algorithm training of Quantum team (20190719)2
A-Problem Description
Ignatius bought a land last week, but he didn’t know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?

Note: The point P1 in the picture is the vertex of the parabola.

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).

Output
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

Sample Input
2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222

Sample Output
33.33
40.69

Hint
For float may be not accurate enough, please use double instead of float.

只要想到了公式推导,知道二次函数和一次函数的表示形式,代入点的坐标推导就好了。
贴上网上看的一个推导,刚看到题目没头绪看完题解以后觉得只要耐下心来还是能做出来的。

推定积分公式。。。。

设直线方程:y=kx+t…………………………………………………………(1)
抛物线方程:y=ax^2+bx+c……………………………………………………(2)
已知抛物线顶点p1(x1,y1),两线交点p2(x2,y2)和p3(x3,y3)
斜率k=(y3-y2)/(x3-x2)……………………………………………………(3)
把p3点代入(1)式结合(3)式可得:t=y3-(kx3)
又因为p1是抛物线的顶点,可得关系:x1=-b/2a即b=-2a
x1………………(4)
把p1点代入(2)式结合(4)式可得:ax1x1-2ax1x1+c=y1化简得c=y1+ax1x1……(5)
把p2点代入(2)式结合(4)式和(5)式可得:a=(y2-y1)/((x1-x2)(x1-x2))
于是通过3点求出了k,t,a,b,c即两个方程式已求出
题目时求面积s
通过积分可知:s=f(x2->x3)(积分符号)(ax^2+bx+c-(kx+t))
=f(x2->x3)(积分符号)(ax^2+(b-k)x+c-t)
=a/3*x3+(b-k)/2*x2+(c-t)x
=a/3
x3x3x3+(b-k)/2x3x3+(c-t)x3-(a/3x2x2x2+(b-k)/2x2x2+(c-t)x2)
化简得:
面积公式:s=-(y2-y1)/((x2-x1)
(x2-x1))((x3-x2)(x3-x2)*(x3-x2))/6;

#include<bits/stdc++.h>

using namespace std;
int main() {
	double x1,x2,x3,y1,y2,y3;
	double k,t,a,b,c,s1,s2;
	int n;
	while(cin>>n)
		while(n--) {
			cin>>x1>>y1>>x2>>y2>>x3>>y3;
			k=(y3-y2)/(x3-x2);
			t=y3-k*x3;
			a=(y2-y1)/((x1-x2)*(x1-x2));
			b=-x1*2*a;
			c=y1-a*x1*x1-b*x1;
			s1=1.0/3*a*x2*x2*x2+1.0/2*(b-k)*x2*x2+x2*(c-t);
			s2=1.0/3*a*x3*x3*x3+1.0/2*(b-k)*x3*x3+x3*(c-t);
			printf("%.2lf\n",s2-s1);
		}
	return 0;
}
/*
2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222
*/
B - Deck 
A single playing card can be placed on a table, carefully, so that the short edges of the card are parallel to the table's edge, and half the length of the card hangs over the edge of the table. If the card hung any further out, with its center of gravity off the table, it would fall off the table and flutter to the floor. The same reasoning applies if the card were placed on another card, rather than on a table. 

Two playing cards can be arranged, carefully, with short edges parallel to table edges, to extend 3/4 of a card length beyond the edge of the table. The top card hangs half a card length past the edge of the bottom card. The bottom card hangs with only 1/4 of its length past the table's edge. The center of gravity of the two cards combined lies just over the edge of the table. 

Three playing cards can be arranged, with short edges parallel to table edges, and each card touching at most one other card, to extend 11/12 of a card length beyond the edge of the table. The top two cards extend 3/4 of a card length beyond the edge of the bottom card, and the bottom card extends only 1/6 over the table's edge; the center of gravity of the three cards lines over the edges of the table. 

If you keep stacking cards so that the edges are aligned and every card has at most one card above it and one below it, how far out can 4 cards extend over the table's edge? Or 52 cards? Or 1000 cards? Or 99999? 
Input
Input contains several nonnegative integers, one to a line. No integer exceeds 99999. 
Output
The standard output will contain, on successful completion of the program, a heading: 

# Cards Overhang 

(that's two spaces between the words) and, following, a line for each input integer giving the length of the longest overhang achievable with the given number of cards, measured in cardlengths, and rounded to the nearest thousandth. The length must be expressed with at least one digit before the decimal point and exactly three digits after it. The number of cards is right-justified in column 5, and the decimal points for the lengths lie in column 12. 
Sample Input
1 
2 
3 
4 
30 
Sample Output
The line of digits is intended to guide you in proper output alignment, and is not part of the output that your solution should produce. 

12345678901234567
# Cards  Overhang
    1     0.500
    2     0.750
    3     0.917
    4     1.042
   30     1.997
#include <stdio.h>
double a[100010];
int main() {
    int n;
    a[1]=0.5;
    for (int i=2; i<=100000; i++) {
        a[i]=a[i-1]+1.0/2/i;
    }
    printf("# Cards  Overhang\n");
    while (scanf("%d",&n)!=EOF) {
        printf("%5d%10.3lf\n",n,a[n]);
    }
    return 0;
}

C - Big Event in HDU
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don’t know that Computer College had ever been split into Computer College and Software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 – the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
Sample Output
20 10
40 40

#include<bits/stdc++.h>

using namespace std;

const int N=250005;
int dp[N],val[5005];
int main() {
	int n;
	while(~scanf("%d",&n),n>0) {
		memset(dp,0,sizeof(dp));
		memset(val,0,sizeof(val));
		int a,b,sum=0,t=0;
		for(int i=0; i<n; i++) {
			scanf("%d%d",&a,&b);
			while(b--) {
				val[t++]=a;
				sum+=a;
			}
		}
		for(int i=0; i<t; i++) {
			for(int j=sum/2; j>=val[i]; j--) {
				dp[j]=max(dp[j],dp[j-val[i]]+val[i]);
			}
		}
		printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);
	}
	return 0;
}
/*
2
10 1
20 1
3
10 1 
20 2
30 1
-1
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值