码迷,mamicode.com
首页 > 其他好文 > 详细

CF 996B World Cup 【找规律/模拟】

时间:2018-07-02 01:17:48      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:can   include   names   .com   com   namespace   答案   turn   \n   

CF
【题意】:圆形球场有n个门,Allen想要进去看比赛。Allen采取以下方案进入球场:开始Allen站在第一个门,如果当前门前面有人Allen会花费单位时间走到下一个门,如果没人Allen从这个门就进去了。球场的每个门,每单位时间可以进去一个人。问Allen最终是从哪个门进入球场的?
【分析】:我们可以发现是有规律的。我们假设第i个门有a个人,Allen第x圈可以从此进入,那么有:x?n+i=a→x=abs(a?i)/n,所以第一个最小圈数进入的那个门就是答案。
【代码】:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
const int INF = 0x3f3f3f3f;
int n, ans;
int main()
{
    scanf("%d", &n);
    int MIN = INF;
    for (int i = 1; i <= n; i++)
    {
        int a; 
        scanf("%d", &a);
        if(MIN > (a-i+n)/n)//x*n+i=a =》x=abs(a-i)/n
        {
            MIN = (a-i+n)/n;
            ans = i;
        }
    }
    printf("%d\n", ans);
    return 0;
}

CF 996B World Cup 【找规律/模拟】

标签:can   include   names   .com   com   namespace   答案   turn   \n   

原文地址:https://www.cnblogs.com/Roni-i/p/9251862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!