2020CCPC秦皇岛站(2020 China Collegiate Programming Contest Qinhuangdao Site)

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, 
  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值