题目列表
A. A Greeting from Qinhuangdao
题意:
有r个红球,b个蓝球;取两次,求两次都是红球的概率;
思路:
ans=r*(r-1)/((r+b)*(r+b-1));
代码:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#define ll long long
using namespace std;
const int N = 1e6 + 10;
int main() {
int T;
scanf("%d", &T);
for (int cas = 1; cas <= T; cas++) {
int r,b;
scanf("%d%d",&r,&b);
int x=r*(r-1);
int y=(r+b)*(r+b-1);
if(x!=0){
int k=__gcd(x,y);
x=x/k;
y=y/k;
}
else{
y=1;
}
printf("Case #%d: %d/%d\n", cas, x,y);
}
return 0;
}
C. Cameraman(计算几何)
题意:
思路:
代码:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
const double pi = acos(-1.0); // 高精度圆周率
const double eps = 1e-8; //偏差值
int sgn(double x) {
//判断x是否等于0
if (fabs(x) < eps)
return 0;
else
return x < 0 ? -1 : 1;
}
int dcmp(double x, double y) {
//比较两个浮点数:0为相等;-1为小于;1为大于
if (fabs(x - y) < eps)
return 0;
else
return x < y ? -1 : 1;
}
//点
struct Point {
double x, y;
Point() {
}
Point(double x, double y) : x(x), y(y) {
}
//向量运算
Point operator+(Point B) {
return Point(x + B.x, y + B.y); }
Point operator-(Point B) {
return Point(x - B.x, y - B.y); }
Point operator*(double k) {
return Point(x * k, y * k); }
Point operator/(double k) {
return Point(x / k, y / k); }
bool operator==(Point B) {
return sgn(x - B.x) == 0 && sgn(y - B.y) == 0; }
};
//向量
typedef Point Vector;
//点积
//若dot(A,B)>0,A与B的夹角为锐角;
//若dot(A,B)<0,A与B的夹角为钝角;
//若dot(A,B)=0,A与B的夹角为直角;
double Dot(Vector A, Vector B) {
return A.x * B.x + A.y * B.y;
}
//求向量A的长度
double Len(Vector A) {
return sqrt(Dot(A, A));
}
//叉积
//叉积有正负
// AXB>0,B在A的逆时针方向
// AXB<0,B在A的顺时针方向
// AXB=0,B与A共线,方向不确定
double Cross(Vector A, Vector B) {
return A.x * B.y - A.y * B.x;
}
//直线
struct Line {
Point p1, p2;
Line() {
}
//两点式确定直线
Line(Point p1, Point p2) : p1(p1), p2(p2) {
}
//点斜式确定直线,0<=angle<pi
Line(Point p, double angle) {
p1 = p;
if (sgn(angle - pi / 2) == 0) {
p2 = (p1 + Point(0, 1));
} else {
p2 = (p1 + Point(1, ta