Codeforces 掉分记 round316(div2)

Codeforces 掉分记 round316(div2)

昨晚打了最近最惨的一场比赛,cf的A题WA了5发,用了将近一个小时,简直不能看,以后读题要仔细,着急做题只能起到反作用。

A题

题目描述

The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.

The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.

At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.

Determine who will win the elections.

题意

就是有N个候选人,M个城市,每个候选人在不同城市有不同的得票,一个候选人在某个城市得到最多的票就可以赢得一轮选举,第二轮选举胜出的条件是在最多的城市胜出,最后输出候选人的序号。题读懂了就能做。

B题

题目描述

One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let’s assume that Misha chose number m, and Andrew chose number a.

Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.

Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.

More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).

题意

是你和另一个人分别从选1到n中选一个数字a,b,再随机出一个c,选择的数字最接近c的那个人赢,距离一样时候你输。给你n和a(那个人选的数字),你输出获胜概率最大的数字b.

解法

机智题,a将1到n划分成了两个区间,如图
这里写图片描述
b紧邻a并在较大区间的时候即是最优解。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M;
    scanf("%d%d",&N,&M);
    if(N == 1)
    {
        printf("1\n");
        return 0;
    }
    if(N%2)
    {
        int mid = (N + 1)/2;
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值