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. HDU 1003:Max Sum

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  2. springboot学习2 整合mybatis

    springboot整合mybatis 一.添加mybatis和数据库连接的依赖 <!--整合mybatis--> <dependency> <groupId>or ...

  3. 第二阶段scrum-3

    1.整个团队的任务量: 2.任务看板: 会议照片: 产品状态: 前端制作完成,数据库正在配置

  4. iOS延迟执行方法

    swift 4.0中dispatch_async,dispatch_after的使用 2018年03月28日 16:15:44 xiao_yuly 阅读数:3576 版权声明:本文为博主原创文章,未经 ...

  5. 实验吧Web-难-头有点大(http头伪造:浏览器、国家、.Net framework版本)

    进去网站显示: 此处告诉我们要干三件事: (1).net framework 版本为9.9 (2)告诉服务器我们的地址为英国 (3)我们访问站点用的是IE 下面我们就抓的包中伪造. 1:.net fr ...

  6. 关于Pytorch中autograd和backward的一些笔记

    参考自<Pytorch autograd,backward详解>: 1 Tensor Pytorch中所有的计算其实都可以回归到Tensor上,所以有必要重新认识一下Tensor. 如果我 ...

  7. 8.scrapy的第一个实例

    [目标]要完成的任务如下: ※ 创建一个 Scrap项目.※ 创建一个 Spider来抓取站点和处理数据.※ 通过命令行将抓取的内容导出.※ 将抓取的内容保存的到 MongoDB数据库.======= ...

  8. WordPress站点绑定多个域名

    refer to https://blog.csdn.net/wzl505/article/details/54970321 打开根目录下的 wp-config.php 文件,找到 require_o ...

  9. nginx重写常用写法

    1.将http协议重写成https协议: (用户用http进行访问,但后端是https),则可添加80 http端口监听,然后进行https rewrite; server {     listen ...

  10. JS-表单验证二

    3.范围验证:年龄范围验证: <head> <meta http-equiv="Content-Type" content="text/html; ch ...