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恤,垮裤,运动鞋)或白领风格( ...
随机推荐
- C# SuperSocket 消息推送
服务端使用Nuget引用SuperSocket.WebSocket和SuperSocket.Engine 服务器端代码[控制台] using SuperSocket.WebSocket; using ...
- js_时间戳和时间格式之间的转换。
关于我的理解,简单明了点: 时间戳:把一个日期使用一个数字表示出来,这个数字就是这个日期的秒数. 日期:就是我们常见的时间表现形式. 时间戳对于一般看时间不够直观明了,可是在程序的世界里作用可大了. ...
- Python ctypes 在 Python 2 和 Python 3 中的不同 // 使用ctypes过程中问题汇总
In Python 2.7, strings are byte-strings by default. In Python 3.x, they are unicode by default. Try ...
- 上传漏洞新姿势(限Linux)
服务器:Linux当前环境:nginx/1.4.7PHP版本:PHP Version 7.0.0 上传情况简介:上传 111.jpg111 确实可以成功的但是上传 1.php.jpg1111.1 ...
- yocto 离线编译
使用yocto编译一个软件包时,一般会先在本地寻找下载好的源码包,如果不存在则根据配置从网络下载. 添加本地源码包 为了支持离线编译,添加一个包的配置文件后,需要在本地也准备好源码包. 可以先打开网络 ...
- perl多线程tcp端口扫描器(原创)
perl多线程tcp端口扫描器(原创) http://bbs.chinaunix.net/thread-1457744-1-1.html perl socket 客户端发送消息 http://blog ...
- 广度优先搜索--POJ迷宫问题
Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, ...
- Tomcat+Apache 负载均衡
1.JDK1.8和Tomcat7.0不兼容,支持Tomcat8.0. 集群架构图: 2.负载均衡:负载的基础是集群,集群就是一组连在一起的计算机,从外部看它是一个系统,各节点可以是不同的操作系统或不同 ...
- 【python】资料记录
今天看了一些关于python的知识: 1.装饰器:https://www.zhihu.com/question/25950466/answer/31731502 2.*args的用法:http://b ...
- new、operator new、placement new
首先我们区分下几个容易混淆的关键词: new.operator new.placement new new和delete操作符我们应该都用过,它们是对堆中的内存进行申请和释放,而这两个都是不能被重载的 ...