CodeForces 996B World Cup(思维)
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(思维)的更多相关文章
- [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<= ...
- 【Codeforces 996B】World Cup
[链接] 我是链接,点我呀:) [题意] [题解] 你可以找出来a[i]里面的最小值mi,显然是这个数字最可能先变成0,但还不确定. 然后用mi/n得到你最少需要走多少圈才能让那个mi变成" ...
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- 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 ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- Mike and distribution CodeForces - 798D (贪心+思维)
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...
随机推荐
- C语言数组的所有元素初始化成相同的值
这个问题一直困扰了我很久,我向来都用for来控制置-1:因为我不会用memset(つ﹏⊂)我是个蒟蒻.今天终于学会了一点皮毛,赶紧记录一下 方法一: 简单粗暴,快捷有效.for循环一点点的置1,这个方 ...
- SpringBoot+SpringSecurity之多模块用户认证授权同步
在之前的文章里介绍了SpringBoot和SpringSecurity如何继承.之后我们需要考虑另外一个问题:当前微服务化也已经是大型网站的趋势,当我们的项目采用微服务化架构时,往往会出现如下情况: ...
- java floor,ceil和round方法
Math.floor():返回值是double类型的,返回的是不大于它的最大整数 举例: double x = Math.floor(5.8); System.out.println(x); //输出 ...
- Spring Boot without the web server
https://stackoverflow.com/questions/26105061/spring-boot-without-the-web-server/28565277 1. spring.m ...
- Nginx系列p2:重载,热部署,日志分割
今天我们来学习 nginx 的 重载.热部署.日志分割功能 重载:当我们需要修改配置文件中的一些值,我们可以直接修改该配置文件,然后重新启动 nginx 服务,就可以实现在 nginx 不停止服务的情 ...
- GTK入门
环境准备 官网下载 GTK 源码包,因为本机 GLib 版本不够,下载一个非最新版的 GTK3.8.0 先学习用 直接阅读 "/gtk+-3.8.0/docs/reference/gtk/h ...
- 51nod 1080:两个数的平方和
1080 两个数的平方和 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 给出一个整数N,将N表示为2个整数i j的平方和(i <= j),如果 ...
- SpringMVC的配置文件说明
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- centos7-vsftp(虚拟用户)
要求如下: 1.所有用户主目录为/var/www宿主为virtual用户: 2.ftpuser1用户只能下载不能上传以及删除文件重命名操作: 3.ftpuser2可以下载与上传文件以及删除重命名操作: ...
- Neo4j安装配置(mac)
Neo4j安装配置(mac) 1.下载APP 注意:无需配置变量 下载地址:https://neo4j.com/download/ 2.安装程序并启动 3.创建数据库(local) 选择版本 4.启动 ...