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(贪心,暴力)的更多相关文章

  1. CodeForces - 995B Suit and Tie

    题面在这里! 明明可以出成n<=1e5但是因为拒绝写数据结构而只出到n<=100,,,出题人真的很棒棒.. 一个显然的贪心就是,把和当前序列最左端的数匹配的数移到它的右边,这样迭代下去总是 ...

  2. CF995B Suit and Tie 贪心 第十三

    Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. CodeForces 712C Memory and De-Evolution (贪心+暴力)

    题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...

  4. Codeforces 990 调和级数路灯贪心暴力 DFS生成树两子树差调水 GCD树连通块暴力

    A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace ...

  5. 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 ...

  6. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  7. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  8. The 10th Shandong Provincial Collegiate Programming Contest H.Tokens on the Segments(贪心+优先级队列 or 贪心+暴力)

    传送门 •题意 二维平面上有 n 条线段,每条线段坐标为 $(l_i,i),(r_i,i)$: 平面上的每个整点坐标上都可以放置一枚硬币,但是要求任意两枚硬币的横坐标不相同: 问最多有多少条线段可以放 ...

  9. [Codeforces Round #492 (Div. 1) ][B. Suit and Tie]

    http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...

随机推荐

  1. UVA - 12107 Digit Puzzle(数字谜)(IDA*)

    题意:给出一个数字谜,要求修改尽量少的数,使修改后的数字谜只有唯一解.空格和数字可以随意替换,但不能增删,数字谜中所有涉及的数必须是没有前导零的正数.输入数字谜一定形如a*b=c,其中a.b.c分别最 ...

  2. zabbix 日志

    /var/log/zabbix/ tail -f /var/log/zabbix/zabbix_server.log tail -f /var/log/zabbix/zabbix_agentd.log

  3. ubuntu安装opencv3.2

    把master分支git下来: git clone git@github.com:opencv/opencv.git 查看可用的版本: git tag 选择自己想要的版本号: git reset -- ...

  4. SpringMVC错误,商品添加信息HTTP Status 400 – Bad Request

    记录一个自己在做商品信息显示与传递数据的时候出现的错误, HTTP Status 400 – Bad Request Type Status Report Description The server ...

  5. DispatcherServlet(2)_HandlerMapping

    HandlerMapping_xmind SpringMVC默认提供的HandlerMapping BeanNameUrlHandlerMapping SimpleUrlHandlerMapping ...

  6. WindowsForm ComboBoxList 下拉框带复选框 可以动态添加

    先来张效果图: 1.这里需要对控件进行重写,详细内容如下,对此不感兴趣的可以直接跳过这步,下载本人生成的dll,直接看第二小结,下载链接https://pan.baidu.com/s/1gfzrK5t ...

  7. 【数据结构】C++语言环形队列的实现

    队列--先进先出 队列的一个缺点--出队后的内存空间浪费了,不能二次利用 环形队列--解决以上缺点的队列,用过的内存空间可以重复利用 github: https://github.com/HITFis ...

  8. 代码神器:拒绝重复编码,这款IDEA插件了解一下.....

    作者:HeloWxl www.jianshu.com/p/e4192d7c6844 Easycode是idea的一个插件,可以直接对数据的表生成entity.controller.service.da ...

  9. POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))

    题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...

  10. Android aar同步Failed to resolve: :nuisdk:

    在app.gradle中android.dependencies同一级别下加入: repositories { flatDir { dirs 'libs' } }