https://codeforces.com/problemset/problem/996/B

题意:

圆形球场有n个门,Allen想要进去看比赛。Allen采取以下方案进入球场:开始Allen站在第一个门,如果当前门前面有人Allen会花费单位时间走到下一个门,如果没人Allen从这个门就进去了。

球场的每个门,每单位时间可以进去一个人。问Allen最终是从哪个门进入球场的?

一样的代码

有点恶心人啊。

代码:

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=1e5+;
using namespace std; int a[maxn]; int main()
{
int n;
scanf("%d",&n);
int ans;
int flag=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(flag&&a[i]<i)
{
flag=;
ans=i;
}
}
int Index=;
int cnt=;
while(flag)
{
if(Index>n)
Index=;
if(a[Index]<=cnt)
{
flag=;
ans=Index;
}
cnt++;
Index++;
}
printf("%d\n",ans);
return ;
}

另一种思路:

假设第i个门一开始有a个人,k是走过的圈数即第k圈可进入,推出一道公式k∗n+i=a,求最小k所对应的i即可(注意求k的时候a-i可能小于0,这时候都加上n,不影响最后结果,这里比较费劲得理解一下)

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
typedef long long int LL;
const int MAXN=1e5+;
const int INF = 0x3f3f3f3f;
int main()
{
int n,a,ans,min1;
scanf("%d",&n);
min1=INF;
for(int i=;i<=n;i++)
{
scanf("%d",&a);
int x=a-i+n; if(min1>x/n)
{
min1=x/n;
ans=i;
}
}
printf("%d\n",ans);
}

CodeForces 996B World Cup(思维)的更多相关文章

  1. [codeforces Mail.Ru Cup 2018 Round 3][B Divide Candies ][思维+数学]

    https://codeforces.com/contest/1056/problem/B 题意:输入n,m    求((a*a)+(b*b))%m==0的(a,b)种数(1<=a,b<= ...

  2. 【Codeforces 996B】World Cup

    [链接] 我是链接,点我呀:) [题意] [题解] 你可以找出来a[i]里面的最小值mi,显然是这个数字最可能先变成0,但还不确定. 然后用mi/n得到你最少需要走多少圈才能让那个mi变成" ...

  3. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  4. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  5. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  6. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  7. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  8. Codeforces 675C Money Transfers 思维题

    原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...

  9. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

随机推荐

  1. Distributed--2PC和3PC

    参考 https://blog.csdn.net/lnho2015/article/details/78685503 https://www.cnblogs.com/hubaoxi/p/6867203 ...

  2. python类、super函数

    #PYTHON语言及其应用学习笔记 1.创建简单的类 class Person(): #python中特殊的对象初始化方法__init__,一个特殊的函数名 #当你在类声明里定义__init__()方 ...

  3. Ubuntu 安装VirtualBox 虚拟机

    转载 1.终端命令 编辑sources.list ? 1 sudo gedit /etc/apt/sources.list 2.添加 软件源 将下面的地址加入sources.list 的末尾,保存并退 ...

  4. 创建了以个vagrant box centos php7 nginx swoole git

    php7.2.9 centos7  nginx.1.16  swoole4.4.4 下载地址 链接:https://pan.baidu.com/s/14p7xIa0ZZigRuYvZxnMsYA 提取 ...

  5. Docker部署NETCORE应用程序

    Docker部署NETCORE应用程序 创建.netcore项目,本文以ASP.NET Core2.2 版本为例 设置Dockerfile属性始终复制 编辑Dockerfile内容 FROM micr ...

  6. 实验吧-密码学-js(Chrome用console.log调试js)

    题目就是js,可能就是一个js的代码,查看源码并复制,在Chrome中打开网页,审查元素. 将复制的代码输入,将eval改成console.log,再回车执行,就得到一段js代码. 代码中有Unico ...

  7. JetBrains,vim配置文件, .ideavimrc

    addr: https://github.com/NorseLZJ/lzj-config/tree/master/idea_vim

  8. 使用Object类为实例定义方法和属性

    1.1 可以使用 Object 类直接定义个实例,并且为该对象赋属性和方法,例如: var person_1 = { nickName:"xiaowu", age:28, show ...

  9. Codeforces 1299A/1300C - Anu Has a Function

    题目大意: 给定一种函数F(x,y)=(x|y)-y,| 即按位或运算 给定一个长度为n的数组a[1],a[2],a[3]...a[n] 可以重新排列数组a,使得 F ( ...... F ( F ( ...

  10. CodeForces - 748B Santa Claus and Keyboard Check

    题意:给定两个字符串a和b,问有多少种不同的字母组合对,使得将这些字母对替换字符串b后,可以变成字符串a.注意字母对彼此各不相同. 分析:vis[u]记录与u可形成关系的字母,若u与v不同,则形成字母 ...