codeforces 1520E Arranging The Sheep
链接:
https://codeforces.com/problemset/problem/1520/E
题意:
给一个字符串,'*'代表羊,'.'代表空,让所有的羊站成一排,意为每个羊中间都没有空,每次只能让一只羊动一步,问最少多少步可以让所有的羊站成一排。
本题只要记录所有羊的位置,然后所有羊都向中间的羊靠拢即可,如果有偶数只羊,那选两只羊的哪一只都可以。
代码如下:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<random>
using namespace std;
typedef long long ll;
int position[1000003];
int main() {int T;cin >> T;while (T--) {int n;cin >> n;string s;cin >> s;int cntshp = 0;for (int i = 0; i < n; i++) {if (s[i] == '*') {position[cntshp++] = i;}}int center = (cntshp >> 1);ll ans = 0;for (int i = 0; i < cntshp; i++) {if (i == center) {continue;}else {ans += (abs(position[center] - position[i]) - abs(center - i));}}cout << ans;cout << endl;}
}
codeforces 1520E Arranging The Sheep相关推荐
- codeforces 1520E. Arranging The Sheep(1400)
题目:codeforces 1520E. Arranging The Sheep(1400) 链接:https://codeforces.ml/problemset/problem/1520/E 题目 ...
- Arranging The Sheep
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep ...
- CF1520E Arranging The Sheep
题目描述 You are playing the game "Arranging The Sheep". The goal of this game is to make the ...
- Arranging The Sheep(移动思维)
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep ...
- Day 5 E. Arranging The Sheep
Problem: You are playing the game "Arranging The Sheep". The goal of this game is to make ...
- Arranging The Sheep 中位数定理
CodeForces - 1520E 题意:移动多少步,可以使所有的*相邻 中位数定理 :数列上所有数,到中位数的距离和最小 #include<stdio.h> #include<m ...
- Codeforces Round #719 (Div. 3) E. Arranging The Sheep
翻译: 你正在玩"安排羊"游戏.这个游戏的目标是让羊排好队.游戏中的关卡是由长度为
- E. Arranging The Sheep
题目链接 1400的 div 3 E题,难度不大. 题目大意:给出一个字符串," * " 表示羊," . "是空地.让你用最小的操作数把所有的羊排成一排.每次操 ...
- excel更改日期格式无效_Excel日期不会更改格式
excel更改日期格式无效 Have you ever imported data into Excel, from your credit card statement, or somewhere ...
最新文章
- Linux卸载unity,你如何删除Unity?
- SQUAD的rnet复现踩坑记
- 聊天秒回的人都是生命之光 诉言网
- 在Tableau中去除选择高亮效果
- 并发新特性—Executor 框架与线程池
- TensorFlow:实战Google深度学习框架(一)计算、数据、运行模型
- 面包房算法 java_java处理买面包事件
- 关于SIGPIPE导致的程序退出
- 今日头条电脑版官方版_雷霆拯救电脑版-雷霆拯救pc版下载v4.0.9 官方版
- 学习python内一般函数知识
- Python学习基础系列----了解python
- HTML+CSS静态网页制作:电影网站设计——漫威电影(2页)
- Outlook/Microsfot邮件配置:QQ邮箱/腾讯企业邮箱
- 基于ThinkPHP6+Layui后台开发框架
- 学生类输入输出姓名学号
- 选择代码覆盖工具的 10 个标准
- 超级记忆力训练法简介
- Kafka服务器命令总结
- android查询cpu信息
- execve 执行遇到的问题-已解决
热门文章
- 华为鸿蒙太空人壁纸,华为太空人动态壁纸下载-华为太空人动态壁纸图片高清版-丫丫安卓网...
- A+B 问题【OJ 示例题目】
- 分析报告 | 在线教育APP的市场到底有多大?
- git gc error: failed to run repack message
- I2C协议---I2C时序图解析
- 订单表的字段类型 mysql_Mysql数据库下订单表如何设计?
- python networkx 导入CSV文件画关系网络图
- IIS6 日志删除脚本(t00ls)
- CSS 3D动态立体图形
- Classloader整理