CodeForces 995B Suit and Tie(贪心,暴力)
https://codeforces.com/problemset/problem/995/B


题意:
就是通过每次移动相邻的两位数,来使数值相同的数挨在一起,求最少要移动多少次。
思路:
直接从前往后遍历,贪心+暴力即可
代码如下:
#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[]; int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=*n;i++)
{
scanf("%d",&a[i]);
}
int ans=;
for(int i=;i<=*n;i+=)
{
if(a[i]==a[i+])
continue;
for(int j=i+;j<=*n;j++)
{
if(a[j]==a[i])
{
ans+=j-i-;
for(int k=j;k>i+;k--)
swap(a[k],a[k-]);
a[i+]=a[i];
break;
}
}
}
printf("%d\n",ans);
return ;
}
CodeForces 995B Suit and Tie(贪心,暴力)的更多相关文章
- CodeForces - 995B Suit and Tie
题面在这里! 明明可以出成n<=1e5但是因为拒绝写数据结构而只出到n<=100,,,出题人真的很棒棒.. 一个显然的贪心就是,把和当前序列最左端的数匹配的数移到它的右边,这样迭代下去总是 ...
- CF995B Suit and Tie 贪心 第十三
Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CodeForces 712C Memory and De-Evolution (贪心+暴力)
题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...
- Codeforces 990 调和级数路灯贪心暴力 DFS生成树两子树差调水 GCD树连通块暴力
A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace ...
- code forces 996D Suit and Tie
D. Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- The 10th Shandong Provincial Collegiate Programming Contest H.Tokens on the Segments(贪心+优先级队列 or 贪心+暴力)
传送门 •题意 二维平面上有 n 条线段,每条线段坐标为 $(l_i,i),(r_i,i)$: 平面上的每个整点坐标上都可以放置一枚硬币,但是要求任意两枚硬币的横坐标不相同: 问最多有多少条线段可以放 ...
- [Codeforces Round #492 (Div. 1) ][B. Suit and Tie]
http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...
随机推荐
- 本地登录ftp的时候报530错误
root@instance-iyi104bj:~# ftp localhost Connected to localhost. (vsFTPd ) Name (localhost:root): roo ...
- cf 261B.Maxim and Restaurant
什么什么期望的,不会! (题解http://blog.sina.com.cn/s/blog_140e100580102wj4e.html(看不懂)) #include<bits/stdc++.h ...
- BZOJ:2244: [SDOI2011]拦截导弹
问题: printf("%.5f ",0):为什么错了? 注意: 初始值很重要 题解: 三维偏序问题: 记录从前往后最长上升子序列长度pref,条数preg 从后往前suff,su ...
- nginx报错
1. nginx报错 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid&q ...
- Essay写作用对标点符号很重要!
很多留学生在essay写作中对于标点符号的正确使用可能不是太清楚,今天Meeloun小编给大家整理了一些关于标点符号的正确打开方式,希望可以帮到同学们! Colloquialism俗语: 如果要在写作 ...
- HZNU-ACM寒假集训Day8小结 最小生成树
最小生成树(无向图) Kruskal 给所有边按从小到大排序 形成环则不选择(利用并查集) P1546 最短网络 https://www.luogu.com.cn/problem/P1546 #i ...
- UNION和UNION ALL的作用和语法
主要就是两句话区别: union是联合的意思,就是合并两个或多个select语句的结果集,并消除重复行: union all 当然也是联合的意思,也是合并两个或多个select语句的结果集,但是保留重 ...
- 低JAVA版本,高兼容性启动
低JAVA版本,高兼容性启动 背景:部分操作系统java环境低版本,暂时无法更新最新版本,新系统需要使用较高版本Java环境 1.JAVA低版本不兼容当前应用 2.解压安装JAVA,无需配置环境变量 ...
- springboot-jar-web
预览 与springboot-jar的区别是: 1.pom.xml 将 <dependency> <groupId>org.springframework.boot</g ...
- POJ 1416:Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4713 Accepted: 2714 ...