2019 ICPC 南京区域赛-H Prince and Princess

题目链接

Prince Mochi of the Mochi Kingdom falls in love with Princess Tofu of the Tofu Kingdom, but the queen of the Tofu Kingdom does not assent to this marriage.The queen challenges their love and advocates a task for Prince Mochi.Solving this task is the premise for earning their happiness. The lack of capacity obliges Prince Mochi to ask you for help.Here is the task: Princess Tofu, King Tofu, the queen, the minister, maids, chefs, and many others are all together for the task, all staying in separate rooms. Note that there is no empty room. Each one of them knows where he/she is and where any other people are.Prince Mochi is asked to find the princess. He can inquire anyone about the following three types of questions:
Who are you?
Who is staying in a specified room?
Which room does the Princess Tofu stay in?
They will never refuse to answer the questions, but may not tell the truth. People, including Princess Tofu herself, who support this marriage will present the facts. The opposition, like the queen, will always provide an incorrect answer. Other participants will be arbitrary.Prince Mochi does not want to spend too much time and so he will query as little as possible. Can you tell him the minimum number of questions he really needs to confirm where his darling is under any circumstances? But sometimes, the task is impossible, then you should also remind him to begin a new love affair.

Input
The only line in input contains three integers a (1≤a≤2×105), b and c (0≤b,c≤2×105) which represent the number of participants who support this marriage, who are against this marriage and who do not really care about it respectively.

Output
If it is impossible to determine where Prince Mochi is, output NO. Otherwise, output YES at first following an integer indicating the minimum number of questions the prince needs to inquire in the second line.

1.题意:有a个只说真话的人(其中一位是公主),b个只说假话的人,c个回答可以为真可以为假的人。向这些人进行询问,可以进行三种询问,分别为询问回答者的身份,其他任意一个人的身份或谁是公主

2.博弈论嘛,模拟即可。其实发现问什么问题不重要,只要a>b+c,就一定YES,问的人数就是2*(b+c)+1。但这还不够,仔细观察下面这句话:
They will never refuse to answer the questions, but may not tell the truth. People, including Princess Tofu herself, who support this marriage will present the facts.
意思是,公主也在支持者的范围内,可能会问到公主。也就是支持者至少有一个人,即公主。如果这个理解不了的话看a的范围(1≤a≤2×105)。所以就是当a为1且a>b+c时,什么都不要问,请他们立刻原地结婚

3.你会发现,多读几遍题目并不是坏事,可能经常有遗漏的细节

代码:

#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>(b+c)){
        if(a==1)
            printf("YES\n0");
        else printf("YES\n%d",2*(b+c)+1);
    }else printf("NO\n");
    return 0;
}

你可能感兴趣的:(ICPC,Contests)