CodeForces - 995B Suit and Tie
明明可以出成n<=1e5但是因为拒绝写数据结构而只出到n<=100,,,出题人真的很棒棒。。
一个显然的贪心就是,把和当前序列最左端的数匹配的数移到它的右边,这样迭代下去总是最优的。
考虑到这样总不会比把这个数向右移到匹配的数左边更劣,而且每个数都得匹配。。。。
n<=100的话直接扫一下就行了,反正怎么做都可以过的数据范围。。。。
n再大一点的话上树状数组就行了。。。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105; int n,a[N*2],ans,m; int main(){
scanf("%d",&n),m=n<<1;
for(int i=1;i<=m;i++) scanf("%d",a+i); for(int i=1,j;i<=m;i++) if(a[i]){
for(j=i+1;a[j]!=a[i];j++) ans+=(a[j]>0);
a[j]=0;
} printf("%d\n",ans);
return 0;
}
CodeForces - 995B Suit and Tie的更多相关文章
- CodeForces 995B Suit and Tie(贪心,暴力)
https://codeforces.com/problemset/problem/995/B 题意: 就是通过每次移动相邻的两位数,来使数值相同的数挨在一起,求最少要移动多少次. 思路: 直接从前往 ...
- 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 ...
- CF995B Suit and Tie 贪心 第十三
Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- [Codeforces Round #492 (Div. 1) ][B. Suit and Tie]
http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- 越狱Season 1-Season 1, Episode 3: Cell Test
Season 1, Episode 3: Cell Test -CO: Oh, my God. 我的天 Williamson, get in here. Williamson 快进来 What the ...
- Daily record-November
November 11. I managed to grab her hand. 我抓到了她的手.2. He passed a hand wearily over his eyes. 他疲倦地用手抹了 ...
- 从零开始单排学设计模式「装饰模式」黑铁 I
阅读本文大概需要 3.6 分钟. 本篇是设计模式系列的第四篇,虽然之前也写过相应的文章,但是因为种种原因后来断掉了,而且发现之前写的内容也很渣,不够系统. 所以现在打算重写,加上距离现在也有一段时间了 ...
- [Python设计模式] 第6章 衣服搭配系统——装饰模式
github地址:https://github.com/cheesezh/python_design_patterns 题目 设计一个控制台程序,可以给人搭配嘻哈风格(T恤,垮裤,运动鞋)或白领风格( ...
随机推荐
- JS语句循环(100以内奇偶数、100以内与7先关的数、100以内整数的和、10以内阶乘、乘法口诀、篮球弹起高度、64格子放东西)
3.循环 循环是操作某一个功能(执行某段代码). ①循环四要素: a 循环初始值 b 循环的条件 c 循环状态 d 循环体 ②for循环 a 穷举:把所有的可能性的都一一列出来. b 迭代:每次循环都 ...
- python中filter函数
python中filter()函数 filter()函数是 Python 内置的另一个有用的高阶函数,filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断 ...
- rabbitmq之队列性能测试及优化方法(六)
前言 下面关注一下rabbitmq实际使用时的性能问题和怎么进行一些优化. 性能测试 针对每个需要生产/消费者与rabbitmq进行通讯的方法进行测试 测试环境 排除网络IO的干扰,采用生产者和消费者 ...
- 【Linux学习】nohup后台运行程序以及输出重定向
Linux有两种命令使程序后台运行 第一种:支持后台运行,但是关闭终端的话,程序也会停止 command & 第二种:支持后台运行,关闭终端后,程序也会继续运行 nohup command & ...
- 【bzoj1923】外星千足虫
这个gauss消元有点naive啊. 由于只有01,位操作显然是方便的多. 那么用bitset代替之前的增广矩阵就行了. #include<bits/stdc++.h> #define N ...
- python之路——面向对象进阶
阅读目录 isinstance和issubclass 反射 setattr delattr getattr hasattr __str__和__repr__ __del__ item系列 __geti ...
- Majority Element——算法课上的一道题(经典)
Given an array of size n, find the majority element. The majority element is the element that appear ...
- android之 Activity跳转出现闪屏
原文:http://blog.csdn.net/az313/article/details/17321549 同一个应用,在不同手机上测试,Activity之间跳转出现闪屏,界面来回跳转…… 查阅网上 ...
- AC日记——NOI2016区间 bzoj 4653
4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #def ...
- Visual Studio for Mac 安装时无法连接到网络等问题
问题: 1.下载 vs for mac 离线安装包 离线下载地址https://download.microsoft.com/download/3/d/4/3d42f40f-4f0a-4613-920 ...