跳到正文

题解

英文题解:P11868 抽卡

easy42约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月20日
篇幅
约 1 分钟
题目
P11868

版本

  1. v1当前

中文。

Promote my blog.

First, consider the greedy algorithm. Assume that the guesses are always correct, so discuss different cases.

  1. a<ba < b

Reduce one card from the bb types.

  1. a>ba > b

Reduce one card from the aa types.

  1. a=ba = b

Reduce one card from either the aa types or the bb types. Since they are equal, it doesn’t matter which one to reduce.

Code:

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,t;
signed main(){
    cin>>a>>b;
    while(a!=0||b!=0){
        if(a<b) b--,t++;
        else if(a>b) a--,t++;
        else a--;
    }
    printf("%.8f",t*1.0);
    return 0;
}
原文