首页 > 其他分享 >A. Stone Game

A. Stone Game

时间:2023-03-11 10:57:29浏览次数:34  
标签:Stone min int begin element Game

A. Stone Game

image

代码

点击查看代码
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int t;
	cin >> t;
	while(t -- ){
		int n;
		cin >> n;
		vector<int> v(n);
		for(int &e:v)cin >> e;
		int maxp = max_element(v.begin(),v.end()) - v.begin();
		int minp = min_element(v.begin(), v.end()) - v.begin();
		cout << min({
			max(maxp, minp) + 1,
			(n - 1) - min(maxp, minp) + 1,
			(n - 1) - maxp + minp + 2,
			(n - 1) - minp + maxp + 2
		}) << '\n';
	}
}

收获

  1. min函数用中括号可以对多个数求最小值,不过要加头文件algorithm
  2. max_element返回最大元素的地址
  3. min_element返回最小元素的地址
  4. vector v(n + 1)可以实现从1开始输入

标签:Stone,min,int,begin,element,Game
From: https://www.cnblogs.com/J-12045/p/17205442.html

相关文章

  • A. Computer Game【dfs诈骗】
    A.ComputerGame代码点击查看代码#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue......
  • Games101-Cp1-Transformation
    最近为了求职重新开始把图形学相关的内容重新系统的学习,先把Games101的内容入门,然后把虎书相关的内容补充。Transformation矩阵变换可以对不同坐标系之间进行转换,在这个......
  • CF207C3 Game with Two Trees 题解
    脑子不够,科技来凑。不过好像也没有用多么高级的科技……首先这个题目很坏,它让你翻转\(S_{t_2}\)。即从\(t_2\)某个节点往下走到另一个节点的路径所表示的字符串。这个......
  • Cisco ISR路由器与Hillstone 防火墙对接IPsec
    用户需求:公司总部有一台Hillstone防火墙,分公司有一台CiscoISR路由器,现在用户想在分公司访问总部的内网资源,于有就有了这一次的IPsec对接。配置过程:一、CiscoISR路由器cryp......
  • [数学记录]arc154F Dice Game
    看这篇看懂的,感觉比洛谷题解的两篇具体不少。来写一下翻译。看懂后觉得官方题解更简练的,但显然我还是新手。思维走过的道路是无可替代的。题意:\(n\)面的骰子每次随......
  • pygame和pywebview配合做界面
    importpygameimportsysfrommultiprocessingimportProcess,Valueimportmultiprocessingimportwebviewimporttimeimportctypesdefhide_show(window,is......
  • How to play Genshin games on Apple Silicon Mac All In One
    HowtoplayGenshingamesonAppleSiliconMacAllInOne如何在Apple芯片的Mac上玩原神游戏macOS&M1/M2CPU✅macOS&IntelCPU❌PlayCoverRuniOSa......
  • [CF282D] Yet Another Number Game 题解
    [CF282D]YetAnotherNumberGame传送门这题可以分三种情况讨论\(n\)的取值。n=1显然,当\(a1\neq0\)时先手可以一下全部取完,后手必败,否则后手必胜。n=2有......
  • PythonGame-3 Cocos2d action
    根据上一个学习,增加action#首先导入Cocos包importcocosfromcocos.actionsimport*#对图层进行子类化并在此处定义编程的逻辑classHelloWorld(cocos.layer.Laye......
  • PythonGame-2 Cocos2d环境搭建
    1、安装pip3installcocos2d报错Preparingmetadata(setup.py)...errorerror:subprocess-exited-with-error×pythonsetup.pyegg_infodidnotruns......