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. AVCodecContext 结构体

    typedef struct AVCodecContext { int bit_rate; int frame_number; //扩展数据,如mov 格式中audio trak 中aac 格式中es ...

  2. MySLQ排序后标记排行

    查询排行及所有(表名.*) 1. ; AS top, customer.* FROM customer 2. AS top, customer.* ) r, customer ORDER BY cus ...

  3. comparable and comparator 比较

      转:http://www.yingjiesheng.com/job-002-393-132.html 一.前言 在Java集合框架里面,各种集合的操作很大程度上都离不开Comparable和Com ...

  4. python刷LeetCode:26. 删除排序数组中的重复项

    难度等级:简单 题目描述: 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外 ...

  5. Python String startswith() Method

    一,摘自官方API  https://docs.python.org/3/library/stdtypes.html#methods str.startswith(prefix[, start[, e ...

  6. EF Core开发模式之Code First

    Code First顾名思义,代码为先.首先编写完相关的实体类及DbContext派生类,然后通过映射关系自动在数据库中完成数据库表的创建. 本例中创建一个班级和学生的管理,主要有班级类MyClass ...

  7. Java学生管理系统(IO版)

    图解: cade: student.java /* * 这是我的学生类 */ public class Student { //学号 private String id; //姓名 private S ...

  8. NABCD模型——星遇

    我们项目是个面向希望有新奇体验的用户的社交软件,致力于打造不一样的有趣的社交. 发表后一周预计用户量:1000人 N:(Need,需求) 目前主流社交软件由于时间原因体量越来越大,各种繁琐而不必要的功 ...

  9. POJ-1733 Parity game(带权并查集区间合并)

    http://poj.org/problem?id=1733 题目描述 你和你的朋友玩一个游戏.你的朋友写下来一连串的0或者1.你选择一个连续的子序列然后问他,这个子序列包含1的个数是奇数还是偶数.你 ...

  10. 阿里云-容器服务之集群服务 k8s(Jenkins+gitlab+k8s的devops)- 04

    配置jenkins和gitlab: 1.进入jenkins,新增一个项目,demo-piepeline,创建好,点击配置, 2 .设置镜像地址的命名空间: 3.设置镜像的名字 4.设置代码的分支或者t ...