标签:
1.http://acm.hdu.edu.cn/showproblem.php?pid=5112
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 100000+10;
struct Node{
int t;
int x;
bool operator<(Node&a){
return t < a.t;
}
};
Node S[MAXN];
int main(){
int i, T,n;
int iCase = 1;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &S[i].t, &S[i].x);
sort(S, S + n);
double Max = 0;
for (i = 0; i < n - 1; i++){
double v = abs(S[i + 1].x - S[i].x)*1.0 / (S[i + 1].t - S[i].t);
Max = max(Max, v);
}
printf("Case #%d: %.2lf\n",iCase++, Max);
}
return 0;
}
2.http://acm.hdu.edu.cn/showproblem.php?pid=5122
一开始一看到以为求逆序来搞,一看题就写了个数状数组,nlogn超时了。当然一定是太性急了,这个题其实就是判断下它后面是否有数字比它小,有的话需要将其往后移一次,否则不变。这样只需要判断下每个数后面是否有有比它小的数,于是将数组倒置,即为判断每个数前面是否有比它大的数,只需要从前向后扫描一遍,需要一个数Min记录当前已扫描结束的序列中最小的数。这样只要碰到后迷死你右数大于这个最小的数就计数一次,否则更新这个Min。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 10000001;
int a[MAXN];
int main(){
int i, T, n;
int iCase = 1;
scanf("%d", &T);
while (T--){
scanf("%d", &n);
for (i = n; i > 0; i--)
scanf("%d", &a[i]);
int Min = a[1];
int ans = 0;
for (i = 2; i <= n; i++){
if (a[i] > Min)
ans++;
else
Min = a[i];
}
printf("Case #%d: %d\n",iCase++,ans);
}
return 0;
}
3.http://acm.hdu.edu.cn/showproblem.php?pid=5120
模板很重要啊。这里主要的是求两个圆相交的面积,有了模板直接搞。最终面积=大圆交大圆-2*大圆交小圆+小圆交小圆。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS = 1e-8;
const double pi = acos(-1.0);
struct Point{
double x, y;
Point(double a=0, double b=0) :x(a), y(b){}
};
struct Circle{
Circle(Point a, double x) :o(a), r(x){}
Point o;
double r;
};
int RlCmp(double r1, double r2){
if (abs(r1 - r2) < EPS)
return 0;
return r1 < r2 ? -1 : 1;
}
Point operator-(Point a, Point b){
return Point(a.x - b.x, a.y - b.y);
}
Point operator+(Point a, Point b){
return Point(a.x + b.x, a.y + b.y);
}
double Mold(Point a){
return sqrt(a.x*a.x + a.y*a.y);
}
double Dis(Point a, Point b){
return Mold(a - b);
}
//园与圆相交面积模板
double CircleCrossArea(Circle A,Circle B){
double r1 = A.r, r2 = B.r;
double d = Dis(A.o, B.o),r=min(r1,r2);
if (RlCmp(d, r1 + r2) >= 0)
return 0; //相离或者外切
if (RlCmp(d, abs(r1 - r2)) <= 0)
return pi*r*r; //内含
//将r1放在圆心
double x1 = (d*d + r1*r1 - r2*r2) / (2 * d);
double s1 = x1*sqrt(r1*r1 - x1*x1) - r1*r1*acos(x1/r1);
//将r2放在圆心
double x2 = (d*d + r2*r2 - r1*r1) / (2 * d);
double s2 = x2*sqrt(r2*r2 - x2*x2) - r2*r2*acos(x2 / r2);
return abs(s1 + s2);
}
int main(){
int T, iCase = 1;
Point q,o;
double r1, r2;
scanf("%d", &T);
while (T--){
scanf("%lf%lf",&r1,&r2);
scanf("%lf%lf",&q.x,&q.y);
scanf("%lf%lf", &o.x,&o.y);
Circle A1(q, r1);
Circle A2(q, r2);
Circle B1(o, r1);
Circle B2(o, r2);
double a = CircleCrossArea(A2, B2);
double b = CircleCrossArea(A2, B1);
double c = CircleCrossArea(A1, B1);
printf("Case #%d: %.6lf\n", iCase++, a - 2 * b + c);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/td15980891505/p/5757553.html